()
| 228 | |
| 229 | |
| 230 | def test_highlight_regex_callable(): |
| 231 | text = Text("Vulnerability CVE-2018-6543 detected") |
| 232 | re_cve = r"CVE-\d{4}-\d+" |
| 233 | compiled_re_cve = re.compile(r"CVE-\d{4}-\d+") |
| 234 | |
| 235 | def get_style(text: str) -> Style: |
| 236 | return Style.parse( |
| 237 | f"bold yellow link https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword={text}" |
| 238 | ) |
| 239 | |
| 240 | # string |
| 241 | count = text.highlight_regex(re_cve, get_style) |
| 242 | assert count == 1 |
| 243 | assert len(text._spans) == 1 |
| 244 | assert text._spans[0].start == 14 |
| 245 | assert text._spans[0].end == 27 |
| 246 | assert ( |
| 247 | text._spans[0].style.link |
| 248 | == "https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=CVE-2018-6543" |
| 249 | ) |
| 250 | |
| 251 | # Clear the tracked _spans for the regular expression object's use |
| 252 | text._spans.clear() |
| 253 | |
| 254 | # regular expression object |
| 255 | count = text.highlight_regex(compiled_re_cve, get_style) |
| 256 | assert count == 1 |
| 257 | assert len(text._spans) == 1 |
| 258 | assert text._spans[0].start == 14 |
| 259 | assert text._spans[0].end == 27 |
| 260 | assert ( |
| 261 | text._spans[0].style.link |
| 262 | == "https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=CVE-2018-6543" |
| 263 | ) |
| 264 | |
| 265 | |
| 266 | def test_highlight_words(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…