fune/testing/mozbase/manifestparser/tests/test_expressionparser.py
William Lachance 543aa429dc Bug 984528 - Rename manifestdestiny -> manifestparser. r=ahal
--HG--
rename : testing/mozbase/docs/manifestdestiny.rst => testing/mozbase/docs/manifestparser.rst
rename : testing/mozbase/manifestdestiny/manifestparser/__init__.py => testing/mozbase/manifestparser/manifestparser/__init__.py
rename : testing/mozbase/manifestdestiny/manifestparser/manifestparser.py => testing/mozbase/manifestparser/manifestparser/manifestparser.py
rename : testing/mozbase/manifestdestiny/setup.py => testing/mozbase/manifestparser/setup.py
rename : testing/mozbase/manifestdestiny/tests/comment-example.ini => testing/mozbase/manifestparser/tests/comment-example.ini
rename : testing/mozbase/manifestdestiny/tests/default-skipif.ini => testing/mozbase/manifestparser/tests/default-skipif.ini
rename : testing/mozbase/manifestdestiny/tests/filter-example.ini => testing/mozbase/manifestparser/tests/filter-example.ini
rename : testing/mozbase/manifestdestiny/tests/fleem => testing/mozbase/manifestparser/tests/fleem
rename : testing/mozbase/manifestdestiny/tests/include-example.ini => testing/mozbase/manifestparser/tests/include-example.ini
rename : testing/mozbase/manifestdestiny/tests/include/bar.ini => testing/mozbase/manifestparser/tests/include/bar.ini
rename : testing/mozbase/manifestdestiny/tests/include/crash-handling => testing/mozbase/manifestparser/tests/include/crash-handling
rename : testing/mozbase/manifestdestiny/tests/include/flowers => testing/mozbase/manifestparser/tests/include/flowers
rename : testing/mozbase/manifestdestiny/tests/include/foo.ini => testing/mozbase/manifestparser/tests/include/foo.ini
rename : testing/mozbase/manifestdestiny/tests/just-defaults.ini => testing/mozbase/manifestparser/tests/just-defaults.ini
rename : testing/mozbase/manifestdestiny/tests/manifest.ini => testing/mozbase/manifestparser/tests/manifest.ini
rename : testing/mozbase/manifestdestiny/tests/mozmill-example.ini => testing/mozbase/manifestparser/tests/mozmill-example.ini
rename : testing/mozbase/manifestdestiny/tests/mozmill-restart-example.ini => testing/mozbase/manifestparser/tests/mozmill-restart-example.ini
rename : testing/mozbase/manifestdestiny/tests/no-tests.ini => testing/mozbase/manifestparser/tests/no-tests.ini
rename : testing/mozbase/manifestdestiny/tests/path-example.ini => testing/mozbase/manifestparser/tests/path-example.ini
rename : testing/mozbase/manifestdestiny/tests/relative-path.ini => testing/mozbase/manifestparser/tests/relative-path.ini
rename : testing/mozbase/manifestdestiny/tests/test_convert_directory.py => testing/mozbase/manifestparser/tests/test_convert_directory.py
rename : testing/mozbase/manifestdestiny/tests/test_convert_symlinks.py => testing/mozbase/manifestparser/tests/test_convert_symlinks.py
rename : testing/mozbase/manifestdestiny/tests/test_default_skipif.py => testing/mozbase/manifestparser/tests/test_default_skipif.py
rename : testing/mozbase/manifestdestiny/tests/test_expressionparser.py => testing/mozbase/manifestparser/tests/test_expressionparser.py
rename : testing/mozbase/manifestdestiny/tests/test_manifestparser.py => testing/mozbase/manifestparser/tests/test_manifestparser.py
rename : testing/mozbase/manifestdestiny/tests/test_read_ini.py => testing/mozbase/manifestparser/tests/test_read_ini.py
rename : testing/mozbase/manifestdestiny/tests/test_testmanifest.py => testing/mozbase/manifestparser/tests/test_testmanifest.py
rename : testing/mozbase/manifestdestiny/tests/verifyDirectory/subdir/manifest.ini => testing/mozbase/manifestparser/tests/verifyDirectory/subdir/manifest.ini
rename : testing/mozbase/manifestdestiny/tests/verifyDirectory/subdir/test_sub.js => testing/mozbase/manifestparser/tests/verifyDirectory/subdir/test_sub.js
rename : testing/mozbase/manifestdestiny/tests/verifyDirectory/test_1.js => testing/mozbase/manifestparser/tests/verifyDirectory/test_1.js
rename : testing/mozbase/manifestdestiny/tests/verifyDirectory/test_2.js => testing/mozbase/manifestparser/tests/verifyDirectory/test_2.js
rename : testing/mozbase/manifestdestiny/tests/verifyDirectory/test_3.js => testing/mozbase/manifestparser/tests/verifyDirectory/test_3.js
rename : testing/mozbase/manifestdestiny/tests/verifyDirectory/verifyDirectory.ini => testing/mozbase/manifestparser/tests/verifyDirectory/verifyDirectory.ini
rename : testing/mozbase/manifestdestiny/tests/verifyDirectory/verifyDirectory_incomplete.ini => testing/mozbase/manifestparser/tests/verifyDirectory/verifyDirectory_incomplete.ini
rename : testing/mozbase/manifestdestiny/tests/verifyDirectory/verifyDirectory_toocomplete.ini => testing/mozbase/manifestparser/tests/verifyDirectory/verifyDirectory_toocomplete.ini
2014-06-10 13:20:23 -04:00

