mirror of
https://github.com/Textualize/rich.git
synced 2025-08-04 10:08:40 +00:00
highlighter tests
This commit is contained in:
parent
571f7f37db
commit
cd4f00ff34
1 changed files with 19 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
|||
"""Tests for the higlighter classes."""
|
||||
import pytest
|
||||
from typing import List
|
||||
|
||||
from rich.highlighter import NullHighlighter, ReprHighlighter
|
||||
from rich.text import Span, Text
|
||||
|
@ -11,24 +12,24 @@ def test_wrong_type():
|
|||
highlighter([])
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"style_name, test_str",
|
||||
[
|
||||
("repr.eui48", "01-23-45-67-89-AB"), # 6x2 hyphen
|
||||
("repr.eui64", "01-23-45-FF-FE-67-89-AB"), # 8x2 hyphen
|
||||
("repr.ipv6", "01:23:45:67:89:AB"), # 6x2 colon
|
||||
("repr.ipv6", "01:23:45:FF:FE:67:89:AB"), # 8x2 colon
|
||||
("repr.eui48", "0123.4567.89AB"), # 3x4 dot
|
||||
("repr.eui64", "0123.45FF.FE67.89AB"), # 4x4 dot
|
||||
("repr.eui48", "ed-ed-ed-ed-ed-ed"), # lowercase
|
||||
("repr.eui48", "ED-ED-ED-ED-ED-ED"), # uppercase
|
||||
("repr.eui48", "Ed-Ed-Ed-Ed-Ed-Ed"), # mixed case
|
||||
("repr.eui48", "0-00-1-01-2-02"), # dropped zero
|
||||
],
|
||||
)
|
||||
def test_highlight_regex(style_name: str, test_str: str):
|
||||
highlight_tests = [
|
||||
("01-23-45-67-89-AB", [Span(0, 17, "repr.eui48")]), # 6x2 hyphen
|
||||
("01-23-45-FF-FE-67-89-AB", [Span(0, 23, "repr.eui64")]), # 8x2 hyphen
|
||||
("01:23:45:67:89:AB", [Span(0, 17, "repr.ipv6")]), # 6x2 colon
|
||||
("01:23:45:FF:FE:67:89:AB", [Span(0, 23, "repr.ipv6")]), # 8x2 colon
|
||||
("0123.4567.89AB", [Span(0, 14, "repr.eui48")]), # 3x4 dot
|
||||
("0123.45FF.FE67.89AB", [Span(0, 19, "repr.eui64")]), # 4x4 dot
|
||||
("ed-ed-ed-ed-ed-ed", [Span(0, 17, "repr.eui48")]), # lowercase
|
||||
("ED-ED-ED-ED-ED-ED", [Span(0, 17, "repr.eui48")]), # uppercase
|
||||
("Ed-Ed-Ed-Ed-Ed-Ed", [Span(0, 17, "repr.eui48")]), # mixed case
|
||||
("0-00-1-01-2-02", [Span(0, 14, "repr.eui48")]), # dropped zero
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test, spans", highlight_tests)
|
||||
def test_highlight_regex(test: str, spans: List[Span]):
|
||||
"""Tests for the regular expressions used in ReprHighlighter."""
|
||||
text = Text(test_str)
|
||||
text = Text(test)
|
||||
highlighter = ReprHighlighter()
|
||||
highlighter.highlight(text)
|
||||
assert text.spans == [Span(0, len(test_str), style_name)]
|
||||
assert text.spans == spans
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue