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'])
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', ')'])
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(')()(')), [')', '(', ')', '('])