/// <summary> /// Validates all the statements in the script. /// </summary> public override PhaseResult Execute(PhaseContext phaseCtx) { // 1. Check number of statements. var statements = _execAllNodes ? phaseCtx.Nodes : phaseCtx.NodesStack[phaseCtx.NodesStack.Count - 1]; var now = DateTime.Now; // 2. No statements ? return if (statements == null || statements.Count == 0) { return(ToPhaseResult(now, now, true, "There are 0 nodes to lint")); } var semacts = new SemActs(); var result = semacts.Validate(statements); // 4. Simply wrap the run-result ( success, message, start/end times ) // inside of a phase result. return(new PhaseResult(result)); }
public void Can_Validate_Variable_Does_Not_Exist() { var symScope = new Symbols(); symScope.DefineVariable("result"); var semacts = new SemActs(); var a = new VariableExpr("a"); a.Ref = new ScriptRef("", 1, 1); a.SymScope = symScope.Current; var zero = new ConstantExpr(2); zero.Ref = new ScriptRef("", 1, 5); zero.SymScope = symScope.Current; var divExpr = new BinaryExpr(a, Operator.Divide, zero); divExpr.SymScope = symScope.Current; var assignExpr = new AssignExpr(true, new VariableExpr("result"), divExpr); assignExpr.SymScope = symScope.Current; var stmts = new List <Expr>(); stmts.Add(assignExpr); var success = semacts.Validate(stmts); var results = semacts.Results; Assert.IsFalse(success); Assert.IsFalse(results.Success); Assert.IsTrue(results.HasResults); Assert.AreEqual(results.Results.Count, 1); }