static void TestInsertionPoints (string text) { TextEditorData data = new TextEditorData (); List<InsertionPoint> loc = new List<InsertionPoint> (); for (int i = 0; i < text.Length; i++) { char ch = text[i]; if (ch == '@') { i++; ch = text[i]; loc.Add (new InsertionPoint (data.Document.OffsetToLocation (data.Document.Length), ch == '3' || ch == '2', ch == '3' || ch == '1')); } else { data.Insert (data.Document.Length, ch.ToString ()); } } var parseResult = new NRefactoryParser ().Parse (null, "a.cs", data.Document.Text); var foundPoints = HelperMethods.GetInsertionPoints (data.Document, parseResult.CompilationUnit.Types[0]); Assert.AreEqual (loc.Count, foundPoints.Count, "point count doesn't match"); for (int i = 0; i < loc.Count; i++) { Console.WriteLine (loc[i] + "/" + foundPoints[i]); Assert.AreEqual (loc[i].Location, foundPoints[i].Location, "point " + i + " doesn't match"); Assert.AreEqual (loc[i].ShouldInsertNewLineAfter, foundPoints[i].ShouldInsertNewLineAfter, "point " + i + " ShouldInsertNewLineAfter doesn't match"); Assert.AreEqual (loc[i].ShouldInsertNewLineBefore, foundPoints[i].ShouldInsertNewLineBefore, "point " + i + " ShouldInsertNewLineBefore doesn't match"); } }
static void TestInsertionPoints (string text) { TextEditorData data = new TextEditorData (); List<InsertionPoint> loc = new List<InsertionPoint> (); for (int i = 0; i < text.Length; i++) { char ch = text[i]; if (ch == '@') { i++; ch = text[i]; NewLineInsertion insertBefore = NewLineInsertion.None; NewLineInsertion insertAfter = NewLineInsertion.None; switch (ch) { case 'n': break; case 'd': insertAfter = NewLineInsertion.Eol; break; case 'D': insertAfter = NewLineInsertion.BlankLine; break; case 'u': insertBefore = NewLineInsertion.Eol; break; case 'U': insertBefore = NewLineInsertion.BlankLine; break; case 's': insertBefore = insertAfter = NewLineInsertion.Eol; break; case 'S': insertBefore = insertAfter = NewLineInsertion.BlankLine; break; case 't': insertBefore = NewLineInsertion.Eol; insertAfter = NewLineInsertion.BlankLine; break; case 'v': insertBefore = NewLineInsertion.BlankLine; insertAfter = NewLineInsertion.Eol; break; default: Assert.Fail ("unknown insertion point:" + ch); break; } loc.Add (new InsertionPoint (data.Document.OffsetToLocation (data.Document.Length), insertBefore, insertAfter)); } else { data.Insert (data.Document.Length, ch.ToString ()); } } var parseResult = new NRefactoryParser ().Parse (null, "a.cs", data.Document.Text); var foundPoints = HelperMethods.GetInsertionPoints (data.Document, parseResult.CompilationUnit.Types[0]); Assert.AreEqual (loc.Count, foundPoints.Count, "point count doesn't match"); for (int i = 0; i < loc.Count; i++) { Console.WriteLine (loc[i] + "/" + foundPoints[i]); Assert.AreEqual (loc[i].Location, foundPoints[i].Location, "point " + i + " doesn't match"); Assert.AreEqual (loc[i].LineAfter, foundPoints[i].LineAfter, "point " + i + " ShouldInsertNewLineAfter doesn't match"); Assert.AreEqual (loc[i].LineBefore, foundPoints[i].LineBefore, "point " + i + " ShouldInsertNewLineBefore doesn't match"); } }