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); }
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)); }
public Value Visit(DoWhileStmt stmt, Scope scope) { do { stmt.Block.Accept(this, scope); } while (stmt.Condition.Accept(this, scope).ToBoolean()); return(Value.Unit);; }
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))); }
public ValueType Visit(DoWhileStmt stmt, Scope context) { return(ValueType.Unit); }
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); }
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); }