public void TestDocumentRemove() { var document = new Mono.TextEditor.TextDocument(); string top = "1234567890\n"; string testText = "12345678\n" + "1234567\n" + "123456\n" + "12345\n" + "1234\n" + "123\n" + "12\n" + "1\n" + "\n"; document.Text = top + testText; document.Remove(0, top.Length); Assert.AreEqual(document.Text, testText); document.Remove(0, document.TextLength); DocumentLine line = document.GetLine(1); Assert.AreEqual(0, line.Offset); Assert.AreEqual(0, line.LengthIncludingDelimiter); Assert.AreEqual(0, document.TextLength); Assert.AreEqual(1, document.LineCount); }
public void TestDocumentBug1Test() { var document = new Mono.TextEditor.TextDocument (); string top = "1234567890"; document.Text = top; Assert.AreEqual (document.GetLine (1).LengthIncludingDelimiter, document.TextLength); document.Remove(0, document.TextLength); DocumentLine line = document.GetLine (1); Assert.AreEqual(0, line.Offset); Assert.AreEqual(0, line.LengthIncludingDelimiter); Assert.AreEqual(0, document.TextLength); Assert.AreEqual(1, document.LineCount); }
public void TestDocumentBug1Test() { var document = new Mono.TextEditor.TextDocument(); string top = "1234567890"; document.Text = top; Assert.AreEqual(document.GetLine(1).LengthIncludingDelimiter, document.TextLength); document.Remove(0, document.TextLength); DocumentLine line = document.GetLine(1); Assert.AreEqual(0, line.Offset); Assert.AreEqual(0, line.LengthIncludingDelimiter); Assert.AreEqual(0, document.TextLength); Assert.AreEqual(1, document.LineCount); }
public void SplitterTest() { var document = new Mono.TextEditor.TextDocument (); for (int i = 0; i < 100; i++) { document.Insert (0, new string ('c', i) + Environment.NewLine); } Assert.AreEqual (101, document.LineCount); for (int i = 0; i < 100; i++) { DocumentLine line = document.GetLine (i + 1 ); Assert.AreEqual (99 - i, line.Length); Assert.AreEqual (Environment.NewLine.Length, line.DelimiterLength); } for (int i = 0; i < 100; i++) { DocumentLine line = document.GetLine (1); document.Remove (line.Length, line.DelimiterLength); } Assert.AreEqual (1, document.LineCount); }
static string StripHeaderAndBlankLines(string text, CodeDomProvider provider) { Mono.TextEditor.TextDocument doc = new Mono.TextEditor.TextDocument(); doc.Text = text; int realStartLine = 0; for (int i = 1; i <= doc.LineCount; i++) { string lineText = doc.GetTextAt(doc.GetLine(i)); // Microsoft.NET generates "auto-generated" tags where Mono generates "autogenerated" tags. if (lineText.Contains("</autogenerated>") || lineText.Contains("</auto-generated>")) { realStartLine = i + 2; break; } } // The Mono provider inserts additional blank lines, so strip them out // But blank lines might actually be significant in other languages. // We reformat the C# generated output to the user's coding style anyway, but the reformatter preserves blank lines if (provider is Microsoft.CSharp.CSharpCodeProvider) { bool previousWasBlank = false; for (int i = 1; i <= doc.LineCount; i++) { Mono.TextEditor.DocumentLine line = doc.GetLine(i); bool isBlank, isBracket; CheckLine(doc, line, out isBlank, out isBracket); if (isBlank && previousWasBlank && line.LengthIncludingDelimiter > 0) { doc.Remove(line.Offset, line.LengthIncludingDelimiter); i--; } previousWasBlank = isBlank || isBracket; } } int offset = doc.GetLine(realStartLine).Offset; return(doc.GetTextAt(offset, doc.TextLength - offset)); }
public void SplitterTest() { var document = new Mono.TextEditor.TextDocument(); for (int i = 0; i < 100; i++) { document.Insert(0, new string ('c', i) + Environment.NewLine); } Assert.AreEqual(101, document.LineCount); for (int i = 0; i < 100; i++) { DocumentLine line = document.GetLine(i + 1); Assert.AreEqual(99 - i, line.Length); Assert.AreEqual(Environment.NewLine.Length, line.DelimiterLength); } for (int i = 0; i < 100; i++) { DocumentLine line = document.GetLine(1); document.Remove(line.Length, line.DelimiterLength); } Assert.AreEqual(1, document.LineCount); }
static string StripHeaderAndBlankLines (string text, CodeDomProvider provider) { Mono.TextEditor.TextDocument doc = new Mono.TextEditor.TextDocument (); doc.Text = text; int realStartLine = 0; for (int i = 1; i <= doc.LineCount; i++) { string lineText = doc.GetTextAt (doc.GetLine (i)); // Microsoft.NET generates "auto-generated" tags where Mono generates "autogenerated" tags. if (lineText.Contains ("</autogenerated>") || lineText.Contains ("</auto-generated>")) { realStartLine = i + 2; break; } } // The Mono provider inserts additional blank lines, so strip them out // But blank lines might actually be significant in other languages. // We reformat the C# generated output to the user's coding style anyway, but the reformatter preserves blank lines if (provider is Microsoft.CSharp.CSharpCodeProvider) { bool previousWasBlank = false; for (int i = 1; i <= doc.LineCount; i++) { Mono.TextEditor.LineSegment line = doc.GetLine (i); bool isBlank, isBracket; CheckLine (doc, line, out isBlank, out isBracket); if (isBlank && previousWasBlank && line.LengthIncludingDelimiter > 0) { doc.Remove (line.Offset, line.LengthIncludingDelimiter); i--; } previousWasBlank = isBlank || isBracket; } } int offset = doc.GetLine (realStartLine).Offset; return doc.GetTextAt (offset, doc.TextLength - offset); }
public void TestDocumentRemove() { var document = new Mono.TextEditor.TextDocument (); string top = "1234567890\n"; string testText = "12345678\n" + "1234567\n" + "123456\n" + "12345\n" + "1234\n" + "123\n" + "12\n" + "1\n" + "\n"; document.Text = top + testText; document.Remove (0, top.Length); Assert.AreEqual (document.Text, testText); document.Remove (0, document.TextLength); DocumentLine line = document.GetLine (1); Assert.AreEqual (0, line.Offset); Assert.AreEqual (0, line.LengthIncludingDelimiter); Assert.AreEqual (0, document.TextLength); Assert.AreEqual (1, document.LineCount); }