public void Test_can_parse_binary_expression_for_two_parenthesized_expressions() { CmsqlParser cmsqlParser = CmsqlParserFactory.CreateParserForQuery( "(jon != 'stark' and john = 'snow') or (arya = 'stark' and sansa = 'stark')"); CmsqlParser.BinaryExpressionContext parseTree = (CmsqlParser.BinaryExpressionContext)cmsqlParser.expression(); ExpressionVisitor visitor = new ExpressionVisitor(); CmsqlQueryBinaryExpression binaryExpression = (CmsqlQueryBinaryExpression)visitor.VisitBinaryExpression(parseTree); binaryExpression.LeftExpression.Should().BeOfType <CmsqlQueryBinaryExpression>(); binaryExpression.LeftExpression.Should().NotBeNull(); binaryExpression.RightExpression.Should().BeOfType <CmsqlQueryBinaryExpression>(); binaryExpression.RightExpression.Should().NotBeNull(); CmsqlQueryBinaryExpression leftParenthesizedBinaryExpression = (CmsqlQueryBinaryExpression)binaryExpression.LeftExpression; leftParenthesizedBinaryExpression.LeftExpression.Should().BeOfType <CmsqlQueryCondition>(); leftParenthesizedBinaryExpression.LeftExpression.Should().NotBeNull(); leftParenthesizedBinaryExpression.RightExpression.Should().BeOfType <CmsqlQueryCondition>(); leftParenthesizedBinaryExpression.RightExpression.Should().NotBeNull(); CmsqlQueryBinaryExpression rightParenthesizedBinaryExpression = (CmsqlQueryBinaryExpression)binaryExpression.RightExpression; rightParenthesizedBinaryExpression.LeftExpression.Should().BeOfType <CmsqlQueryCondition>(); rightParenthesizedBinaryExpression.LeftExpression.Should().NotBeNull(); rightParenthesizedBinaryExpression.RightExpression.Should().BeOfType <CmsqlQueryCondition>(); rightParenthesizedBinaryExpression.RightExpression.Should().NotBeNull(); }
public void Test_can_parse_single_condition_as_expression() { CmsqlParser cmsqlParser = CmsqlParserFactory.CreateParserForQuery("where foo != 'bar'"); CmsqlParser.WhereClauseContext parseTree = cmsqlParser.whereClause(); WhereClauseVisitor visitor = new WhereClauseVisitor(); ICmsqlQueryExpression expression = visitor.VisitWhereClause(parseTree); expression.Should().BeOfType <CmsqlQueryCondition>(); }
public void Test_can_parse_valid_content_type_identifier(string queryIdentifier) { CmsqlParser cmsqlParser = CmsqlParserFactory.CreateParserForQuery($"select {queryIdentifier}"); CmsqlParser.SelectClauseContext parseTree = cmsqlParser.selectClause(); SelectClauseVisitor visitor = new SelectClauseVisitor(); string identifier = visitor.VisitSelectClause(parseTree); identifier.ShouldBeEquivalentTo(queryIdentifier); }
public void Test_can_parse_arbitrary_id_as_start_node(string id) { CmsqlParser cmsqlParser = CmsqlParserFactory.CreateParserForQuery($"from {id}"); CmsqlParser.FromClauseContext parseTree = cmsqlParser.fromClause(); FromClauseVisitor visitor = new FromClauseVisitor(); CmsqlQueryStartNode startNode = visitor.VisitFromClause(parseTree); startNode.StartNodeId.ShouldBeEquivalentTo(id); startNode.StartNodeType.ShouldBeEquivalentTo(CmsqlQueryStartNodeType.Id); }
public void Test_can_parse_root_as_start_node() { CmsqlParser cmsqlParser = CmsqlParserFactory.CreateParserForQuery("from root"); CmsqlParser.FromClauseContext parseTree = cmsqlParser.fromClause(); FromClauseVisitor visitor = new FromClauseVisitor(); CmsqlQueryStartNode startNode = visitor.VisitFromClause(parseTree); startNode.StartNodeId.Should().BeNullOrEmpty(); startNode.StartNodeType.ShouldBeEquivalentTo(CmsqlQueryStartNodeType.Root); }
public void Test_can_parse_multiple_valid_queries_without_where_clause(string query) { CmsqlParser cmsqlParser = CmsqlParserFactory.CreateParserForQuery(query); CmsqlParser.QueriesContext parseTree = cmsqlParser.queries(); QueriesVisitor visitor = new QueriesVisitor(); IEnumerable <CmsqlQuery> queries = visitor.VisitQueries(parseTree); queries.Should().NotBeNullOrEmpty(); queries.Should().HaveCount(3); }
public void Test_can_parse_grouped_expression_and_condition() { CmsqlParser cmsqlParser = CmsqlParserFactory.CreateParserForQuery("where (bar = 'foo' and foo = 'bar') or foo != 'bar'"); CmsqlParser.WhereClauseContext parseTree = cmsqlParser.whereClause(); WhereClauseVisitor visitor = new WhereClauseVisitor(); CmsqlQueryBinaryExpression binaryExpression = visitor.VisitWhereClause(parseTree) as CmsqlQueryBinaryExpression; binaryExpression.Operator.ShouldBeEquivalentTo(ConditionalOperator.Or); binaryExpression.LeftExpression.Should().BeOfType <CmsqlQueryBinaryExpression>(); binaryExpression.RightExpression.Should().BeOfType <CmsqlQueryCondition>(); }
public void Test_can_parse_less_than_or_equals_condition() { CmsqlParser cmsqlParser = CmsqlParserFactory.CreateParserForQuery("foo <= 'bar'"); CmsqlParser.ConditionContext parseTree = cmsqlParser.condition(); ConditionVisitor visitor = new ConditionVisitor(); CmsqlQueryCondition condition = visitor.VisitCondition(parseTree); condition.Identifier.ShouldBeEquivalentTo("foo"); condition.Operator.ShouldBeEquivalentTo(EqualityOperator.LessThanOrEquals); condition.Value.ShouldBeEquivalentTo("bar"); }
public void Test_can_parse_parenthesized_expression_containing_condition_expression() { CmsqlParser cmsqlParser = CmsqlParserFactory.CreateParserForQuery("(foo != 'bar')"); CmsqlParser.ParenthesizedExpressionContext parseTree = (CmsqlParser.ParenthesizedExpressionContext)cmsqlParser.expression(); ExpressionVisitor visitor = new ExpressionVisitor(); ICmsqlQueryExpression expression = visitor.VisitParenthesizedExpression(parseTree); expression.Should().BeOfType <CmsqlQueryCondition>(); expression.Should().NotBeNull(); }
public void Test_can_parse_condition_as_expression() { CmsqlParser cmsqlParser = CmsqlParserFactory.CreateParserForQuery("foo != 'bar'"); CmsqlParser.ConditionExpressionContext parseTree = (CmsqlParser.ConditionExpressionContext)cmsqlParser.expression(); ExpressionVisitor visitor = new ExpressionVisitor(); ICmsqlQueryExpression expression = visitor.VisitConditionExpression(parseTree); expression.Should().BeOfType <CmsqlQueryCondition>(); expression.Should().NotBeNull(); }
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(); }
public void Test_can_parse_parenthesized_expression_for_binary_expression() { CmsqlParser cmsqlParser = CmsqlParserFactory.CreateParserForQuery("(foo != 'bar' and bar = 'foo')"); CmsqlParser.ParenthesizedExpressionContext parseTree = (CmsqlParser.ParenthesizedExpressionContext)cmsqlParser.expression(); ExpressionVisitor visitor = new ExpressionVisitor(); CmsqlQueryBinaryExpression binaryExpression = (CmsqlQueryBinaryExpression)visitor.VisitParenthesizedExpression(parseTree); binaryExpression.LeftExpression.Should().BeOfType <CmsqlQueryCondition>(); binaryExpression.LeftExpression.Should().NotBeNull(); binaryExpression.RightExpression.Should().BeOfType <CmsqlQueryCondition>(); binaryExpression.RightExpression.Should().NotBeNull(); }
public void Test_can_parse_binary_expression_containing_parenthesized_expression_and_condition_expression(string queryExpression) { CmsqlParser cmsqlParser = CmsqlParserFactory.CreateParserForQuery(queryExpression); CmsqlParser.BinaryExpressionContext parseTree = (CmsqlParser.BinaryExpressionContext)cmsqlParser.expression(); ExpressionVisitor visitor = new ExpressionVisitor(); CmsqlQueryBinaryExpression binaryExpression = (CmsqlQueryBinaryExpression)visitor.VisitBinaryExpression(parseTree); binaryExpression.LeftExpression.Should().BeOfType <CmsqlQueryCondition>(); binaryExpression.LeftExpression.Should().NotBeNull(); binaryExpression.RightExpression.Should().BeOfType <CmsqlQueryCondition>(); binaryExpression.RightExpression.Should().NotBeNull(); }
public void Test_can_binary_expression_containing_two_condition_expressions() { CmsqlParser cmsqlParser = CmsqlParserFactory.CreateParserForQuery("foo != 'bar' and bar = 'foo'"); CmsqlParser.BinaryExpressionContext parseTree = (CmsqlParser.BinaryExpressionContext)cmsqlParser.expression(); ExpressionVisitor visitor = new ExpressionVisitor(); CmsqlQueryBinaryExpression binaryExpression = (CmsqlQueryBinaryExpression)visitor.VisitBinaryExpression(parseTree); binaryExpression.LeftExpression.Should().BeOfType <CmsqlQueryCondition>(); binaryExpression.LeftExpression.Should().NotBeNull(); binaryExpression.RightExpression.Should().BeOfType <CmsqlQueryCondition>(); binaryExpression.RightExpression.Should().NotBeNull(); }