Files
textual/tests/test_highlight.py
TomJGooding 19eeb5d7ba feat(highlight): use theme text colors
The new `highlight` module for syntax highlighting currently uses the
'base' theme colors. Perhaps this was intentional, but to my eye this
makes the colors in `Markdown` code blocks so prominent that they feel
a bit out of place.

This updates the highlight theme to instead use the dedicated theme text
colors, which I think looks more consistent.
2025-07-17 18:58:59 +01:00

30 lines
832 B
Python

import pytest
from textual.content import Span
from textual.highlight import guess_language, highlight
def test_highlight() -> None:
"""Test simple application of highlight."""
import_this = highlight("import this", language="python")
assert import_this.plain == "import this"
print(import_this.spans)
assert import_this.spans == [
Span(0, 11, style="$text"),
Span(0, 6, style="$text-error"),
Span(7, 11, style="$text-primary"),
]
@pytest.mark.parametrize(
"code,path,language",
[
("import this", "foo.py", "python"),
("<xml>", "foo.xml", "xml"),
("{}", "data.json", "json"),
],
)
def test_guess_language(code: str, path: str, language: str) -> None:
"""Test guess_language is working."""
assert guess_language(code, path) == language