Mercurial > hg > expressionparser
changeset 5:e55489813783
put tests in sseparate file
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 03 Jun 2011 08:23:19 -0700 |
parents | a42bb6dc2fa7 |
children | 4b07bb71c218 |
files | test.py |
diffstat | 1 files changed, 64 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test.py Fri Jun 03 08:23:19 2011 -0700 @@ -0,0 +1,64 @@ +#!/usr/bin/env python + +from expr import parse +import unittest + +class ExpressionParserUnittest(unittest.TestCase): + + + def test_BasicValues(self): + self.assertEqual(1, parse("1")) + self.assertEqual(100, parse("100")) + self.assertEqual(True, parse("true")) + self.assertEqual(False, parse("false")) + self.assertEqual("", parse('""')) + self.assertEqual("foo bar", parse('"foo bar"')) + self.assertEqual(1, parse("foo", foo=1)) + self.assertEqual(True, parse("bar", bar=True)) + self.assertEqual("xyz", parse("abc123", abc123="xyz")) + + def test_Equality(self): + self.assertTrue(parse("true == true")) + self.assertTrue(parse("false == false")) + self.assertTrue(parse("false == false")) + self.assertTrue(parse("1 == 1")) + self.assertTrue(parse("100 == 100")) + self.assertTrue(parse('"some text" == "some text"')) + self.assertTrue(parse("true != false")) + self.assertTrue(parse("1 != 2")) + self.assertTrue(parse('"text" != "other text"')) + self.assertTrue(parse("foo == true", foo=True)) + self.assertTrue(parse("foo == 1", foo=1)) + self.assertTrue(parse('foo == "bar"', foo='bar')) + self.assertTrue(parse("foo == bar", foo=True, bar=True)) + self.assertTrue(parse("true == foo", foo=True)) + self.assertTrue(parse("foo != true", foo=False)) + self.assertTrue(parse("foo != 2", foo=1)) + self.assertTrue(parse('foo != "bar"', foo='abc')) + self.assertTrue(parse("foo != bar", foo=True, bar=False)) + self.assertTrue(parse("true != foo", foo=False)) + + def test_Conjunctions(self): + self.assertTrue(parse("true && true")) + self.assertTrue(parse("true || false")) + self.assertFalse(parse("false || false")) + self.assertFalse(parse("true && false")) + self.assertTrue(parse("true || false && false")) + + def test_Parens(self): + self.assertTrue(parse("(true)")) + self.assertEquals(10, parse("(10)")) + self.assertEquals('foo', parse('("foo")')) + self.assertEquals(1, parse("(foo)", foo=1)) + self.assertTrue(parse("(true == true)")) + self.assertTrue(parse("(true != false)")) + self.assertTrue(parse("(true && true)")) + self.assertTrue(parse("(true || false)")) + self.assertTrue(parse("(true && true || false)")) + self.assertFalse(parse("(true || false) && false")) + self.assertTrue(parse("(true || false) && true")) + self.assertTrue(parse("true && (true || false)")) + self.assertTrue(parse("true && (true || false)")) + +if __name__ == '__main__': + unittest.main()