Add tests for linguist integration
This commit is contained in:
parent
8f5ab16891
commit
c2d8ef260a
1 changed files with 26 additions and 1 deletions
|
@ -1,8 +1,10 @@
|
||||||
|
import re
|
||||||
|
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from .blocks import CodeStructValue, get_language_choices
|
from .blocks import CodeStructValue, get_language_choices
|
||||||
from .utils import PYGMENTS_VERSION_SLUG
|
from .utils import PYGMENTS_VERSION_SLUG, get_linguist_colours
|
||||||
|
|
||||||
|
|
||||||
class PygmentsStylesTestCase(SimpleTestCase):
|
class PygmentsStylesTestCase(SimpleTestCase):
|
||||||
|
@ -35,6 +37,29 @@ class CodeStructValueTestCase(SimpleTestCase):
|
||||||
block = CodeStructValue(None, [("filename", ""), ("language", "Python")])
|
block = CodeStructValue(None, [("filename", ""), ("language", "Python")])
|
||||||
self.assertEqual(block.header_text(), "Python")
|
self.assertEqual(block.header_text(), "Python")
|
||||||
|
|
||||||
|
def test_header_text_uses_language_mapping(self) -> None:
|
||||||
|
block = CodeStructValue(
|
||||||
|
None, [("filename", ""), ("language", "Python console session")]
|
||||||
|
)
|
||||||
|
self.assertEqual(block.header_text(), "Python")
|
||||||
|
|
||||||
def test_header_text_empty_when_text(self) -> None:
|
def test_header_text_empty_when_text(self) -> None:
|
||||||
block = CodeStructValue(None, [("filename", ""), ("language", "Text only")])
|
block = CodeStructValue(None, [("filename", ""), ("language", "Text only")])
|
||||||
self.assertEqual(block.header_text(), "")
|
self.assertEqual(block.header_text(), "")
|
||||||
|
|
||||||
|
def test_linguist_mapping(self) -> None:
|
||||||
|
linguist_languages = set(get_linguist_colours().keys())
|
||||||
|
|
||||||
|
for language in CodeStructValue.LINGUIST_MAPPING.values():
|
||||||
|
self.assertIn(language.lower(), linguist_languages)
|
||||||
|
|
||||||
|
|
||||||
|
class LinguistColoursTestCase(SimpleTestCase):
|
||||||
|
HEX_RE = re.compile(r"#[0-9A-F]", re.IGNORECASE)
|
||||||
|
|
||||||
|
def test_gets_colours(self) -> None:
|
||||||
|
colours = get_linguist_colours()
|
||||||
|
|
||||||
|
for colour in colours.values():
|
||||||
|
with self.subTest(colour):
|
||||||
|
self.assertRegex(colour, self.HEX_RE)
|
||||||
|
|
Loading…
Reference in a new issue