[update_cc_test_checks] Add test for missing handling of mangled names
[llvm-project.git] / llvm / utils / filecheck_lint / filecheck_lint_test.py
blob6edcf0abd25a94ff5a141ecc16e36b22bf89627b
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 pos.as_str() == "1:7-11"
53 assert match == "CHCK1"
55 pos, match = results[1]
56 assert pos.as_str() == "2:8-12"
57 assert match == "CHCK2"
59 pos, match = results[2]
60 assert pos.as_str() == "3:1-10"
61 assert match == "SOME CHCK3"
63 def test_levenshtein(self):
64 for s1, s2, distance in [
65 ("Levenshtein", "Levenstin", 2), # 2 insertions
66 ("Levenshtein", "Levenstherin", 3), # 1 insertion, 2 deletions
67 ("Levenshtein", "Lenvinshtein", 2), # 1 deletion, 1 substitution
68 ("Levenshtein", "Levenshtein", 0), # identical strings
70 assert fcl.levenshtein(s1, s2) == distance