Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Oct 12, 2020
1 parent 82cafb4 commit 75930e7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rich/highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class ReprHighlighter(RegexHighlighter):
r"(?P<path>\B(\/[\w\.\-\_\+]+)*\/)(?P<filename>[\w\.\-\_\+]*)?",
r"(?<!\\)(?P<str>b?\'\'\'.*?(?<!\\)\'\'\'|b?\'.*?(?<!\\)\'|b?\"\"\".*?(?<!\\)\"\"\"|b?\".*?(?<!\\)\")",
r"(?P<uuid>[a-fA-F0-9]{8}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{12})",
r"(?P<url>https?:\/\/[0-9a-zA-Z\$\-\_\+\!`\(\)\,\.\?\/\;\:\&\=\%\#]*)",
),
r"(?P<url>https?:\/\/[0-9a-zA-Z\$\-\_\+\!`\(\)\,\.\?\/\;\:\&\=\%\#]*)",
]


Expand Down
23 changes: 23 additions & 0 deletions tests/test_highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def test_wrong_type():


highlight_tests = [
(" ", []),
(
"<foo>",
[
Expand All @@ -21,13 +22,24 @@ def test_wrong_type():
Span(4, 5, "repr.tag_end"),
],
),
(
"False True None",
[
Span(0, 5, "repr.bool_false"),
Span(6, 10, "repr.bool_true"),
Span(11, 15, "repr.none"),
],
),
("foo=bar", [Span(0, 3, "repr.attrib_name"), Span(4, 7, "repr.attrib_value")]),
('foo="bar"', [Span(0, 3, "repr.attrib_name"), Span(4, 9, "repr.attrib_value")]),
("( )", [Span(0, 1, "repr.brace"), Span(2, 3, "repr.brace")]),
("[ ]", [Span(0, 1, "repr.brace"), Span(2, 3, "repr.brace")]),
("{ }", [Span(0, 1, "repr.brace"), Span(2, 3, "repr.brace")]),
(" 1 ", [Span(1, 2, "repr.number")]),
(" 1.2 ", [Span(1, 4, "repr.number")]),
(" 0xff ", [Span(1, 5, "repr.number")]),
(" /foo ", [Span(1, 2, "repr.path"), Span(2, 5, "repr.filename")]),
(" /foo/bar.html ", [Span(1, 6, "repr.path"), Span(6, 14, "repr.filename")]),
("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
Expand All @@ -38,6 +50,16 @@ def test_wrong_type():
("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
("https://example.org", [Span(0, 19, "repr.url")]),
("http://example.org", [Span(0, 18, "repr.url")]),
("No place like 127.0.0.1", [Span(14, 23, "repr.ipv4")]),
("''", [Span(0, 2, "repr.str")]),
("'hello'", [Span(0, 7, "repr.str")]),
("'''hello'''", [Span(0, 11, "repr.str")]),
('""', [Span(0, 2, "repr.str")]),
('"hello"', [Span(0, 7, "repr.str")]),
('"""hello"""', [Span(0, 11, "repr.str")]),
("\\'foo'", []),
]


Expand All @@ -47,4 +69,5 @@ def test_highlight_regex(test: str, spans: List[Span]):
text = Text(test)
highlighter = ReprHighlighter()
highlighter.highlight(text)
print(text.spans)
assert text.spans == spans

0 comments on commit 75930e7

Please sign in to comment.