예제 #1
0
 def test_ids(self):
     self.assertEqual(list(lex('foo')), ['foo'])
     self.assertEqual(list(lex('foo bar')), ['foo', 'bar'])
     self.assertEqual(list(lex('foo   bar')), ['foo', 'bar'])
     self.assertEqual(list(lex('  foo bar')), ['foo', 'bar'])
     self.assertEqual(list(lex('foo bar  ')), ['foo', 'bar'])
     self.assertEqual(list(lex('   foo   bar   ')), ['foo', 'bar'])
예제 #2
0
    def test_expressions(self):
        self.assertEqual(list(lex('a and b')), ['a', 'and', 'b'])
        self.assertEqual(list(lex('a and b or c')),
                         ['a', 'and', 'b', 'or', 'c'])

        self.assertEqual(list(lex('(a)')), ['(', 'a', ')'])
        self.assertEqual(list(lex('(a and b) or c')),
                         ['(', 'a', 'and', 'b', ')', 'or', 'c'])
        self.assertEqual(list(lex('(a and b)or c')),
                         ['(', 'a', 'and', 'b', ')', 'or', 'c'])

        self.assertEqual(list(lex('not (a and b) or c')),
                         ['not', '(', 'a', 'and', 'b', ')', 'or', 'c'])
        self.assertEqual(list(lex('not(a and b)or c')),
                         ['not', '(', 'a', 'and', 'b', ')', 'or', 'c'])

        self.assertEqual(list(lex('a and (b or c)')),
                         ['a', 'and', '(', 'b', 'or', 'c', ')'])
        self.assertEqual(list(lex('a and(b or c)')),
                         ['a', 'and', '(', 'b', 'or', 'c', ')'])
        self.assertEqual(list(lex('a and not (b or c)')),
                         ['a', 'and', 'not', '(', 'b', 'or', 'c', ')'])
        self.assertEqual(list(lex('a and not(b or c)')),
                         ['a', 'and', 'not', '(', 'b', 'or', 'c', ')'])
        self.assertEqual(list(lex('  a    and  (b   or  c) ')),
                         ['a', 'and', '(', 'b', 'or', 'c', ')'])
예제 #3
0
    def test_parens(self):
        self.assertEqual(list(lex('()')), ['(', ')'])
        self.assertEqual(list(lex(' ()')), ['(', ')'])
        self.assertEqual(list(lex('( )')), ['(', ')'])
        self.assertEqual(list(lex('() ')), ['(', ')'])
        self.assertEqual(list(lex(' ( ) ')), ['(', ')'])
        self.assertEqual(list(lex('  (  )  ')), ['(', ')'])
        self.assertEqual(list(lex('   (   )   ')), ['(', ')'])

        self.assertEqual(list(lex('(())')), ['(', '(', ')', ')'])
        self.assertEqual(list(lex('(  ())')), ['(', '(', ')', ')'])
        self.assertEqual(list(lex('((  ))')), ['(', '(', ')', ')'])
        self.assertEqual(list(lex('(())  ')), ['(', '(', ')', ')'])

        self.assertEqual(list(lex(')()(')), [')', '(', ')', '('])