public void TestSecondLevelCombine() { var val1 = new Variables.ValSimple("true", typeof(bool)); var s1 = new StatementFilter(val1); var val11 = new Variables.ValSimple("true", typeof(bool)); var s11 = new StatementFilter(val11); s11.Add(new StatementSimpleStatement("var11")); s1.Add(s11); var val2 = new Variables.ValSimple("true", typeof(bool)); var s2 = new StatementFilter(val2); var val21 = new Variables.ValSimple("true", typeof(bool)); var s21 = new StatementFilter(val21); s21.Add(new StatementSimpleStatement("var21")); s2.Add(s21); Assert.IsTrue(s1.TryCombineStatement(s2, null), "statement should have combined"); Assert.AreEqual(1, s1.Statements.Count(), "# of combined statements"); var deep = s1.Statements.First() as StatementInlineBlockBase; Assert.IsNotNull(deep, "couldn't find interior statement"); Assert.AreEqual(2, deep.Statements.Count(), "Number of statements isn't right here"); }
public void TestExprNoStatements() { var val = new Variables.ValSimple("true", typeof(bool)); var statement = new StatementFilter(val); var result = statement.CodeItUp().ToArray(); Assert.AreEqual(0, result.Length, "no statements, so wasn't expecting any sort of output at all"); }
public void TestTryCombine(IStatement s) { /// We should never be able to combine any filter statements currently! var val = new Variables.ValSimple("true", typeof(bool)); var statement = new StatementIfOnCount(DeclarableParameter.CreateDeclarableParameterExpression(typeof(string)), new Variables.ValSimple("two", typeof(string)), StatementIfOnCount.ComparisonOperator.EqualTo); Assert.IsFalse(statement.TryCombineStatement(s, null), "unable to do any combines for Filter"); }
public void TestFalseExpr() { var val = new Variables.ValSimple("false", typeof(bool)); var statement = new StatementFilter(val); statement.Add(new StatementSimpleStatement("dude")); var result = statement.CodeItUp().ToArray(); Assert.AreEqual(0, result.Length, "Expect no statements for a false if statement"); }
public void TestWithStatement() { var val = new Variables.ValSimple("true", typeof(bool)); var statement = new StatementIfOnCount(DeclarableParameter.CreateDeclarableParameterExpression(typeof(string)), new Variables.ValSimple("two", typeof(string)), StatementIfOnCount.ComparisonOperator.EqualTo); statement.Add(new StatementSimpleStatement("dude")); var result = statement.CodeItUp().ToArray(); Assert.AreEqual(5, result.Length, "no statements, so wasn't expecting any sort of output at all"); Assert.AreEqual("if (aString_1 == two)", result[1], "if statement is not correct"); }
public void TestTrueExpr() { var val = new Variables.ValSimple("true", typeof(bool)); var statement = new StatementFilter(val); statement.Add(new StatementSimpleStatement("dude")); var result = statement.CodeItUp().ToArray(); Assert.AreEqual(3, result.Length, "true test means only the involved statements should be in here!"); Assert.AreEqual("{", result[0], "open bracket"); Assert.AreEqual(" dude;", result[1], "statement isn't in the proper spot"); Assert.AreEqual("}", result[2], "end of block not right"); }
public void TestSimpleCombine() { var val1 = new Variables.ValSimple("true", typeof(bool)); var s1 = new StatementFilter(val1); s1.Add(new StatementSimpleStatement("var1")); var val2 = new Variables.ValSimple("true", typeof(bool)); var s2 = new StatementFilter(val2); s2.Add(new StatementSimpleStatement("var2")); Assert.IsTrue(s1.TryCombineStatement(s2, null), "statement should have combined"); Assert.AreEqual(2, s1.Statements.Count(), "# of combined statements"); }
public void TestExprWithStatement() { var val = new Variables.ValSimple("1 == 1", typeof(bool)); var statement = new StatementFilter(val); statement.Add(new StatementSimpleStatement("dude")); var result = statement.CodeItUp().ToArray(); Assert.AreEqual(4, result.Length, "no statements, so wasn't expecting any sort of output at all"); Assert.AreEqual("if (1 == 1)", result[0], "if statement isn't correct"); Assert.AreEqual("{", result[1], "open bracket"); Assert.AreEqual(" dude;", result[2], "statement isn't in the proper spot"); Assert.AreEqual("}", result[3], "end of block not right"); }
public void TestTryCombine([PexAssumeUnderTest] StatementForLoop target, IStatement s) { /// We should never be able to combine any filter statements currently! var val = new Variables.ValSimple("true", typeof(bool)); var result = target.TryCombineStatement(s, null); if (s.GetType() != typeof(StatementForLoop)) { Assert.IsFalse(result, "Types not right"); } else { var other = s as StatementForLoop; Assert.AreEqual(other.ArrayLength == target.ArrayLength, result, "for loops not conssitent"); } }
public void TestTryCombine([PexAssumeUnderTest]StatementForLoop target, IStatement s) { /// We should never be able to combine any filter statements currently! var val = new Variables.ValSimple("true", typeof(bool)); var result = target.TryCombineStatement(s, null); if (s.GetType() != typeof(StatementForLoop)) { Assert.IsFalse(result, "Types not right"); } else { var other = s as StatementForLoop; Assert.AreEqual(other.ArrayLength == target.ArrayLength, result, "for loops not conssitent"); } }
public void TestAllOperators() { var matchedValues = new Tuple <StatementIfOnCount.ComparisonOperator, string>[] { Tuple.Create(StatementIfOnCount.ComparisonOperator.EqualTo, "=="), Tuple.Create(StatementIfOnCount.ComparisonOperator.GreaterThan, ">"), Tuple.Create(StatementIfOnCount.ComparisonOperator.GreaterThanEqual, ">="), Tuple.Create(StatementIfOnCount.ComparisonOperator.LessThan, "<"), Tuple.Create(StatementIfOnCount.ComparisonOperator.LessThanEqual, "<=") }; foreach (var op in matchedValues) { var val = new Variables.ValSimple("true", typeof(bool)); var statement = new StatementIfOnCount(DeclarableParameter.CreateDeclarableParameterExpression(typeof(string)), new Variables.ValSimple("two", typeof(string)), op.Item1); statement.Add(new StatementSimpleStatement("dude")); var result = statement.CodeItUp().ToArray(); Assert.AreEqual(5, result.Length, "no statements, so wasn't expecting any sort of output at all"); Assert.IsTrue(result[1].EndsWith(op.Item2 + " two)"), "if statement is not correct"); } }
public void TestAllOperators() { var matchedValues = new Tuple<StatementIfOnCount.ComparisonOperator, string>[] { Tuple.Create(StatementIfOnCount.ComparisonOperator.EqualTo, "=="), Tuple.Create(StatementIfOnCount.ComparisonOperator.GreaterThan, ">"), Tuple.Create(StatementIfOnCount.ComparisonOperator.GreaterThanEqual, ">="), Tuple.Create(StatementIfOnCount.ComparisonOperator.LessThan, "<"), Tuple.Create(StatementIfOnCount.ComparisonOperator.LessThanEqual, "<=") }; foreach (var op in matchedValues) { var val = new Variables.ValSimple("true", typeof(bool)); var statement = new StatementIfOnCount(DeclarableParameter.CreateDeclarableParameterExpression(typeof(string)), new Variables.ValSimple("two", typeof(string)), op.Item1); statement.Add(new StatementSimpleStatement("dude")); var result = statement.CodeItUp().ToArray(); Assert.AreEqual(5, result.Length, "no statements, so wasn't expecting any sort of output at all"); Assert.IsTrue(result[1].EndsWith(op.Item2 + " two)"), "if statement is not correct"); } }