Esempio n. 1
0
        public void Test_can_parse_multiple_queries()
        {
            CmsqlQueryParser      parser      = new CmsqlQueryParser();
            CmsqlQueryParseResult parseResult = parser.Parse(
                "select test from start;select test from root where foo = 'bar';select barf from 123 where (foo = 'bar' and bar = 'foo') or (bla = 'bli' and bli = 'bla')");

            parseResult.Queries.Should().HaveCount(3);
            parseResult.Errors.Should().BeNullOrEmpty();

            CmsqlQuery firstQuery = parseResult.Queries.First();

            firstQuery.ContentType.ShouldBeEquivalentTo("test");
            firstQuery.StartNode.StartNodeId.Should().BeNullOrEmpty();
            firstQuery.StartNode.StartNodeType.ShouldBeEquivalentTo(CmsqlQueryStartNodeType.Start);
            firstQuery.Criteria.Should().BeNull();

            CmsqlQuery secondQuery = parseResult.Queries.ElementAt(1);

            secondQuery.ContentType.ShouldBeEquivalentTo("test");
            secondQuery.StartNode.StartNodeId.Should().BeNullOrEmpty();
            secondQuery.StartNode.StartNodeType.ShouldBeEquivalentTo(CmsqlQueryStartNodeType.Root);
            secondQuery.Criteria.Should().BeOfType <CmsqlQueryCondition>();
            CmsqlQueryCondition condition = secondQuery.Criteria as CmsqlQueryCondition;

            condition.Identifier.ShouldBeEquivalentTo("foo");
            condition.Operator.ShouldBeEquivalentTo(EqualityOperator.Equals);
            condition.Value.ShouldBeEquivalentTo("bar");

            CmsqlQuery thirdQuery = parseResult.Queries.ElementAt(2);

            thirdQuery.ContentType.ShouldBeEquivalentTo("barf");
            thirdQuery.StartNode.StartNodeId.ShouldBeEquivalentTo("123");
            thirdQuery.StartNode.StartNodeType.ShouldBeEquivalentTo(CmsqlQueryStartNodeType.Id);
            thirdQuery.Criteria.Should().BeOfType <CmsqlQueryBinaryExpression>();
        }
Esempio n. 2
0
        public void Test_can_parse_valid_query_with_where_clause_with_terminator(string query)
        {
            CmsqlParser cmsqlParser = CmsqlParserFactory.CreateParserForQuery(query);

            CmsqlParser.QueryContext parseTree = cmsqlParser.query();

            QueryVisitor visitor    = new QueryVisitor();
            CmsqlQuery   cmsqlQuery = visitor.VisitQuery(parseTree);

            cmsqlQuery.Should().NotBeNull();
            cmsqlQuery.ContentType.Should().NotBeNullOrEmpty();
            cmsqlQuery.StartNode.Should().NotBeNull();
            cmsqlQuery.Criteria.Should().NotBeNull();
        }
Esempio n. 3
0
        public void Test_can_parse_single_query_with_terminator()
        {
            CmsqlQueryParser      parser      = new CmsqlQueryParser();
            CmsqlQueryParseResult parseResult = parser.Parse("select test from start;");

            parseResult.Queries.Should().NotBeNullOrEmpty();
            parseResult.Queries.Should().HaveCount(1);
            parseResult.Errors.Should().BeNullOrEmpty();

            CmsqlQuery query = parseResult.Queries.First();

            query.ContentType.ShouldBeEquivalentTo("test");
            query.StartNode.StartNodeId.Should().BeNullOrEmpty();
            query.StartNode.StartNodeType.ShouldBeEquivalentTo(CmsqlQueryStartNodeType.Start);
            query.Criteria.Should().BeNull();
        }