| 13 | |
| 14 | |
| 15 | class TestMatcher(unittest.TestCase): |
| 16 | def setUp(self): |
| 17 | self.file_type_dict = {} |
| 18 | self.file_type_dict["cppfiles"] = ["./cpp/ice_rxtx_vec_avx2.c"] |
| 19 | mather_factory = MatcherFactory(self.file_type_dict) |
| 20 | self.matcher = mather_factory.get_matcher(MatcherType.CppMatcher) |
| 21 | |
| 22 | def test_cpp(self): |
| 23 | results = self.matcher.match() |
| 24 | # print(results.file_path) |
| 25 | self.assertGreaterEqual(len(results), 1) |
| 26 | |
| 27 | def test_macro_branch_judge(self): |
| 28 | """[['if', 308, '#if __x86__', 'x86'], ['elif', 310, '#elif aarch64', 'arm'], ['elif', 312, |
| 29 | #elif mips', 'mips'], ['endif', 316, '#endif', 'all']]""" |
| 30 | input = [['if', 308, '#if __x86__', 'x86'], ['elif', 310, '#elif aarch64', 'arm'], |
| 31 | ['elif', 312, '#elif mips', 'mips'], ['endif', 316, '#endif', 'all']] |
| 32 | start, end, need = self.matcher.macro_branch_judge(input) |
| 33 | self.assertEqual(need, 0) |
| 34 | |
| 35 | input = [['if', 308, '#if __x86__', 'x86'], ['elif', 310, '#elif shenwei', 'all'], |
| 36 | ['elif', 312, '#elif mips', 'mips'], ['endif', 316, '#endif', 'all']] |
| 37 | start, end, need = self.matcher.macro_branch_judge(input) |
| 38 | self.assertEqual(need, 1) |
| 39 | |
| 40 | input = [['ifndef', 308, '#ifndef arrch64', 'all'], ['elif', 310, '#elif aarch64', 'arm'], |
| 41 | ['elif', 312, '#elif mips', 'mips'], ['endif', 316, '#endif', 'all']] |
| 42 | start, end, need = self.matcher.macro_branch_judge(input) |
| 43 | self.assertEqual(need, 0) |
| 44 | |
| 45 | if __name__ == "__main__": |
| 46 | # create test suite |