Mercurial > hg > expressionparser
annotate test.py @ 15:6f0c032b65f5 default tip
add a not token, i hope!
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 03 Jun 2011 13:01:22 -0700 |
parents | facdc089ffbc |
children |
rev | line source |
---|---|
5 | 1 #!/usr/bin/env python |
2 | |
3 from expr import parse | |
4 import unittest | |
5 | |
6 class ExpressionParserUnittest(unittest.TestCase): | |
6 | 7 """test the expression parser""" |
5 | 8 |
9 def test_BasicValues(self): | |
10 self.assertEqual(1, parse("1")) | |
11 self.assertEqual(100, parse("100")) | |
12 self.assertEqual(True, parse("true")) | |
13 self.assertEqual(False, parse("false")) | |
14 self.assertEqual("", parse('""')) | |
15 self.assertEqual("foo bar", parse('"foo bar"')) | |
13
ec0e83ec329f
allow both kinds of strings
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
16 self.assertEqual("foo bar", parse("'foo bar'")) |
5 | 17 self.assertEqual(1, parse("foo", foo=1)) |
18 self.assertEqual(True, parse("bar", bar=True)) | |
19 self.assertEqual("xyz", parse("abc123", abc123="xyz")) | |
20 | |
21 def test_Equality(self): | |
22 self.assertTrue(parse("true == true")) | |
23 self.assertTrue(parse("false == false")) | |
24 self.assertTrue(parse("false == false")) | |
25 self.assertTrue(parse("1 == 1")) | |
26 self.assertTrue(parse("100 == 100")) | |
27 self.assertTrue(parse('"some text" == "some text"')) | |
28 self.assertTrue(parse("true != false")) | |
29 self.assertTrue(parse("1 != 2")) | |
30 self.assertTrue(parse('"text" != "other text"')) | |
31 self.assertTrue(parse("foo == true", foo=True)) | |
32 self.assertTrue(parse("foo == 1", foo=1)) | |
33 self.assertTrue(parse('foo == "bar"', foo='bar')) | |
34 self.assertTrue(parse("foo == bar", foo=True, bar=True)) | |
35 self.assertTrue(parse("true == foo", foo=True)) | |
36 self.assertTrue(parse("foo != true", foo=False)) | |
37 self.assertTrue(parse("foo != 2", foo=1)) | |
38 self.assertTrue(parse('foo != "bar"', foo='abc')) | |
39 self.assertTrue(parse("foo != bar", foo=True, bar=False)) | |
40 self.assertTrue(parse("true != foo", foo=False)) | |
15 | 41 self.assertTrue(parse("!false")) |
5 | 42 |
43 def test_Conjunctions(self): | |
44 self.assertTrue(parse("true && true")) | |
45 self.assertTrue(parse("true || false")) | |
46 self.assertFalse(parse("false || false")) | |
47 self.assertFalse(parse("true && false")) | |
48 self.assertTrue(parse("true || false && false")) | |
49 | |
50 def test_Parens(self): | |
51 self.assertTrue(parse("(true)")) | |
52 self.assertEquals(10, parse("(10)")) | |
53 self.assertEquals('foo', parse('("foo")')) | |
54 self.assertEquals(1, parse("(foo)", foo=1)) | |
55 self.assertTrue(parse("(true == true)")) | |
56 self.assertTrue(parse("(true != false)")) | |
57 self.assertTrue(parse("(true && true)")) | |
58 self.assertTrue(parse("(true || false)")) | |
59 self.assertTrue(parse("(true && true || false)")) | |
60 self.assertFalse(parse("(true || false) && false")) | |
61 self.assertTrue(parse("(true || false) && true")) | |
62 self.assertTrue(parse("true && (true || false)")) | |
63 self.assertTrue(parse("true && (true || false)")) | |
14
facdc089ffbc
add an additional parentheses test
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
64 self.assertTrue(parse("(true && false) || (true && (true || false))")) |
5 | 65 |
66 if __name__ == '__main__': | |
67 unittest.main() |