Ejemplo n.º 1
0
 def both(txt):
     return combine_ors(tokenize(txt))
Ejemplo n.º 2
0
 def both(txt): return combine_ors(tokenize(txt))
 self.assertEqual(both('this OR that AND jelly'), ['this OR that', 'AND', 'jelly'])
Ejemplo n.º 3
0
    def test_tokenize(self):
        self.assertEqual(tokenize("this that"), ["this", "AND", "that"])
        self.assertEqual(tokenize('"this that"'), ['"this that"'])
        self.assertEqual(tokenize("(this that)"), ["(this that)"])
        self.assertEqual(tokenize("(())"), ["(())"])
        self.assertEqual(tokenize('"(this OR that)"'), ['"(this OR that)"'])
        self.assertEqual(tokenize("this OR that"), ["this", "OR", "that"])
        self.assertEqual(tokenize("NOT Bob"), ["NOT Bob"])
        self.assertEqual(tokenize("NOT Bob Smith"), ["NOT Bob", "AND", "Smith"])
        self.assertEqual(tokenize('NOT "Bob Smith"'), ['NOT "Bob Smith"'])
        self.assertEqual(tokenize("a NOT (Bob Smith) b"), ["a", "AND", "NOT (Bob Smith)", "AND", "b"])
        self.assertEqual(tokenize("a(b)"), ["a", "AND", "(b)"])

        def both(txt):
            return combine_ors(tokenize(txt))

        self.assertEqual(both("this OR that AND jelly"), ["this OR that", "AND", "jelly"])
        self.assertEqual(both("this OR NOT that AND jelly"), ["this OR NOT that", "AND", "jelly"])
        self.assertEqual(both("NOT this, that"), ["NOT this,", "AND", "that"])
        self.assertEqual(type(both("abc")[0]), _tagstr)
        self.assertEqual(both("abc 123")[-1].char, 4)
        self.assertEqual(both("abc 123")[0].lineno, 0)
        self.assertEqual(both("abc\n123")[-1].char, 4)
        self.assertEqual(both("abc\n123")[-1].lineno, 1)
Ejemplo n.º 4
0
 def test_tokenize(self):
     self.assertEqual(tokenize('this that'), ['this', 'AND', 'that'])
     self.assertEqual(tokenize('"this that"'), ['"this that"'])
     self.assertEqual(tokenize('(this that)'), ['(this that)'])
     self.assertEqual(tokenize('(())'), ['(())'])
     self.assertEqual(tokenize('"(this OR that)"'), ['"(this OR that)"'])
     self.assertEqual(tokenize('this OR that'), ['this', 'OR', 'that'])
     self.assertEqual(tokenize('NOT Bob'), ['NOT Bob'])
     self.assertEqual(tokenize('NOT Bob Smith'), ['NOT Bob', 'AND', 'Smith'])
     self.assertEqual(tokenize('NOT "Bob Smith"'), ['NOT "Bob Smith"'])
     self.assertEqual(tokenize('a NOT (Bob Smith) b'), ['a', 'AND', 'NOT (Bob Smith)', 'AND', 'b'])
     self.assertEqual(tokenize('a(b)'), ['a', 'AND', '(b)'])
     def both(txt): return combine_ors(tokenize(txt))
     self.assertEqual(both('this OR that AND jelly'), ['this OR that', 'AND', 'jelly'])
     self.assertEqual(both('this OR NOT that AND jelly'), ['this OR NOT that', 'AND', 'jelly'])
     self.assertEqual(both('NOT this, that'), ['NOT this,', 'AND', 'that'])
     self.assertEqual(type(both('abc')[0]), _tagstr)
     self.assertEqual(both('abc 123')[-1].char, 4)
     self.assertEqual(both('abc 123')[0].lineno, 0)
     self.assertEqual(both('abc\n123')[-1].char, 4)
     self.assertEqual(both('abc\n123')[-1].lineno, 1)