[Zope-CVS] CVS: Products/ZCTextIndex/tests - testQueryParser.py:1.1.2.2

Guido van Rossum guido@python.org
Tue, 30 Apr 2002 16:36:36 -0400


Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv21037

Modified Files:
      Tag: TextIndexDS9-branch
	testQueryParser.py 
Log Message:
Add tests for illegal syntax.

Simplify test_suite().


=== Products/ZCTextIndex/tests/testQueryParser.py 1.1.2.1 => 1.1.2.2 ===
 
 from Products.ZCTextIndex.QueryParser import \
-     QueryParser, ParseTreeNode, OrNode, AndNode, NotNode, AtomNode
+     QueryParser, ParseError, ParseTreeNode, OrNode, AndNode, NotNode, AtomNode
 
 class TestQueryParser(TestCase):
 
@@ -41,6 +41,9 @@
         tree = self.p.parseQuery(input)
         self.compareParseTrees(tree, output)
 
+    def failure(self, input):
+        self.assertRaises(ParseError, self.p.parseQuery, input)
+
     def setUp(self):
         self.p = QueryParser()
 
@@ -60,12 +63,27 @@
                              OrNode([AtomNode("c"), AtomNode("d")])]))
         self.expect("a AND NOT b",
                     AndNode([AtomNode("a"), NotNode(AtomNode("b"))]))
-                    
+
+    def testParseFailures(self):
+        self.failure("")
+        self.failure("OR")
+        self.failure("AND")
+        self.failure("NOT")
+        self.failure(")")
+        self.failure("(")
+        self.failure("foo bar")
+        self.failure("foo OR")
+        self.failure("foo AND")
+        self.failure("OR foo")
+        self.failure("AND foo")
+        self.failure("(foo bar)")
+        self.failure("(foo OR)")
+        self.failure("(foo AND)")
+        self.failure("(NOT)")
+
 
 def test_suite():
-    return TestSuite((
-        makeSuite(TestQueryParser),
-        ))
+    return makeSuite(TestQueryParser)
 
 if __name__=='__main__':
     main(defaultTest='test_suite')