annotate test.py @ 12:835efd8acb04

add some vocab
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 03 Jun 2011 11:09:08 -0700
parents 4b07bb71c218
children ec0e83ec329f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 from expr import parse
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 import unittest
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 class ExpressionParserUnittest(unittest.TestCase):
6
4b07bb71c218 add a docstring
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
7 """test the expression parser"""
5
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 def test_BasicValues(self):
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 self.assertEqual(1, parse("1"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 self.assertEqual(100, parse("100"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 self.assertEqual(True, parse("true"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 self.assertEqual(False, parse("false"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 self.assertEqual("", parse('""'))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 self.assertEqual("foo bar", parse('"foo bar"'))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 self.assertEqual(1, parse("foo", foo=1))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 self.assertEqual(True, parse("bar", bar=True))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 self.assertEqual("xyz", parse("abc123", abc123="xyz"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 def test_Equality(self):
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 self.assertTrue(parse("true == true"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 self.assertTrue(parse("false == false"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 self.assertTrue(parse("false == false"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 self.assertTrue(parse("1 == 1"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 self.assertTrue(parse("100 == 100"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 self.assertTrue(parse('"some text" == "some text"'))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 self.assertTrue(parse("true != false"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28 self.assertTrue(parse("1 != 2"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29 self.assertTrue(parse('"text" != "other text"'))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30 self.assertTrue(parse("foo == true", foo=True))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 self.assertTrue(parse("foo == 1", foo=1))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 self.assertTrue(parse('foo == "bar"', foo='bar'))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 self.assertTrue(parse("foo == bar", foo=True, bar=True))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 self.assertTrue(parse("true == foo", foo=True))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35 self.assertTrue(parse("foo != true", foo=False))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36 self.assertTrue(parse("foo != 2", foo=1))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
37 self.assertTrue(parse('foo != "bar"', foo='abc'))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
38 self.assertTrue(parse("foo != bar", foo=True, bar=False))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39 self.assertTrue(parse("true != foo", foo=False))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
40
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
41 def test_Conjunctions(self):
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
42 self.assertTrue(parse("true && true"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
43 self.assertTrue(parse("true || false"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
44 self.assertFalse(parse("false || false"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45 self.assertFalse(parse("true && false"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
46 self.assertTrue(parse("true || false && false"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
47
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
48 def test_Parens(self):
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
49 self.assertTrue(parse("(true)"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
50 self.assertEquals(10, parse("(10)"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
51 self.assertEquals('foo', parse('("foo")'))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
52 self.assertEquals(1, parse("(foo)", foo=1))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
53 self.assertTrue(parse("(true == true)"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
54 self.assertTrue(parse("(true != false)"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
55 self.assertTrue(parse("(true && true)"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
56 self.assertTrue(parse("(true || false)"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
57 self.assertTrue(parse("(true && true || false)"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
58 self.assertFalse(parse("(true || false) && false"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
59 self.assertTrue(parse("(true || false) && true"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
60 self.assertTrue(parse("true && (true || false)"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
61 self.assertTrue(parse("true && (true || false)"))
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
62
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
63 if __name__ == '__main__':
e55489813783 put tests in sseparate file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
64 unittest.main()