Mercurial > hg > expressionparser
comparison test.py @ 5:e55489813783
put tests in sseparate file
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 03 Jun 2011 08:23:19 -0700 |
parents | |
children | 4b07bb71c218 |
comparison
equal
deleted
inserted
replaced
4:a42bb6dc2fa7 | 5:e55489813783 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 from expr import parse | |
4 import unittest | |
5 | |
6 class ExpressionParserUnittest(unittest.TestCase): | |
7 | |
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"')) | |
16 self.assertEqual(1, parse("foo", foo=1)) | |
17 self.assertEqual(True, parse("bar", bar=True)) | |
18 self.assertEqual("xyz", parse("abc123", abc123="xyz")) | |
19 | |
20 def test_Equality(self): | |
21 self.assertTrue(parse("true == true")) | |
22 self.assertTrue(parse("false == false")) | |
23 self.assertTrue(parse("false == false")) | |
24 self.assertTrue(parse("1 == 1")) | |
25 self.assertTrue(parse("100 == 100")) | |
26 self.assertTrue(parse('"some text" == "some text"')) | |
27 self.assertTrue(parse("true != false")) | |
28 self.assertTrue(parse("1 != 2")) | |
29 self.assertTrue(parse('"text" != "other text"')) | |
30 self.assertTrue(parse("foo == true", foo=True)) | |
31 self.assertTrue(parse("foo == 1", foo=1)) | |
32 self.assertTrue(parse('foo == "bar"', foo='bar')) | |
33 self.assertTrue(parse("foo == bar", foo=True, bar=True)) | |
34 self.assertTrue(parse("true == foo", foo=True)) | |
35 self.assertTrue(parse("foo != true", foo=False)) | |
36 self.assertTrue(parse("foo != 2", foo=1)) | |
37 self.assertTrue(parse('foo != "bar"', foo='abc')) | |
38 self.assertTrue(parse("foo != bar", foo=True, bar=False)) | |
39 self.assertTrue(parse("true != foo", foo=False)) | |
40 | |
41 def test_Conjunctions(self): | |
42 self.assertTrue(parse("true && true")) | |
43 self.assertTrue(parse("true || false")) | |
44 self.assertFalse(parse("false || false")) | |
45 self.assertFalse(parse("true && false")) | |
46 self.assertTrue(parse("true || false && false")) | |
47 | |
48 def test_Parens(self): | |
49 self.assertTrue(parse("(true)")) | |
50 self.assertEquals(10, parse("(10)")) | |
51 self.assertEquals('foo', parse('("foo")')) | |
52 self.assertEquals(1, parse("(foo)", foo=1)) | |
53 self.assertTrue(parse("(true == true)")) | |
54 self.assertTrue(parse("(true != false)")) | |
55 self.assertTrue(parse("(true && true)")) | |
56 self.assertTrue(parse("(true || false)")) | |
57 self.assertTrue(parse("(true && true || false)")) | |
58 self.assertFalse(parse("(true || false) && false")) | |
59 self.assertTrue(parse("(true || false) && true")) | |
60 self.assertTrue(parse("true && (true || false)")) | |
61 self.assertTrue(parse("true && (true || false)")) | |
62 | |
63 if __name__ == '__main__': | |
64 unittest.main() |