Exemplo n.º 1
0
 def test_bat_brat_cat(self):
     strings = ['bat', 'brat', 'cat']
     # NOTE: our crappy DAWG doesn't merge suffixes for strings that don't start the same...
     # dawg = DAWG.from_iter(strings)
     # print(dawg)
     # self.assertEqual('(br?|c)at', match(strings))
     self.assertEqual('(br?at|cat)', match(strings))
Exemplo n.º 2
0
 def test_parens2(self):
     strings = ['aa', 'ab', 'bb']
     # dawg = DAWG.from_list(strings)
     # print(dawg)
     # [ab][ab]
     # (a[ab]|bb)
     self.assertEqual('(a[ab]|bb)', match(strings))
Exemplo n.º 3
0
    def test_numbers(self):
        # (100?|[1-9]|)|[2-9][0-9]?|0
        # (0|(1(|00?|[1-9]))|[2-9][0-9]?)
        # (0|(1(|00?|[1-9]))|[2-9][0-9]?)

        # (100?|[1-9]|)|[02-9][0-9]?
        # (100|[0-9][0-9]?)
        # (1?[0-9][0-9]?)  XXX: too broad
        vals = [str(n) for n in range(101)]
        pattern = match(vals)
        fullpat = '^({})$'.format(pattern)
        self.assertTrue(all(re.match(fullpat, v) for v in vals))
        self.assertEqual('(0|1(00?|[1-9]?)|[2-9][0-9]?)', pattern)
Exemplo n.º 4
0
 def test_greenred(self):
     strings = ['Black', 'Blue', 'Green', 'Red']
     self.assertEqual('(Bl(ack|ue)|Green|Red)', match(strings))
Exemplo n.º 5
0
 def test_parens4(self):
     strings = ['aaa', 'abb', 'cc', 'dd']
     self.assertEqual('(a(aa|bb)|cc|dd)', match(strings))
Exemplo n.º 6
0
 def test_parens3(self):
     strings = ['aaa', 'abb', 'c']
     self.assertEqual('(a(aa|bb)|c)', match(strings))
Exemplo n.º 7
0
 def test_pattern(self):
     self.assertEqual(
         match(self.strings),
         '(E(Fgre(en|y)|ntireS[12])|J(27(Green|Red)P[12]|ournalP(1(Bl(ack|ue)|(Green|Red))|2(Bl(ack|ue)|Green))))'
     )
Exemplo n.º 8
0
 def test_1(self):
     self.assertEqual('0', match(['0']))
Exemplo n.º 9
0
 def test_optional_group_complex(self):
     # joe(s(eph)?|y?)  # technically accurate, as "y" is optional
     # joe(s(eph)?|y)?  # ...better, i think
     self.assertEqual('joe(s(eph)?|y?)',
                      match(['joe', 'joey', 'joes', 'joeseph']))
Exemplo n.º 10
0
 def test_shared_suffix_abcdef_def(self):
     strings = ['abcdef', 'def']
     self.assertEqual('(abc)?def', match(strings))
Exemplo n.º 11
0
 def test_float_variable_prefix23(self):
     # 0(|.1(|23))
     # 0(.1(23)?)?
     self.assertEqual('0(.1(23)?)?', match(['0', '0.1', '0.123']))
Exemplo n.º 12
0
 def test_float_variable_prefix(self):
     self.assertEqual('0(.12?)?', match(['0', '0.1', '0.12']))
Exemplo n.º 13
0
 def test_float_maybe_(self):
     # self.assertEqual('([0-9]|[0-9]\.[0-9])',
     #                match(['0', '0.1']))
     self.assertEqual('0(\.1)?', match(['0', '0.1']))
Exemplo n.º 14
0
 def test_float_maybe_dot(self):
     # self.assertEqual('([0-9]|[0-9]\.)', match(['0', '0.']))
     self.assertEqual('0\.?', match(['0', '0.']))
Exemplo n.º 15
0
 def test_0_1(self):
     self.assertEqual('(0 0|1 1)', match(['0 0', '1 1']))
Exemplo n.º 16
0
 def test_dupes(self):
     self.assertEqual('0', match(['0', '0']))
Exemplo n.º 17
0
 def test_tap_taps_top_tops(self):
     strings = ['tap', 'taps', 'top', 'tops']
     self.assertEqual('t[ao]ps?', match(strings))
Exemplo n.º 18
0
 def test_hundreds(self):
     '''test that shared suffixes are combined even when first char differs...'''
     # TODO: combining shared suffixes does not work if beginning is different
     self.assertEqual('[12]00', match(['100', '200']))
Exemplo n.º 19
0
 def test_optional_space(self):
     self.assertEqual('a( b)?', match(['a', 'a b']))
Exemplo n.º 20
0
 def test_100_101(self):
     self.assertEqual('10[01]', match(['100', '101']))
Exemplo n.º 21
0
 def test_empty(self):
     strings = ['', 'aa', 'bb']
     self.assertEqual('(aa|bb)?', match(strings))
Exemplo n.º 22
0
 def test_empty(self):
     self.assertEqual('', match([]))