public void SingleLineIf() { string code = "Public Class Foo\r\n" + "\tPublic Sub Bar\r\n" + "\t\tIf True Then _\r\n" + "\r\n" + // This extra new line is required. This is the new line just entered by the user. "\tEnd Sub\r\n" + "End Class"; string bar = "Then _"; int cursorOffset = code.IndexOf(bar) + bar.Length; int line = 3; string expectedCode = "Public Class Foo\r\n" + "\tPublic Sub Bar\r\n" + "\t\tIf True Then _\r\n" + "\t\t\t\r\n" + "\tEnd Sub\r\n" + "End Class"; using (TextEditorControl editor = new TextEditorControl()) { editor.Document.TextContent = code; editor.ActiveTextAreaControl.Caret.Position = editor.Document.OffsetToPosition(cursorOffset); VBFormattingStrategy formattingStrategy = new VBFormattingStrategy(); formattingStrategy.FormatLine(editor.ActiveTextAreaControl.TextArea, line, cursorOffset, '\n'); Assert.AreEqual(expectedCode, editor.Document.TextContent); } }
void RunFormatTest(string code, string expectedCode) { using (TextEditorControl editor = new TextEditorControl()) { editor.Document.TextContent = code; VBFormattingStrategy formattingStrategy = new VBFormattingStrategy(); formattingStrategy.IndentLines(editor.ActiveTextAreaControl.TextArea, 0, editor.Document.TotalNumberOfLines); Assert.AreEqual(expectedCode, editor.Document.TextContent); } }
/// <summary> /// Checks that when the user presses the return key after the Operator line that the /// expected code is generated. /// </summary> void RunFormatLineTest(string code, string expectedCode) { string foo = "As Foo"; int cursorOffset = code.IndexOf(foo) + foo.Length; int line = 2; using (TextEditorControl editor = new TextEditorControl()) { editor.Document.TextContent = code; editor.ActiveTextAreaControl.Caret.Position = editor.Document.OffsetToPosition(cursorOffset); VBFormattingStrategy formattingStrategy = new VBFormattingStrategy(); formattingStrategy.FormatLine(editor.ActiveTextAreaControl.TextArea, line, cursorOffset, '\n'); Assert.AreEqual(expectedCode, editor.Document.TextContent); } }