private void formatDocumentToolStripMenuItem_Click(object sender, EventArgs e) { var code = (from Line l in editor.Lines select l.Text).ToList(); var openedBlock = Refactoring.FormatLines(ref code, new String(editor.Indentation.UseTabs ? '\t' : ' ', editor.Indentation.UseTabs ? 1 : editor.Indentation.IndentWidth)); if (openedBlock != null) { MessageBox.Show("Can't format the code because missing closing statements after:\n" + (openedBlock.Line + 1) + ": '" + editor.Lines[openedBlock.Line].Text.Trim().Trim(new[] { '\n', '\r' }) + "'\n\nPlease check your code and retry.", "Format document", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); editor.Selection.Start = editor.Lines[openedBlock.Line].StartPosition; editor.Selection.End = editor.Lines[openedBlock.Line].EndPosition; editor.Scrolling.ScrollToCaret(); } else { int selectionStart = editor.Selection.Start, selectionEnd = editor.Selection.End; var first = editor.Lines.FirstVisibleIndex; editor.Text = String.Join(Environment.NewLine, code); editor.Lines.FirstVisibleIndex = first; editor.Selection.Start = Math.Min(selectionStart, editor.TextLength); editor.Selection.End = Math.Min(selectionEnd, editor.TextLength); editor.Refresh(); } }
private void TestBlocksThatShouldNotChange(object[] args) { foreach (var l in _codeBlocks) { var tmp = String.Format(l, args); var original = new List <string>(tmp.Split(new[] { CRLF }, StringSplitOptions.None)); var test = new List <string>(tmp.Split(new[] { CRLF }, StringSplitOptions.None)); Refactoring.FormatLines(ref test, IndentationString); CollectionAssert.AreEqual(original, test); } }
private static void FormatAndCheck(List <string> actual, List <string> expected) { Refactoring.FormatLines(ref actual, IndentationString); CollectionAssert.AreEqual(expected, actual); }