95 lines
4 KiB
Python
Executable file

#!/usr/bin/env python
import unittest
from manifestparser import parse
class ExpressionParserTest(unittest.TestCase):
"""Test the conditional expression parser."""
def test_basic(self):
self.assertEqual(parse("1"), 1)
self.assertEqual(parse("100"), 100)
self.assertEqual(parse("true"), True)
self.assertEqual(parse("false"), False)
self.assertEqual('', parse('""'))
self.assertEqual(parse('"foo bar"'), 'foo bar')
self.assertEqual(parse("'foo bar'"), 'foo bar')
self.assertEqual(parse("foo", foo=1), 1)
self.assertEqual(parse("bar", bar=True), True)
self.assertEqual(parse("abc123", abc123="xyz"), 'xyz')
def test_equality(self):
self.assertTrue(parse("true == true"))
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))
self.assertTrue(parse("!false"))
def test_conjunctures(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_parentheses(self):
self.assertTrue(parse("(true)"))
self.assertEqual(parse("(10)"), 10)
self.assertEqual(parse('("foo")'), 'foo')
self.assertEqual(parse("(foo)", foo=1), 1)
self.assertTrue(parse("(true == 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)"))
self.assertTrue(parse("(true && false) || (true && (true || false))"))
def test_comments(self):
# comments in expressions work accidentally, via an implementation
# detail - the '#' character doesn't match any of the regular
# expressions we specify as tokens, and thus are ignored.
# However, having explicit tests for them means that should the
# implementation ever change, comments continue to work, even if that
# means a new implementation must handle them explicitly.
self.assertTrue(parse("true == true # it does!"))
self.assertTrue(parse("false == false # it does"))
self.assertTrue(parse("false != true # it doesnt"))
self.assertTrue(parse('"string with #" == "string with #" # really, it does'))
self.assertTrue(parse('"string with #" != "string with # but not the same" # no match!'))
def test_not(self):
"""
Test the ! operator.
"""
self.assertTrue(parse("!false"))
self.assertTrue(parse("!(false)"))
self.assertFalse(parse("!true"))
self.assertFalse(parse("!(true)"))
self.assertTrue(parse("!true || true)"))
self.assertTrue(parse("true || !true)"))
self.assertFalse(parse("!true && true"))
self.assertFalse(parse("true && !true"))
if __name__ == '__main__':
unittest.main()