예제 #1
0
    def test_multi_regex(self):
        """Tests that the lazy dictionary doesn't walk over itself or something."""
        parsed = matcher.parse_ast('var_hello = 42', '<string>')
        m = base_matchers.AllOf(
            base_matchers.FileMatchesRegex('var'),
            base_matchers.FileMatchesRegex('hello'),
            base_matchers.FileMatchesRegex('42'),
            base_matchers.FileMatchesRegex(r'\Avar_hello = 42\Z'),
            ast_matchers.Num())

        matches = list(matcher.find_iter(m, parsed))

        self.assertLen(matches, 1)
예제 #2
0
    def test_doesnt_match(self):
        parsed = matcher.parse_ast('hi = 42', '<string>')
        m = base_matchers.AllOf(base_matchers.FileMatchesRegex('hello'),
                                ast_matchers.Num())

        matches = list(matcher.find_iter(m, parsed))

        self.assertEqual(matches, [])
예제 #3
0
    def test_matches(self):
        parsed = matcher.parse_ast('var_hello = 42', '<string>')
        m = base_matchers.AllOf(base_matchers.FileMatchesRegex('hello'),
                                ast_matchers.Num())

        matches = list(matcher.find_iter(m, parsed))

        self.assertLen(matches, 1)
예제 #4
0
 def test_bindings(self):
     parsed = matcher.parse_ast('x = 2', '<string>')
     matches = list(
         matcher.find_iter(
             base_matchers.AllOf(
                 base_matchers.FileMatchesRegex(r'(?P<var>x)'),
                 ast_matchers.Num()), parsed))
     self.assertLen(matches, 1)
     [m] = matches
     self.assertIn('var', m.bindings)
     self.assertEqual(m.bindings['var'].value.span, (0, 1))
예제 #5
0
 def test_bind_variables(self):
     self.assertEqual(
         base_matchers.FileMatchesRegex('(?P<name>x)(y)').bind_variables,
         {'name'})