public void TestUpdateFoldSegmentBug2() { Document document = new Mono.TextEditor.Document(); document.Text = @"-[1 2 +[3 4] 5 +[6 7] 8 9 10 11 12 13 14] 15 16"; var segments = GetFoldSegments(document); document.UpdateFoldSegments(segments, false); Assert.AreEqual(10, document.VisualToLogicalLine(8)); Assert.AreEqual(3, document.FoldSegments.Count()); int start = document.GetLine(2).Offset; int end = document.GetLine(8).Offset; ((IBuffer)document).Remove(start, end - start); Assert.AreEqual(1, document.FoldSegments.Count()); Assert.AreEqual(10, document.LogicalToVisualLine(10)); }
public void TestUpdateFoldSegmentBug2() { Document document = new Mono.TextEditor.Document(); document.Text = @"-[0 1 +[2 3] 4 +[5 6] 7 8 9 10 11 12 13] 14 15"; var segments = GetFoldSegments(document); document.UpdateFoldSegments(segments, false); Assert.AreEqual(10, document.VisualToLogicalLine(8)); int start = document.GetLine(2).Offset; int end = document.GetLine(8).Offset; ((IBuffer)document).Remove(start, end - start); Assert.AreEqual(10, document.LogicalToVisualLine(10)); }
public void TestDocumentRemove() { Document document = new Mono.TextEditor.Document(); 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; ((IBuffer)document).Remove(0, top.Length); Assert.AreEqual(document.Text, testText); ((IBuffer)document).Remove(0, document.Length); LineSegment line = document.GetLine(0); Assert.AreEqual(0, line.Offset); Assert.AreEqual(0, line.Length); Assert.AreEqual(0, document.Length); Assert.AreEqual(1, document.LineCount); }
static string StripHeaderAndBlankLines(string text, CodeDomProvider provider) { Mono.TextEditor.Document doc = new Mono.TextEditor.Document(); doc.Text = text; int realStartLine = 0; for (int i = 0; i < doc.LineCount; i++) { var lineSegment = doc.GetLine(i); if (lineSegment == null) { continue; } string lineText = doc.GetTextAt(lineSegment); // Microsoft.NET generates "auto-generated" tags where Mono generates "autogenerated" tags. if (lineText.Contains("</autofgenerated>") || 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 = 0; 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.Length > 0) { ((Mono.TextEditor.IBuffer)doc).Remove(line.Offset, line.Length); i--; } previousWasBlank = isBlank || isBracket; } } int offset = doc.GetLine(realStartLine).Offset; return(doc.GetTextAt(offset, doc.Length - offset)); }
public void TestDocumentBug1Test() { Document document = new Mono.TextEditor.Document(); string top = "1234567890"; document.Text = top; Assert.AreEqual(document.GetLine(0).Length, document.Length); ((IBuffer)document).Remove(0, document.Length); LineSegment line = document.GetLine(0); Assert.AreEqual(0, line.Offset); Assert.AreEqual(0, line.Length); Assert.AreEqual(0, document.Length); Assert.AreEqual(1, document.LineCount); }
public void SplitterTest() { Document document = new Mono.TextEditor.Document(); for (int i = 0; i < 100; i++) { ((IBuffer)document).Insert(0, new string ('c', i) + Environment.NewLine); } Assert.AreEqual(101, document.LineCount); for (int i = 0; i < 100; i++) { LineSegment line = document.GetLine(i); Assert.AreEqual(99 - i, line.EditableLength); Assert.AreEqual(Environment.NewLine.Length, line.DelimiterLength); } for (int i = 0; i < 100; i++) { LineSegment line = document.GetLine(0); ((IBuffer)document).Remove(line.EditableLength, line.DelimiterLength); } Assert.AreEqual(1, document.LineCount); }
internal static string CreateWrapperClassForMember(IMember member, string fileName, TextEditor editor) { if (member == null) { return(""); } StringBuilder result = new StringBuilder(); int startLine = member.Location.Line; int endLine = member.Location.Line; if (!member.BodyRegion.IsEmpty) { endLine = member.BodyRegion.End.Line + 1; } string text; result.Append("class " + member.DeclaringType.Name + " {"); if (editor != null) { int col, maxLine; editor.GetLineColumnFromPosition(editor.TextLength - 1, out col, out maxLine); endLine = System.Math.Max(endLine, maxLine); int endPos = editor.GetPositionFromLineColumn(endLine, editor.GetLineLength(endLine)); if (endPos < 0) { endPos = editor.TextLength; } int startPos = Math.Max(0, editor.GetPositionFromLineColumn(startLine, 0)); text = editor.GetText(startPos, endPos); } else { Mono.TextEditor.Document doc = new Mono.TextEditor.Document(); doc.Text = File.ReadAllText(fileName) ?? ""; startLine = Math.Min(doc.LineCount, Math.Max(1, startLine)); endLine = Math.Min(doc.LineCount, Math.Max(1, endLine)); int startOffset = doc.LocationToOffset(startLine - 1, 0); text = doc.GetTextAt(startOffset, doc.LocationToOffset(endLine - 1, doc.GetLine(endLine - 1).EditableLength) - startOffset); } if (!string.IsNullOrEmpty(text)) { result.Append(text); } result.Append("}"); return(result.ToString()); }
public void TestDocumentBug2Test() { Document document = new Mono.TextEditor.Document(); string top = "123\n456\n789\n0"; string testText = "Hello World!"; document.Text = top; ((IBuffer)document).Insert(top.Length, testText); LineSegment line = document.GetLine(document.LineCount - 1); Assert.AreEqual(top.Length - 1, line.Offset); Assert.AreEqual(testText.Length + 1, line.Length); }
public void TestUpdateFoldSegmentBug2 () { Document document = new Mono.TextEditor.Document (); document.Text = @"-[0 1 +[2 3] 4 +[5 6] 7 8 9 10 11 12 13] 14 15"; var segments = GetFoldSegments (document); document.UpdateFoldSegments (segments, false); Assert.AreEqual (10, document.VisualToLogicalLine (8)); int start = document.GetLine (2).Offset; int end = document.GetLine (8).Offset; ((IBuffer)document).Remove (start, end - start); Assert.AreEqual (10, document.LogicalToVisualLine (10)); }
static string StripHeaderAndBlankLines (string text, CodeDomProvider provider) { Mono.TextEditor.Document doc = new Mono.TextEditor.Document (); 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.Length > 0) { ((Mono.TextEditor.IBuffer)doc).Remove (line.Offset, line.Length); i--; } previousWasBlank = isBlank || isBracket; } } int offset = doc.GetLine (realStartLine).Offset; return doc.GetTextAt (offset, doc.Length - offset); }
public void TestDocumentRemove () { Document document = new Mono.TextEditor.Document (); 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; ((IBuffer)document).Remove (0, top.Length); Assert.AreEqual (document.Text, testText); ((IBuffer)document).Remove (0, document.Length); LineSegment line = document.GetLine (0); Assert.AreEqual (0, line.Offset); Assert.AreEqual (0, line.Length); Assert.AreEqual (0, document.Length); Assert.AreEqual (1, document.LineCount); }
public void SplitterTest () { Document document = new Mono.TextEditor.Document (); for (int i = 0; i < 100; i++) { ((IBuffer)document).Insert (0, new string ('c', i) + Environment.NewLine); } Assert.AreEqual (101, document.LineCount); for (int i = 0; i < 100; i++) { LineSegment line = document.GetLine (i); Assert.AreEqual (99 - i, line.EditableLength); Assert.AreEqual (Environment.NewLine.Length, line.DelimiterLength); } for (int i = 0; i < 100; i++) { LineSegment line = document.GetLine (0); ((IBuffer)document).Remove (line.EditableLength, line.DelimiterLength); } Assert.AreEqual (1, document.LineCount); }
public void TestDocumentBug2Test() { Document document = new Mono.TextEditor.Document (); string top = "123\n456\n789\n0"; string testText = "Hello World!"; document.Text = top; ((IBuffer)document).Insert (top.Length, testText); LineSegment line = document.GetLine (document.LineCount - 1); Assert.AreEqual (top.Length - 1, line.Offset); Assert.AreEqual (testText.Length + 1, line.Length); }
public void TestDocumentBug1Test() { Document document = new Mono.TextEditor.Document (); string top = "1234567890"; document.Text = top; Assert.AreEqual (document.GetLine (0).Length, document.Length); ((IBuffer)document).Remove(0, document.Length); LineSegment line = document.GetLine (0); Assert.AreEqual(0, line.Offset); Assert.AreEqual(0, line.Length); Assert.AreEqual(0, document.Length); Assert.AreEqual(1, document.LineCount); }
internal static string CreateWrapperClassForMember(IMember member, string fileName, TextEditor editor) { if (member == null) return ""; StringBuilder result = new StringBuilder (); int startLine = member.Location.Line; int endLine = member.Location.Line; if (!member.BodyRegion.IsEmpty) endLine = member.BodyRegion.End.Line + 1; string text; result.Append ("class " + member.DeclaringType.Name + " {"); if (editor != null) { int col, maxLine; editor.GetLineColumnFromPosition (editor.TextLength - 1, out col, out maxLine); endLine = System.Math.Max (endLine, maxLine); int endPos = editor.GetPositionFromLineColumn (endLine, editor.GetLineLength (endLine)); if (endPos < 0) endPos = editor.TextLength; text = editor.GetText (editor.GetPositionFromLineColumn (startLine, 0), endPos); } else { Mono.TextEditor.Document doc = new Mono.TextEditor.Document (); doc.Text = File.ReadAllText (fileName) ?? ""; startLine = Math.Min (doc.LineCount, Math.Max (1, startLine)); endLine = Math.Min (doc.LineCount, Math.Max (1, endLine)); int startOffset = doc.LocationToOffset (startLine - 1, 0); text = doc.GetTextAt (startOffset, doc.LocationToOffset (endLine - 1, doc.GetLine (endLine - 1).EditableLength) - startOffset); } if (!string.IsNullOrEmpty (text)) result.Append (text); result.Append ("}"); return result.ToString (); }
public void TestUpdateFoldSegmentBug2 () { Document document = new Mono.TextEditor.Document (); document.Text = @"-[1 2 +[3 4] 5 +[6 7] 8 9 10 11 12 13 14] 15 16"; var segments = GetFoldSegments (document); document.UpdateFoldSegments (segments, false); Assert.AreEqual (10, document.VisualToLogicalLine (8)); Assert.AreEqual (3, document.FoldSegments.Count ()); int start = document.GetLine (2).Offset; int end = document.GetLine (8).Offset; ((IBuffer)document).Remove (start, end - start); Assert.AreEqual (1, document.FoldSegments.Count ()); Assert.AreEqual (10, document.LogicalToVisualLine (10)); }