Esempio n. 1
0
def test_quotes():
    """Test the quoted-string regexes, both with double and single quotes."""
    tests = [
        (r'"hi there"', r'hi there'),
        (r'"hi"there"', r'hi"there'),
        (
            r'"hi"there"d', r'hi"there"d'
        ),  # Don't prematurely stop capturing when we hit a quote without a space after it.
        (
            r'"hi\" and"', r'hi" and'
        ),  # Don't count a backslashed quote as a closing one, even if it has a space after it.
        (r'"hi \pthere\"boogy"', r'hi \pthere"boogy'
         ),  # Preserve backslashes that don't escape a quote.
        (r'"multi word', r'multi word'
         ),  # Get all words in a space-having input without closing quotes.
        (r'"\\""', r'\"'),  # It is possible to express backslash-quote.
        (ur'"sñork"', ur'sñork')
    ]  # Unicode holds up in quoted strings.
    for rule_name, transform in [('double_quoted_text', lambda x: x),
                                 ('single_quoted_text',
                                  lambda x: x.replace('"', "'"))]:
        rule = query_grammar([])[rule_name]
        for input, output in tests:

            def test_something():
                eq_(QueryVisitor().visit(rule.match(transform(input))),
                    transform(output))

            yield test_something
Esempio n. 2
0
def test_quotes():
    """Test the quoted-string regexes, both with double and single quotes."""
    tests = [(r'"hi there"', r'hi there'),
             (r'"hi"there"', r'hi"there'),
             (r'"hi"there"d', r'hi"there"d'),  # Don't prematurely stop capturing when we hit a quote without a space after it.
             (r'"hi\" and"', r'hi" and'),  # Don't count a backslashed quote as a closing one, even if it has a space after it.
             (r'"hi \pthere\"boogy"', r'hi \pthere"boogy'),  # Preserve backslashes that don't escape a quote.
             (r'"multi word', r'multi word'),  # Get all words in a space-having input without closing quotes.
             (r'"\\""', r'\"'),  # It is possible to express backslash-quote.
             (ur'"sñork"', ur'sñork')]  # Unicode holds up in quoted strings.
    for rule_name, transform in [('double_quoted_text',
                                  lambda x: x),
                                 ('single_quoted_text',
                                  lambda x: x.replace('"', "'"))]:
        rule = query_grammar([])[rule_name]
        for input, output in tests:
            def test_something():
                eq_(QueryVisitor().visit(rule.match(transform(input))),
                    transform(output))
            yield test_something
Esempio n. 3
0
 def visit(self, query):
     return QueryVisitor().visit(query_grammar(plugins_named(['core', 'clang'])).parse(query))
Esempio n. 4
0
 def visit(self, query):
     return QueryVisitor().visit(
         query_grammar(plugins_named(['core', 'clang'])).parse(query))