예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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));
        }
예제 #6
0
        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);
        }
예제 #7
0
        public void TestDocumentBug2Test()
        {
            var document = new Mono.TextEditor.TextDocument();

            string top      = "123\n456\n789\n0";
            string testText = "Hello World!";

            document.Text = top;

            document.Insert(top.Length, testText);

            DocumentLine line = document.GetLine(document.LineCount);

            Assert.AreEqual(top.Length - 1, line.Offset);
            Assert.AreEqual(testText.Length + 1, line.LengthIncludingDelimiter);
        }
예제 #8
0
		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);
		}
예제 #9
0
        public void TestDocumentBug2Test()
        {
            var document = new Mono.TextEditor.TextDocument ();

            string top      = "123\n456\n789\n0";
            string testText = "Hello World!";

            document.Text = top;

            document.Insert (top.Length, testText);

            DocumentLine line = document.GetLine (document.LineCount);

            Assert.AreEqual (top.Length - 1, line.Offset);
            Assert.AreEqual (testText.Length + 1, line.LengthIncludingDelimiter);
        }
예제 #10
0
        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);
        }
예제 #11
0
        IDocumentLine IReadonlyTextDocument.GetLine(int lineNumber)
        {
            var line = snapshot.GetLine(lineNumber);

            return(line != null ? new DocumentLineWrapper(line) : null);
        }