Beispiel #1
0
 def test_random(self):
     '''
     Compares lepl + python expressions.  This runs 'til it fails, and it
     always does fail, because lepl's expressions are guarenteed greedy
     while python's aren't.  This is "normal" (Perl is the same as Python)
     but I cannot fathom why it should be - it seems *harder* to make them
     wwork that way... 
     '''
     #basicConfig(level=DEBUG)
     #log = getLogger('lepl.reexgp._test.random')
     match_alphabet = '012'
     string_alphabet = '013'
     for _ in range(100):
         expression = random_expression(3, match_alphabet) 
         string = random_string(3, string_alphabet)
         matcher = DfaRegexp(expression)
         matcher.config.no_full_first_match()
         lepl_result = matcher.parse(string)
         if lepl_result:
             lepl_result = lepl_result[0]
         #log.debug(format('{0} {1} {2}', expression, string, lepl_result))
         try:
             python_result = compile_(expression).match(string) 
             if python_result:
                 python_result = python_result.group()
             assert lepl_result == python_result, \
                 format('{0} != {1}\n{2} {3}', 
                        lepl_result, python_result, expression, string)
         except:
             (e, v, _t) = exc_info()
             if repr(v) == "error('nothing to repeat',)":
                 pass
             else:
                 raise e
Beispiel #2
0
 def test_random(self):
     '''
     Compares lepl + python expressions.  This runs 'til it fails, and it
     always does fail, because lepl's expressions are guaranteed greedy
     while python's aren't.  This is "normal" (Perl is the same as Python)
     but I cannot fathom why it should be - it seems *harder* to make them
     work that way... 
     '''
     #basicConfig(level=DEBUG)
     log = getLogger('lepl.regexp._test.random')
     match_alphabet = '012'
     string_alphabet = '013'
     for _ in range(100):
         expression = random_expression(3, match_alphabet)
         string = random_string(3, string_alphabet)
         matcher = DfaRegexp(expression)
         #            matcher = NfaRegexp(expression)
         matcher.config.no_full_first_match()
         lepl_result = matcher.parse(string)
         if lepl_result:
             lepl_result = lepl_result[0]
         log.debug(fmt('{0} {1} {2}', expression, string, lepl_result))
         try:
             python_result = compile_(expression).match(string)
             if python_result:
                 python_result = python_result.group()
             assert lepl_result == python_result, \
                 fmt('{0} != {1}\n{2} {3}',
                        lepl_result, python_result, expression, string)
         except:
             (e, v, _t) = exc_info()
             if repr(v) == "error('nothing to repeat',)":
                 pass
             else:
                 raise e
Beispiel #3
0
 def test_single_line(self):
     #basicConfig(level=DEBUG)
     line = DfaRegexp('(*SOL)[a-z]*(*EOL)')
     line.config.default_line_aware()
     parser = line.get_parse_string()
     assert parser('abc') == ['abc']
Beispiel #4
0
 def test_start(self):
     #basicConfig(level=DEBUG)
     match = DfaRegexp('(*SOL)a*')
     match.config.default_line_aware().no_full_first_match()
     result = list(match.match_string('abc'))[0][0]
     assert result == ['a'], result
Beispiel #5
0
 def test_invert_bug_1(self):
     #basicConfig(level=DEBUG)
     match = DfaRegexp('(*SOL)[^c]*')
     match.config.default_line_aware().trace(True).no_full_first_match()
     result = list(match.match_string('abc'))[0][0]
     assert result == ['ab'], result
Beispiel #6
0
 def test_start(self):
     #basicConfig(level=DEBUG)
     match = DfaRegexp('(*SOL)a*')
     match.config.default_line_aware().no_full_first_match()
     result = list(match.match_string('abc'))[0][0]
     assert result == ['a'], result
Beispiel #7
0
 def test_invert_bug_1(self):
     #basicConfig(level=DEBUG)
     match = DfaRegexp('(*SOL)[^c]*')
     match.config.default_line_aware().trace(True).no_full_first_match()
     result = list(match.match_string('abc'))[0][0]
     assert result == ['ab'], result