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))
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))
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)
def test_greenred(self): strings = ['Black', 'Blue', 'Green', 'Red'] self.assertEqual('(Bl(ack|ue)|Green|Red)', match(strings))
def test_parens4(self): strings = ['aaa', 'abb', 'cc', 'dd'] self.assertEqual('(a(aa|bb)|cc|dd)', match(strings))
def test_parens3(self): strings = ['aaa', 'abb', 'c'] self.assertEqual('(a(aa|bb)|c)', match(strings))
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))))' )
def test_1(self): self.assertEqual('0', match(['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']))
def test_shared_suffix_abcdef_def(self): strings = ['abcdef', 'def'] self.assertEqual('(abc)?def', match(strings))
def test_float_variable_prefix23(self): # 0(|.1(|23)) # 0(.1(23)?)? self.assertEqual('0(.1(23)?)?', match(['0', '0.1', '0.123']))
def test_float_variable_prefix(self): self.assertEqual('0(.12?)?', match(['0', '0.1', '0.12']))
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']))
def test_float_maybe_dot(self): # self.assertEqual('([0-9]|[0-9]\.)', match(['0', '0.'])) self.assertEqual('0\.?', match(['0', '0.']))
def test_0_1(self): self.assertEqual('(0 0|1 1)', match(['0 0', '1 1']))
def test_dupes(self): self.assertEqual('0', match(['0', '0']))
def test_tap_taps_top_tops(self): strings = ['tap', 'taps', 'top', 'tops'] self.assertEqual('t[ao]ps?', match(strings))
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']))
def test_optional_space(self): self.assertEqual('a( b)?', match(['a', 'a b']))
def test_100_101(self): self.assertEqual('10[01]', match(['100', '101']))
def test_empty(self): strings = ['', 'aa', 'bb'] self.assertEqual('(aa|bb)?', match(strings))
def test_empty(self): self.assertEqual('', match([]))