public void visitAssert(AssertNode node)
 {
     foreach (INode child in node.getChildren())
     {
         child.accept(this);
     }
 }
Beispiel #2
0
        public void AssertionTest()
        {
            var node = new AssertNode
            {
                Source = new ConstantScanNode
                {
                    Values =
                    {
                        new Entity {
                            ["name"] = new SqlString("Mark", CultureInfo.CurrentCulture.LCID, SqlCompareOptions.IgnoreCase | SqlCompareOptions.IgnoreNonSpace)
                        },
                        new Entity {
                            ["name"] = new SqlString("Carrington", CultureInfo.CurrentCulture.LCID, SqlCompareOptions.IgnoreCase | SqlCompareOptions.IgnoreNonSpace)
                        }
                    }
                },
                Assertion    = e => e.GetAttributeValue <SqlString>("name").Value == "Mark",
                ErrorMessage = "Only Mark is allowed"
            };

            var results = node.Execute(_dataSources, new StubOptions(), null, null).GetEnumerator();

            Assert.IsTrue(results.MoveNext());
            Assert.AreEqual("Mark", results.Current.GetAttributeValue <SqlString>("name").Value);

            var ex = Assert.ThrowsException <QueryExecutionException>(() => results.MoveNext());

            Assert.AreEqual(node.ErrorMessage, ex.Message);
        }
 public void visitAssert(AssertNode node)
 {
     node.getChildren()[0].accept(this);
     if (!popBool())
     {
         this.inputOutput.outputLine("Assertion failed.");
     }
 }
        public void visitAssert(AssertNode assertNode)
        {
            this.typeStack.Clear();
            assertNode.getChildren()[0].accept(this);
            MiniPLTokenType type = this.typeStack.Pop();

            this.typeStack.Clear();
            if (type != MiniPLTokenType.TYPE_IDENTIFIER_BOOL)
            {
                throw new SemanticException("Assert statement can only take bool as an argument.");
            }
        }
 /// <summary>
 /// Visits assertions
 /// </summary>
 /// <param name="line">Line to add the tag for</param>
 /// <param name="context">AssertNode to visit</param>
 /// <param name="lineNo">Current line numer</param>
 /// <param name="collectedSpans">Collection of spans found</param>
 private void Visit(ITextSnapshotLine line, AssertNode context, int lineNo, List <TagSpan <Z80TestTokenTag> > collectedSpans)
 {
     if (context == null ||
         lineNo < context.Span.StartLine ||
         lineNo > context.Span.EndLine)
     {
         return;
     }
     Visit(line, context.AssertKeywordSpan, lineNo, collectedSpans, Z80TestTokenType.Keyword);
     foreach (var expr in context.Expressions)
     {
         Visit(line, expr, lineNo, collectedSpans);
     }
 }
        /// <summary>
        /// Visit a parse tree produced by <see cref="Z80TestParser.assert"/>.
        /// <para>
        /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
        /// on <paramref name="context"/>.
        /// </para>
        /// </summary>
        /// <param name="context">The parse tree.</param>
        /// <return>The visitor result.</return>
        public override object VisitAssert(Z80TestParser.AssertContext context)
        {
            if (IsInvalidContext(context))
            {
                return(null);
            }
            var node = new AssertNode(context);

            foreach (var expr in context.expr())
            {
                node.Expressions.Add((ExpressionNode)VisitExpr(expr));
            }
            return(node);
        }
 /// <summary>
 /// Visits assertions
 /// </summary>
 /// <param name="line">Line to add the tag for</param>
 /// <param name="context">AssertNode to visit</param>
 /// <param name="lineNo">Current line number</param>
 /// <param name="collectedSpans">Collection of spans found</param>
 private void Visit(ITextSnapshotLine line, AssertNode context, int lineNo,
                    List <ClassificationSpan> collectedSpans)
 {
     if (context == null ||
         lineNo < context.Span.StartLine ||
         lineNo > context.Span.EndLine)
     {
         return;
     }
     Visit(line, context.AssertKeywordSpan, lineNo, collectedSpans, _keyword);
     foreach (var expr in context.Expressions)
     {
         Visit(line, expr, lineNo, collectedSpans);
     }
 }
Beispiel #8
0
 /// <summary>
 /// Visit the assert section of the block
 /// </summary>
 /// <param name="plan">Test file plan</param>
 /// <param name="testBlock">TestBlockPlan to visit</param>
 /// <param name="assert">Asser syntax node</param>
 private void VisitAssert(TestFilePlan plan, TestBlockPlan testBlock, AssertNode assert)
 {
     if (assert == null)
     {
         return;
     }
     foreach (var expr in assert.Expressions)
     {
         var value = Eval(plan, testBlock, expr, true);
         if (value == null)
         {
             continue;
         }
         testBlock.Assertions.Add(expr);
     }
 }
 public AssertCompiler(AssertNode node)
 {
     this.node = node;
 }