def test_iter_with_unmatched_simple3(self):
     t = Trie()
     t.add('AND', 'AND')
     t.make_automaton()
     test_string = 'AND  an a andersom'
     result = list(t.iter(test_string))
     assert ['AND'] == [r.value for r in result]
예제 #2
0
 def test_iter_with_unmatched_simple2(self):
     t = Trie()
     t.add('AND', 'AND')
     t.make_automaton()
     test_string = 'AND  an a and'
     result = list(t.iter(test_string))
     assert 'ANDand' == ''.join(r.string for r in result)
    def test_iter_simple(self):
        t = Trie()
        t.add('AND', 'AND')
        t.add('OR', 'OR')
        t.add('WITH', 'WITH')
        t.add('(', '(')
        t.add(')', ')')
        t.add('GPL-2.0', 'GPL-2.0')
        t.add('mit', 'MIT')
        t.add('Classpath', 'Classpath')
        t.make_automaton()
        test_string = '(GPL-2.0 with Classpath) or (gpl-2.0) and (classpath or  gpl-2.0 OR mit) '
        #                        111111111122222222223333333333444444444455555555556666666666777
        #              0123456789012345678901234567890123456789012345678901234567890123456789012
        result = list(t.iter(test_string))
        expected = [
            Token(0, 0, u'(', u'('),
            Token(1, 7, u'GPL-2.0', u'GPL-2.0'),
            Token(9, 12, u'with', u'WITH'),
            Token(14, 22, u'Classpath', u'Classpath'),
            Token(23, 23, u')', u')'),
            Token(25, 26, u'or', u'OR'),
            Token(28, 28, u'(', u'('),
            Token(29, 35, u'gpl-2.0', u'GPL-2.0'),
            Token(36, 36, u')', u')'),
            Token(38, 40, u'and', u'AND'),
            Token(42, 42, u'(', u'('),
            Token(43, 51, u'classpath', u'Classpath'),
            Token(53, 54, u'or', u'OR'),
            Token(57, 63, u'gpl-2.0', u'GPL-2.0'),
            Token(65, 66, u'OR', u'OR'),
            Token(68, 70, u'mit', u'MIT'),
            Token(71, 71, u')', u')')
        ]

        assert expected == result