Correctly get language
Operator precedence is important
This commit is contained in:
parent
82701a706c
commit
2d537d3b10
2 changed files with 13 additions and 1 deletions
|
@ -32,7 +32,7 @@ class CodeStructValue(StructValue):
|
|||
if filename := self["filename"]:
|
||||
return filename
|
||||
|
||||
if language := self["language"] and self["language"] != TextLexer.name:
|
||||
if (language := self["language"]) != TextLexer.name:
|
||||
return language
|
||||
|
||||
return ""
|
||||
|
|
|
@ -26,3 +26,15 @@ class CodeStructValueTestCase(SimpleTestCase):
|
|||
None, [("source", "test"), ("language", language)]
|
||||
)
|
||||
self.assertIsInstance(block.code(), str)
|
||||
|
||||
def test_header_text_uses_filename(self) -> None:
|
||||
block = CodeStructValue(None, [("filename", "test.txt")])
|
||||
self.assertEqual(block.header_text(), "test.txt")
|
||||
|
||||
def test_header_text_uses_language(self) -> None:
|
||||
block = CodeStructValue(None, [("filename", ""), ("language", "Python")])
|
||||
self.assertEqual(block.header_text(), "Python")
|
||||
|
||||
def test_header_text_empty_when_text(self) -> None:
|
||||
block = CodeStructValue(None, [("filename", ""), ("language", "Text only")])
|
||||
self.assertEqual(block.header_text(), "")
|
||||
|
|
Loading…
Reference in a new issue