public StatementSimpleStatement TestRename([PexAssumeUnderTest] StatementSimpleStatement target, string oldvar, string newvar) { // // Make sure that Pex is using a legal variable name // var goodVar = new Regex(string.Format(@"w+")); if (!goodVar.Match(oldvar).Success) { throw new ArgumentException("The old variable is not a proper variable name"); } if (!goodVar.Match(newvar).Success) { throw new ArgumentException("THe new variable is not a proper variable name"); } target.RenameVariable(oldvar, newvar); if (oldvar != null && oldvar != newvar) { Assert.IsFalse(Regex.Match(target.Line, string.Format(@"\b{0}\b", oldvar)).Success, "old guy should not be in there!"); } return(target); }
public void TestBadRemove() { var s = new StatementInlineBlock(); var tmp = new StatementSimpleStatement("fork"); s.Remove(tmp); }
public void TestAddBeforeBad() { var s = new StatementInlineBlock(); var s1 = new StatementSimpleStatement("one"); var s2 = new StatementSimpleStatement("two"); s.AddBefore(s1, s2); }
public void SimpleStatementCallbackLineWithNoSemicolon() { var st = new StatementSimpleStatement(() => "}", addSemicolon: false); var lines = st.CodeItUp().ToArray(); Assert.AreEqual(1, lines.Length); Assert.AreEqual("}", lines[0]); }
/// <summary>Test stub for CodeItUp()</summary> public IEnumerable<string> CodeItUp(StatementSimpleStatement target) { IEnumerable<string> result = target.CodeItUp(); var lines = result.ToArray(); Assert.AreEqual(1, lines.Length, "bad # of lines"); return result; // TODO: add assertions to method StatementSimpleStatementTest.CodeItUp(StatementSimpleStatement) }
/// <summary>Test stub for CodeItUp()</summary> public IEnumerable <string> CodeItUp(StatementSimpleStatement target) { IEnumerable <string> result = target.CodeItUp(); var lines = result.ToArray(); Assert.AreEqual(1, lines.Length, "bad # of lines"); return(result); // TODO: add assertions to method StatementSimpleStatementTest.CodeItUp(StatementSimpleStatement) }
public void TestCombineSame() { var st1 = new StatementSimpleStatement("int"); var st2 = new StatementSimpleStatement("int"); Assert.IsTrue(st1.TryCombineStatement(st2, null), "same statements should combine"); var st3 = new StatementSimpleStatement("float"); Assert.IsFalse(st1.TryCombineStatement(st3, null), "diff statements should not combine"); }
public void SimpleStatementNoCallBackTillCodeUp() { bool called = false; var st = new StatementSimpleStatement(() => { called = true; return("int j"); }); Assert.IsFalse(called, "Call back called too early"); var lines = st.CodeItUp().ToArray(); Assert.IsTrue(called); }
public void TestAddBeforeParentNonNullParent() { var s = new StatementInlineBlock(); var s1 = new StatementSimpleStatement("one"); var s2 = new StatementSimpleStatement("two"); s1.Parent = s; s.Add(s2); s.AddBefore(s1, s2); }
public void SimpleStatementCallbackAndTransformAfterRendering() { var st = new StatementSimpleStatement(() => "int j"); var lines = st.CodeItUp().ToArray(); st.RenameVariable("j", "k"); lines = st.CodeItUp().ToArray(); Assert.AreEqual(1, lines.Length); Assert.AreEqual("int k;", lines[0]); }
public void TestAddBeforeParent() { var s = new StatementInlineBlock(); var s1 = new StatementSimpleStatement("one"); var s2 = new StatementSimpleStatement("two"); s.Add(s2); s.AddBefore(s1, s2); Assert.AreEqual(s, s1.Parent, "s1 parent"); Assert.AreEqual(s, s2.Parent, "s2 parent"); }
public void TestRemoveSingleStatementResetsParent() { var s = new StatementInlineBlock(); var s1 = new StatementSimpleStatement("one"); var s2 = new StatementSimpleStatement("two"); s.Add(s1); s.Add(s2); s.Remove(s1); Assert.IsNull(s1.Parent, "s1 parent"); }
public void SimpleStatementNoCallBackTillCodeUp2() { int count = 0; var st = new StatementSimpleStatement(() => { count++; return("int j"); }); var lines = st.CodeItUp().ToArray(); Assert.AreEqual(1, count); var lines2 = st.CodeItUp().ToArray(); Assert.AreEqual(1, count); }
public void TestRemoveSingleStatement() { var s = new StatementInlineBlock(); var s1 = new StatementSimpleStatement("one"); var s2 = new StatementSimpleStatement("two"); s.Add(s1); s.Add(s2); s.Remove(s1); Assert.AreEqual(1, s.Statements.Count(), "# of statements after remove"); Assert.AreEqual(s2, s.Statements.First(), "First statement"); }
public void TestAddBefore() { var s = new StatementInlineBlock(); var s1 = new StatementSimpleStatement("one"); var s2 = new StatementSimpleStatement("two"); s.Add(s2); s.AddBefore(s1, s2); Assert.AreEqual(2, s.Statements.Count(), "# of statements"); Assert.AreEqual(s1, s.Statements.First(), "first statement"); Assert.AreEqual(s2, s.Statements.Skip(1).First(), "second statement"); }
/// <summary>Test stub for .ctor(String)</summary> public StatementSimpleStatement Constructor(string line) { StatementSimpleStatement target = new StatementSimpleStatement(line); Assert.IsFalse(target.Line.EndsWith(";"), "semicolon should have been stripped off ('" + target.Line + "')"); Assert.AreNotEqual(0, target.Line, "empty line is not allowed"); line = line.Trim(); while (line.EndsWith(";")) { line = line.Substring(0, line.Length - 1); line = line.Trim(); } Assert.AreEqual(line, target.Line, "bad line set"); return target; }
/// <summary>Test stub for .ctor(String)</summary> public StatementSimpleStatement Constructor(string line) { StatementSimpleStatement target = new StatementSimpleStatement(line); Assert.IsFalse(target.Line.EndsWith(";"), "semicolon should have been stripped off ('" + target.Line + "')"); Assert.AreNotEqual(0, target.Line, "empty line is not allowed"); line = line.Trim(); while (line.EndsWith(";")) { line = line.Substring(0, line.Length - 1); line = line.Trim(); } Assert.AreEqual(line, target.Line, "bad line set"); return(target); }
public void CombineWithMoveNonIdenticalStatements() { // Part of a fix for something found in the wild. When we move statements, with append turned off, and // move turned on, make sure the move occurs. var inline1 = new StatementInlineBlock(); var inline2 = new StatementInlineBlock(); var s1 = new StatementSimpleStatement("dude", true); inline1.Add(s1); var s2 = new StatementSimpleStatement("fork", true); inline2.Add(s2); Assert.IsFalse(inline2.Combine(new IStatement[] { s1 }, inline1, appendIfCantCombine: false, moveIfIdentical: true), "Combine of two idential statements should go"); Assert.AreEqual(1, inline1.Statements.Count(), "All statements should have been removed from block 1"); Assert.AreEqual(1, inline2.Statements.Count(), "statements in inlien2"); }
public void CombinedGeneratedDifferentInitializationStatements() { var q1 = new GeneratedCode(); var q2 = new GeneratedCode(); var s1 = new Statements.StatementSimpleStatement("dude1"); var s2 = new Statements.StatementSimpleStatement("dude2"); q1.AddInitalizationStatement(s1); q2.AddInitalizationStatement(s2); var target = new CombinedGeneratedCode(); target.AddGeneratedCode(q1); target.AddGeneratedCode(q2); var initStatements = target.InitalizationStatements.ToArray(); Assert.AreEqual(2, initStatements.Length); }
public void TestSimpleCombine() { var q1 = new GeneratedCode(); var q2 = new GeneratedCode(); var s1 = new Statements.StatementSimpleStatement("dude1"); var s2 = new Statements.StatementSimpleStatement("dude2"); q1.Add(s1); q2.Add(s2); var v1 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)); var v2 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)); q1.SetResult(v1); q2.SetResult(v2); var target = new CombinedGeneratedCode(); target.AddGeneratedCode(q1); target.AddGeneratedCode(q2); Assert.AreEqual(1, target.QueryCode().Count(), "didn't combine blocks correctly"); var c = target.QueryCode().First(); Assert.AreEqual(2, c.Statements.Count(), "bad # of statements in combined query"); var st1 = c.Statements.First(); var st2 = c.Statements.Skip(1).First(); Assert.IsInstanceOfType(st1, typeof(Statements.StatementSimpleStatement), "st1"); Assert.IsInstanceOfType(st2, typeof(Statements.StatementSimpleStatement), "st2"); var sst1 = st1 as Statements.StatementSimpleStatement; var sst2 = st2 as Statements.StatementSimpleStatement; Assert.IsTrue("dude1" == sst1.Line || "dude1" == sst2.Line, "sst1"); Assert.IsTrue("dude2" == sst1.Line || "dude2" == sst2.Line, "sst2"); }
public void SimpleStatementNoCallBackTillCodeUp2() { int count = 0; var st = new StatementSimpleStatement(() => { count++; return "int j"; }); var lines = st.CodeItUp().ToArray(); Assert.AreEqual(1, count); var lines2 = st.CodeItUp().ToArray(); Assert.AreEqual(1, count); }
public void SimpleStatementNoCallBackTillCodeUp() { bool called = false; var st = new StatementSimpleStatement(() => { called = true; return "int j"; }); Assert.IsFalse(called, "Call back called too early"); var lines = st.CodeItUp().ToArray(); Assert.IsTrue(called); }
public bool TestTryCombine([PexAssumeUnderTest] StatementSimpleStatement target, IStatement st) { return(target.TryCombineStatement(st, null)); }
public void CombineWithMoveNonAndNotNonIdenticalStatements() { // Part of a fix for something found in the wild. When we move statements, with append turned off, and // move turned on, make sure the move occurs. var inline1 = new StatementInlineBlock(); var inline2 = new StatementInlineBlock(); var s1 = new StatementSimpleStatement("dude", true); var s11 = new StatementSimpleStatement("fork", true); inline1.Add(s1); inline1.Add(s11); var s2 = new StatementSimpleStatement("fork", true); inline2.Add(s2); Assert.IsFalse(inline2.Combine(new IStatement[] { s1, s11 }, inline1, appendIfCantCombine: false, moveIfIdentical: true), "Combine of two idential statements should go"); Assert.AreEqual(1, inline1.Statements.Count(), "All statements should have been removed from block 1"); Assert.AreEqual(1, inline2.Statements.Count(), "statements in inlien2"); }
public void CombinedGeneratedDifferentInitalizationStatements() { var q1 = new GeneratedCode(); var q2 = new GeneratedCode(); var s1 = new Statements.StatementSimpleStatement("dude1"); var s2 = new Statements.StatementSimpleStatement("dude2"); q1.AddInitalizationStatement(s1); q2.AddInitalizationStatement(s2); var target = new CombinedGeneratedCode(); target.AddGeneratedCode(q1); target.AddGeneratedCode(q2); var initStatements = target.InitalizationStatements.ToArray(); Assert.AreEqual(2, initStatements.Length); }