Skip to content

Commit

Permalink
Add support for checking if a language is supported.
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeseekr committed Apr 1, 2024
1 parent aadba2e commit cce3d57
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Highlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public function __construct(
}
}

public function isSupportedLanguage(string $language): bool
{
return array_key_exists(strtolower($language), $this->languages);
}

public function setLanguage(string $name, Language $language): self
{
$this->languages[$name] = $language;
Expand Down
12 changes: 12 additions & 0 deletions tests/HighlighterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ public static function data(): array
['02', 'html'], // deep injections
];
}

public function test_is_supported_language(): void
{
$highlight = new Highlighter();

self::assertTrue($highlight->isSupportedLanguage('php'));
self::assertTrue($highlight->isSupportedLanguage('PHP'));
self::assertTrue($highlight->isSupportedLanguage('Php'));

self::assertFalse($highlight->isSupportedLanguage('DoesNotExist'));
self::assertFalse($highlight->isSupportedLanguage('DOESNOTEXIST'));
}
}

0 comments on commit cce3d57

Please sign in to comment.