Esempio n. 1
0
 def test_and_containing_ors(self):
     """Does this explode? Right now, visit_branch assumes that Ands receive only strings or USELESS."""
     eq_(
         visit_regex('(a|b)(c|d)'),
         Or([
             And([
                 Or([And(['a']), And(['b'])]),
                 Or([And(['c']), And(['d'])])
             ])
         ]))
Esempio n. 2
0
 def test_wtf(self):
     """Guard against an ill-defined WTF we had."""
     eq_(
         visit_regex('(aa|b)(c|d)'),
         Or([
             And([
                 Or([And(['aa']), And(['b'])]),
                 Or([And(['c']), And(['d'])])
             ])
         ]))
Esempio n. 3
0
    def test_empty(self):
        """Pin down what empty top-level trees turn into.

        I'm not sure the current state is desirable. '' is another
        possibility, but I worry about what Or(['hi', '']) means. [It means
        "hi can occur, or not", which makes it useless.]

        """
        eq_(Or([And()]).simplified(), '')
Esempio n. 4
0
 def test_big_tree(self):
     """Try the ambitious tree (a|b)(c|d)."""
     eq_(
         Or([
             And([
                 Or([And(['alpha']), And(['bravo'])]),
                 Or([And(['charlie']), And(['delta'])])
             ])
         ]).simplified(),
         And([Or(['alpha', 'bravo']),
              Or(['charlie', 'delta'])]))
Esempio n. 5
0
 def test_short_ngram_removal(self):
     """Substrings shorter than 3 chars should be removed."""
     eq_(And(['oof', 'by', 'smurf']).simplified(), And(['oof', 'smurf']))
     eq_(Or(['', 'by', 'smurf']).simplified(), 'smurf')
     eq_(Or([And(['', 'e', 'do']), 'hi']).simplified(), '')
Esempio n. 6
0
 def test_not_coalescing_over_uselesses(self):
     """Don't coalesce 2 strings that have a USELESS between them."""
     eq_(visit_regex('arkb*cork').simplified(), And(['ark', 'cork']))
Esempio n. 7
0
 def test_nopes(self):
     """These examples should not simplify down to strings."""
     ok_(not isinstance(
         And(['smoo', Or(['him'])]).simplified(), basestring))
     eq_(Or(['smoo', 'him']).simplified(), Or(['smoo', 'him']))
Esempio n. 8
0
 def test_single_strings(self):
     """These should simplify down to single strings."""
     eq_(And(['smoo']).simplified(), 'smoo')
     eq_(And(Or(['smoo'])).simplified(), 'smoo')
     eq_(Or(And(['smoo'])).simplified(), 'smoo')
Esempio n. 9
0
 def test_nested_tree(self):
     """Make sure Ors containing Ands build properly."""
     eq_(visit_regex('ab[^q](cd|ef)'),
         Or([And(['ab', Or([And(['cd']), And(['ef'])])])]))
     eq_(visit_regex('ab(cd|ef)'),
         Or([And(['ab', Or([And(['cd']), And(['ef'])])])]))
Esempio n. 10
0
 def test_empty_branch(self):
     """Make sure the right kind of tree is built when a branch is empty."""
     eq_(visit_regex('(a||b)'),
         Or([And([Or([And(['a']), And(['']),
                      And(['b'])])])]))
Esempio n. 11
0
 def test_anded_uselesses(self):
     """Make USELESSes break up contiguous strings of literals."""
     eq_(visit_regex('ab[^q]cd'), Or([And(['ab', 'cd'])]))
Esempio n. 12
0
 def test_3_branches(self):
     eq_(visit_regex('ab|cd|ef'),
         Or([And(['ab']), And(['cd']),
             And(['ef'])]))
Esempio n. 13
0
 def test_merge_literals(self):
     """Make sure we know how to merge adjacent char literals."""
     eq_(visit_regex('abcd'), Or([And(['abcd'])]))