Exemplo n.º 1
0
 def testPrecedenceOrAnd(self):
     answer = CQL_QUERY(
         SCOPED_CLAUSE(
             SEARCH_CLAUSE(SEARCH_TERM(TERM('term1'))), BOOLEAN('or'),
             SCOPED_CLAUSE(
                 SCOPED_CLAUSE(SEARCH_CLAUSE(SEARCH_TERM(TERM('term2')))),
                 BOOLEAN('and'),
                 SEARCH_CLAUSE(SEARCH_TERM(TERM('term3'))))))
     self.assertEqualsCQL(answer, parseString('term1 or term2 and term3'))
Exemplo n.º 2
0
 def testPrecedenceAndAndAnd(self):
     expected = CQL_QUERY(
         SCOPED_CLAUSE(
             SCOPED_CLAUSE(
                 SCOPED_CLAUSE(
                     SCOPED_CLAUSE(SEARCH_CLAUSE(SEARCH_TERM(TERM('a'))), ),
                     BOOLEAN('and'), SEARCH_CLAUSE(SEARCH_TERM(TERM('b')))),
                 BOOLEAN('and'), SEARCH_CLAUSE(SEARCH_TERM(TERM('c')))),
             BOOLEAN('and'), SEARCH_CLAUSE(SEARCH_TERM(TERM('d')))))
     r = parseString("a and b and c and d")
     self.assertEqualsCQL(expected, r)
Exemplo n.º 3
0
 def testPrecedenceAndOr(self):
     answer = CQL_QUERY(
         SCOPED_CLAUSE(
             SEARCH_CLAUSE(
                 CQL_QUERY(
                     SCOPED_CLAUSE(
                         SCOPED_CLAUSE(
                             SEARCH_CLAUSE(SEARCH_TERM(TERM('term')))),
                         BOOLEAN('and'),
                         SEARCH_CLAUSE(SEARCH_TERM(TERM('term2')))))),
             BOOLEAN('or'),
             SCOPED_CLAUSE(SEARCH_CLAUSE(SEARCH_TERM(TERM('term3'))))))
     result = parseString('term and term2 or term3')
     self.assertEqualsCQL(answer, result)
Exemplo n.º 4
0
 def testTwoTerms(self):
     expected = CQL_QUERY(
         SCOPED_CLAUSE(
             SCOPED_CLAUSE(SEARCH_CLAUSE(SEARCH_TERM(TERM('term1'))), ),
             BOOLEAN('and'), SEARCH_CLAUSE(SEARCH_TERM(TERM('term2')))))
     r = parseString('term1 and term2')
     self.assertEqualsCQL(expected, r)
Exemplo n.º 5
0
 def testPrecedenceAndOr2(self):
     answer = CQL_QUERY(
         SCOPED_CLAUSE(
             SEARCH_CLAUSE(
                 CQL_QUERY(
                     SCOPED_CLAUSE(
                         SCOPED_CLAUSE(
                             SEARCH_CLAUSE(SEARCH_TERM(TERM('term')))),
                         BOOLEAN('and'),
                         SEARCH_CLAUSE(
                             parseString(
                                 'term2 and term3 and term4 and term5'))))),
             BOOLEAN('or'),
             SCOPED_CLAUSE(SEARCH_CLAUSE(SEARCH_TERM(TERM('term6'))))))
     r = parseString(
         'term and (term2 and term3 and term4 and term5) or term6')
     self.assertEqualsCQL(answer, r)
Exemplo n.º 6
0
 def testBooleansAreCaseInsensitive(self):
     self.assertEqualsCQL(
         CQL_QUERY(
             SCOPED_CLAUSE(
                 SCOPED_CLAUSE(SEARCH_CLAUSE(SEARCH_TERM(TERM('term')))),
                 BOOLEAN('and'),
                 SEARCH_CLAUSE(SEARCH_TERM(TERM('term2'))))),
         parseString('term AnD term2'))
Exemplo n.º 7
0
 def _addFilter(self, filterQuery):
     self._filters.append(filterQuery)
     insertOriginalAst = SCOPED_CLAUSE(SEARCH_CLAUSE(self.ast)) if len(self._filters) == 1 else self.ast.children[0]
     self.ast = CQL_QUERY(
         SCOPED_CLAUSE(
             insertOriginalAst,
             BOOLEAN('and'),
             filterQuery
         )
     )
Exemplo n.º 8
0
    def testParentheses(self):
        Q = CQL_QUERY
        SC = SCOPED_CLAUSE
        SE = SEARCH_CLAUSE
        ST = SEARCH_TERM
        T = TERM
        self.assertEqualsCQL(Q(SC(SE(Q(SC(SE(ST(T('term')))))))),
                             parseString('(term)'))
        self.assertEqualsCQL(Q(SC(SE(Q(SC(SE(Q(SC(SE(ST(T('term'))))))))))),
                             parseString('((term))'))

        self.assertEqualsCQL(
            Q(
                SC(
                    SE(
                        Q(
                            SC(SC(SE(ST(T('term')))), BOOLEAN('and'),
                               SE(ST(T('term2')))))))),
            parseString('(term and term2)'))

        self.assertException(CQLParseException, '(term')
        self.assertException(CQLParseException, '(term term2')