Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / utils / filecheck_lint / filecheck_lint_test.py
blob16f381d5b0455de86da67229c8d8944f8bfba738
1 # ===----------------------------------------------------------------------===##
3 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 # See https://llvm.org/LICENSE.txt for license information.
5 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 # ===----------------------------------------------------------------------===##
8 import unittest
10 import filecheck_lint as fcl
13 class TestParser(unittest.TestCase):
14 def test_parse_all_additional_prefixes(self):
15 def run(content, expected_prefixes):
16 prefixes = set(fcl.parse_custom_prefixes(content))
17 for prefix in expected_prefixes:
18 self.assertIn(prefix, prefixes)
20 for content, expected_prefixes in [
21 ("-check-prefix=PREFIX", {"PREFIX"}),
22 ("-check-prefix='PREFIX'", {"PREFIX"}),
23 ('-check-prefix="PREFIX"', {"PREFIX"}),
24 ("-check-prefix PREFIX", {"PREFIX"}),
25 ("-check-prefix PREFIX", {"PREFIX"}),
26 ("-check-prefixes=PREFIX1,PREFIX2", {"PREFIX1", "PREFIX2"}),
27 ("-check-prefixes PREFIX1,PREFIX2", {"PREFIX1", "PREFIX2"}),
29 """-check-prefix=PREFIX1 -check-prefix PREFIX2
30 -check-prefixes=PREFIX3,PREFIX4 -check-prefix=PREFIX5
31 -check-prefixes PREFIX6,PREFIX7 -check-prefixes=PREFIX8',
32 """, # pylint: disable=bad-continuation
33 {f"PREFIX{i}" for i in range(1, 9)},
36 run(content, expected_prefixes)
38 def test_additional_prefixes_uniquely(self):
39 lines = ["--check-prefix=SOME-PREFIX", "--check-prefix=SOME-PREFIX"]
40 prefixes = set(fcl.parse_custom_prefixes("\n".join(lines)))
41 assert len(prefixes) == 1
44 class TestTypoDetection(unittest.TestCase):
45 def test_find_potential_directives_comment_prefix(self):
46 lines = ["junk; CHCK1:", "junk// CHCK2:", "SOME CHCK3:"]
47 content = "\n".join(lines)
49 results = list(fcl.find_potential_directives(content))
50 assert len(results) == 3
51 pos, match = results[0]
52 assert (
53 pos.line == 1
54 and pos.start_column == len("junk; ") + 1
55 and pos.end_column == len(lines[0]) - 1
57 assert match == "CHCK1"
59 pos, match = results[1]
60 assert (
61 pos.line == 2
62 and pos.start_column == len("junk// ") + 1
63 and pos.end_column == len(lines[1]) - 1
65 assert match == "CHCK2"
67 pos, match = results[2]
68 assert (
69 pos.line == 3
70 and pos.start_column == 1
71 and pos.end_column == len(lines[2]) - 1
73 assert match == "SOME CHCK3"
75 def test_levenshtein(self):
76 for s1, s2, distance in [
77 ("Levenshtein", "Levenstin", 2), # 2 insertions
78 ("Levenshtein", "Levenstherin", 3), # 1 insertion, 2 deletions
79 ("Levenshtein", "Lenvinshtein", 2), # 1 deletion, 1 substitution
80 ("Levenshtein", "Levenshtein", 0), # identical strings
82 assert fcl.levenshtein(s1, s2) == distance