Esempio n. 1
0
            public void DoWhileLoopConditionIgnoredTest()
            {
                var target = new EvaluateVisitor();

                var conditionExecuted = false;
                var condition         = new Mock <Expression>();

                condition.Setup(c => c.Accept(It.IsAny <IExpressionVisitor <Value, Scope> >(), It.IsAny <Scope>()))
                .Returns <IExpressionVisitor <Value, Scope>, Scope>(
                    (v, s) =>
                {
                    conditionExecuted = true;
                    return(new Value(false));;
                });

                var statement = new Mock <Statement>();

                statement.Setup(c => c.Accept(It.IsAny <IExpressionVisitor <Value, Scope> >(), It.IsAny <Scope>()))
                .Returns <IExpressionVisitor <Value, Scope>, Scope>(
                    (v, s) =>
                {
                    if (conditionExecuted)
                    {
                        throw new Exception("Statement executed after condition evaluated.");
                    }
                    return(new Value(false));
                });

                var expr = new DoWhileStmt(condition.Object, new ScopeBlockStmt(new[] { statement.Object }));

                target.Visit(expr, _scope);

                condition.Verify(c => c.Accept(target, _scope), Times.Once);
                statement.Verify(s => s.Accept(target, It.IsAny <Scope>()), Times.Once);
            }
Esempio n. 2
0
            public void DoWhileLoopTest()
            {
                var target = new EvaluateVisitor();

                const int totalLoopIteration = 3;
                int       loopIterations     = 0;

                var condition = new Mock <Expression>();

                condition.Setup(c => c.Accept(It.IsAny <IExpressionVisitor <Value, Scope> >(), It.IsAny <Scope>()))
                .Returns <IExpressionVisitor <Value, Scope>, Scope>(
                    (v, s) =>
                {
                    loopIterations++;
                    return(new Value(loopIterations < totalLoopIteration));
                });

                var statement = new Mock <Statement>();

                var expr = new DoWhileStmt(condition.Object, new ScopeBlockStmt(new[] { statement.Object }));

                target.Visit(expr, _scope);

                condition.Verify(c => c.Accept(target, _scope), Times.Exactly(totalLoopIteration));
                statement.Verify(s => s.Accept(target, It.IsAny <Scope>()), Times.Exactly(totalLoopIteration));
            }
Esempio n. 3
0
        public Value Visit(DoWhileStmt stmt, Scope scope)
        {
            do
            {
                stmt.Block.Accept(this, scope);
            } while (stmt.Condition.Accept(this, scope).ToBoolean());

            return(Value.Unit);;
        }
Esempio n. 4
0
 public string Visit(DoWhileStmt stmt, Scope scope)
 {
     return(string.Format("do\r\n{{\r\n\t{0}\r\n}}while({1});",
                          stmt.Block.Accept(this, scope),
                          stmt.Condition.Accept(this, scope)));
 }
Esempio n. 5
0
 public ValueType Visit(DoWhileStmt stmt, Scope context)
 {
     return(ValueType.Unit);
 }
Esempio n. 6
0
            public void DoWhileLoopConditionIgnoredTest()
            {
                var target = new EvaluateVisitor();

                var conditionExecuted = false;
                var condition = new Mock<Expression>();
                condition.Setup(c => c.Accept(It.IsAny<IExpressionVisitor<Value, Scope>>(), It.IsAny<Scope>()))
                    .Returns<IExpressionVisitor<Value, Scope>, Scope>(
                        (v, s) =>
                        {
                            conditionExecuted = true;
                            return new Value(false); ;
                        });

                var statement = new Mock<Statement>();
                statement.Setup(c => c.Accept(It.IsAny<IExpressionVisitor<Value, Scope>>(), It.IsAny<Scope>()))
                    .Returns<IExpressionVisitor<Value, Scope>, Scope>(
                        (v, s) =>
                        {
                            if (conditionExecuted)
                                throw new Exception("Statement executed after condition evaluated.");
                            return new Value(false);
                        });

                var expr = new DoWhileStmt(condition.Object, new ScopeBlockStmt(new[] { statement.Object }));

                target.Visit(expr, _scope);

                condition.Verify(c => c.Accept(target, _scope), Times.Once);
                statement.Verify(s => s.Accept(target, It.IsAny<Scope>()), Times.Once);
            }
Esempio n. 7
0
            public void DoWhileFalseLoopTest()
            {
                var target = new EvaluateVisitor();

                var condition = new Mock<Expression>();
                condition.Setup(c => c.Accept(It.IsAny<IExpressionVisitor<Value, Scope>>(), It.IsAny<Scope>()))
                    .Returns<IExpressionVisitor<Value, Scope>, Scope>(
                        (v, s) =>
                        {
                            return new Value(false);
                        });

                var statement = new Mock<Statement>();

                var expr = new DoWhileStmt(condition.Object, new ScopeBlockStmt(new[] { statement.Object }));

                target.Visit(expr, _scope);

                condition.Verify(c => c.Accept(target, _scope), Times.Exactly(1));
                statement.Verify(s => s.Accept(target, It.IsAny<Scope>()), Times.Once);
            }