diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFormattingStrategy.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFormattingStrategy.cs index 96bae7c079..0439d01b5c 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFormattingStrategy.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFormattingStrategy.cs @@ -14,6 +14,7 @@ using System.Text; using System.Xml; using ICSharpCode.Core; +using ICSharpCode.NRefactory; using ICSharpCode.SharpDevelop.Editor; namespace ICSharpCode.XmlEditor @@ -112,6 +113,7 @@ namespace ICSharpCode.XmlEditor string currentIndentation = ""; Stack tagStack = new Stack(); IDocument document = editor.Document; + string tab = editor.Options.IndentationString; int nextLine = begin; // in #dev coordinates bool wasEmptyElement = false; @@ -134,7 +136,7 @@ namespace ICSharpCode.XmlEditor currentIndentation = tagStack.Pop(); } - while (r.LineNumber > nextLine) { // caution: here we compare 1-based and 0-based line numbers + while (r.LineNumber >= nextLine) { if (nextLine > end) break; if (lastType == XmlNodeType.CDATA || lastType == XmlNodeType.Comment) { nextLine++; @@ -152,7 +154,10 @@ namespace ICSharpCode.XmlEditor newText = currentIndentation + lineText.Trim(); if (newText != lineText) { + int extraCharsToBeAddedAtStartedOfLine = newText.Length - lineText.Length; document.Replace(line.Offset, line.Length, newText); + Location caretPosition = document.OffsetToPosition(line.Offset + extraCharsToBeAddedAtStartedOfLine); + editor.Caret.Position = caretPosition; } nextLine++; } @@ -177,7 +182,7 @@ namespace ICSharpCode.XmlEditor if (r.LineNumber != startLine) attribIndent = currentIndentation; // change to tab-indentation r.MoveToAttribute(r.AttributeCount - 1); - while (r.LineNumber > nextLine) { + while (r.LineNumber >= nextLine) { if (nextLine > end) break; // set indentation of 'nextLine' IDocumentLine line = document.GetLine(nextLine); @@ -190,6 +195,5 @@ namespace ICSharpCode.XmlEditor r.Close(); } } - } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/ElementEndAddedAfterGreaterThanCharTypedTestFixture.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/ElementEndAddedAfterGreaterThanCharTypedTestFixture.cs new file mode 100644 index 0000000000..6c6fa6acfd --- /dev/null +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/ElementEndAddedAfterGreaterThanCharTypedTestFixture.cs @@ -0,0 +1,82 @@ +// +// +// +// +// $Revision$ +// + +using System; + +using ICSharpCode.AvalonEdit.Document; +using ICSharpCode.NRefactory; +using ICSharpCode.SharpDevelop.Editor.AvalonEdit; +using ICSharpCode.XmlEditor; +using NUnit.Framework; +using XmlEditor.Tests.Utils; + +namespace XmlEditor.Tests.Editor +{ + [TestFixture] + public class ElementEndAddedAfterGreaterThanCharTypedTestFixture + { + XmlFormattingStrategy formattingStrategy; + MockTextEditor textEditor; + MockTextEditorOptions options; + AvalonEditDocumentAdapter document; + TextDocument textDocument; + + [SetUp] + public void Init() + { + formattingStrategy = new XmlFormattingStrategy(); + + options = new MockTextEditorOptions(); + textEditor = new MockTextEditor(); + textEditor.Options = options; + + textDocument = new TextDocument(); + document = new AvalonEditDocumentAdapter(textDocument, null); + textEditor.SetDocument(document); + + document.Text = + "\r\n" + + "\t\r\n" + + "\r\n"; + + // Just typed the '>' character of the element + textEditor.Caret.Offset = 16; + formattingStrategy.FormatLine(textEditor, '>'); + } + + [Test] + public void ChildEndElementAddedAfterGreaterThanCharTyped() + { + string expectedText = + "\r\n" + + "\t\r\n" + + "\r\n"; + + Assert.AreEqual(expectedText, document.Text); + } + + [Test] + public void IndentCanBeUndoneInOneStep() + { + string expectedText = + "\r\n" + + "\t\r\n" + + "\r\n"; + + textDocument.UndoStack.Undo(); + + Assert.AreEqual(expectedText, textDocument.Text); + } + + [Test] + public void CursorIsJustBeforeEndElementTagAfterLinesFormatted() + { + int newCaretOffset = 16; + Assert.AreEqual(newCaretOffset, textEditor.Caret.Offset); + } + } +} diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/IndentChildElementEndTagAfterNewLineTypedTestFixture.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/IndentChildElementEndTagAfterNewLineTypedTestFixture.cs new file mode 100644 index 0000000000..9719458fe5 --- /dev/null +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/IndentChildElementEndTagAfterNewLineTypedTestFixture.cs @@ -0,0 +1,88 @@ +// +// +// +// +// $Revision$ +// + +using System; + +using ICSharpCode.AvalonEdit.Document; +using ICSharpCode.NRefactory; +using ICSharpCode.SharpDevelop.Editor.AvalonEdit; +using ICSharpCode.XmlEditor; +using NUnit.Framework; +using XmlEditor.Tests.Utils; + +namespace XmlEditor.Tests.Editor +{ + [TestFixture] + public class IndentChildElementEndTagAfterNewLineTypedTestFixture + { + XmlFormattingStrategy formattingStrategy; + MockTextEditor textEditor; + MockTextEditorOptions options; + MockDocumentLine docLine; + AvalonEditDocumentAdapter document; + TextDocument textDocument; + + [SetUp] + public void Init() + { + formattingStrategy = new XmlFormattingStrategy(); + + options = new MockTextEditorOptions(); + textEditor = new MockTextEditor(); + textEditor.Options = options; + + textDocument = new TextDocument(); + document = new AvalonEditDocumentAdapter(textDocument, null); + textEditor.SetDocument(document); + + document.Text = + "\r\n" + + "\t\r\n" + + "\r\n" + + "\r\n"; + + docLine = new MockDocumentLine(); + docLine.LineNumber = 3; + formattingStrategy.IndentLine(textEditor, docLine); + } + + [Test] + public void ChildEndElementIndentedBySameLevelAsStartElementAfterNewLineTyped() + { + string expectedText = + "\r\n" + + "\t\r\n" + + "\t\r\n" + + "\r\n"; + + Assert.AreEqual(expectedText, document.Text); + } + + [Test] + public void IndentCanBeUndoneInOneStep() + { + string expectedText = + "\r\n" + + "\t\r\n" + + "\r\n" + + "\r\n"; + + textDocument.UndoStack.Undo(); + + Assert.AreEqual(expectedText, textDocument.Text); + } + + [Test] + public void CursorIsJustBeforeChildEndElementEndTagAfterIndent() + { + int line = 3; + int column = 2; + Location expectedLocation = new Location(column, line); + Assert.AreEqual(expectedLocation, textEditor.Caret.Position); + } + } +} diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/IndentLinesTests.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/IndentLinesTests.cs new file mode 100644 index 0000000000..bf963013ec --- /dev/null +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/IndentLinesTests.cs @@ -0,0 +1,245 @@ +// +// +// +// +// $Revision$ +// + +using System; + +using ICSharpCode.AvalonEdit.Document; +using ICSharpCode.NRefactory; +using ICSharpCode.SharpDevelop.Editor.AvalonEdit; +using ICSharpCode.XmlEditor; +using NUnit.Framework; +using XmlEditor.Tests.Utils; + +namespace XmlEditor.Tests.Editor +{ + [TestFixture] + public class IndentLinesTests + { + XmlFormattingStrategy formattingStrategy; + MockTextEditor textEditor; + MockTextEditorOptions options; + AvalonEditDocumentAdapter document; + TextDocument textDocument; + + [SetUp] + public void Init() + { + formattingStrategy = new XmlFormattingStrategy(); + + options = new MockTextEditorOptions(); + textEditor = new MockTextEditor(); + textEditor.Options = options; + + textDocument = new TextDocument(); + document = new AvalonEditDocumentAdapter(textDocument, null); + textEditor.SetDocument(document); + } + + [Test] + public void IndentLinesIndentsChildElement() + { + document.Text = + "\r\n" + + "\r\n" + + "\r\n" + + ""; + + string expectedText = + "\r\n" + + "\t\r\n" + + "\t\r\n" + + ""; + + formattingStrategy.IndentLines(textEditor, 1, 4); + + Assert.AreEqual(expectedText, document.Text); + } + + public void IndentLinesIndentsChildElementUsingTextEditorIndentationString() + { + document.Text = + "\r\n" + + "\r\n" + + "\r\n" + + ""; + + string expectedText = + "\r\n" + + " \r\n" + + " \r\n" + + ""; + + MockTextEditorOptions options = new MockTextEditorOptions(); + options.IndentationString = " "; + textEditor.Options = options; + + formattingStrategy.IndentLines(textEditor, 1, 4); + + Assert.AreEqual(expectedText, document.Text); + } + + [Test] + public void IndentsChildElementAttributesOnOtherLine() + { + document.Text = + "\r\n" + + "\r\n" + + "\r\n" + + ""; + + string expectedText = + "\r\n" + + "\t\r\n" + + "\t\r\n" + + ""; + + formattingStrategy.IndentLines(textEditor, 1, 6); + + Assert.AreEqual(expectedText, document.Text, document.Text); + } + + [Test] + public void IndentsChildElementAttributeWithSpacesWhenFirstAttributeOnStartElementLine() + { + document.Text = + "\r\n" + + "\r\n" + + "\r\n" + + ""; + + string expectedText = + "\r\n" + + "\t\r\n" + + "\t\r\n" + + ""; + + formattingStrategy.IndentLines(textEditor, 1, 6); + + Assert.AreEqual(expectedText, document.Text, document.Text); + } + + [Test] + public void IndentsChildElementAttributeWithTabsWhenChildElementNameIsLargerThan16Chars() + { + document.Text = + "\r\n" + + "\r\n" + + "\r\n" + + ""; + + string expectedText = + "\r\n" + + "\t\r\n" + + "\t\r\n" + + ""; + + formattingStrategy.IndentLines(textEditor, 1, 6); + + Assert.AreEqual(expectedText, document.Text, document.Text); + } + + [Test] + public void SingleCommentLineIsIndented() + { + document.Text = + "\r\n" + + "\r\n" + + "\r\n" + + ""; + + string expectedText = + "\r\n" + + "\t\r\n" + + "\t\r\n" + + ""; + + formattingStrategy.IndentLines(textEditor, 1, 4); + + Assert.AreEqual(expectedText, document.Text, document.Text); + } + + [Test] + public void MultipleLineCommentOnlyHasFirstLineIndented() + { + document.Text = + "\r\n" + + "\r\n" + + "\r\n" + + ""; + + string expectedText = + "\r\n" + + "\t\r\n" + + "\t\r\n" + + ""; + + formattingStrategy.IndentLines(textEditor, 1, 6); + + Assert.AreEqual(expectedText, document.Text, document.Text); + } + + [Test] + public void SingleCDataIsIndented() + { + document.Text = + "\r\n" + + "\r\n" + + "\r\n" + + ""; + + string expectedText = + "\r\n" + + "\t\r\n" + + "\t\r\n" + + ""; + + formattingStrategy.IndentLines(textEditor, 1, 4); + + Assert.AreEqual(expectedText, document.Text, document.Text); + } + + [Test] + public void MultipleLineCDataOnlyHasFirstLineIndented() + { + document.Text = + "\r\n" + + "\r\n" + + "\r\n" + + ""; + + string expectedText = + "\r\n" + + "\t\r\n" + + "\t\r\n" + + ""; + + formattingStrategy.IndentLines(textEditor, 1, 6); + + Assert.AreEqual(expectedText, document.Text, document.Text); + } + } +} diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/NoElementEndAddedAfterGreaterThanCharTypedTests.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/NoElementEndAddedAfterGreaterThanCharTypedTests.cs new file mode 100644 index 0000000000..7112e42c44 --- /dev/null +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/NoElementEndAddedAfterGreaterThanCharTypedTests.cs @@ -0,0 +1,100 @@ +// +// +// +// +// $Revision$ +// + +using System; + +using ICSharpCode.AvalonEdit.Document; +using ICSharpCode.NRefactory; +using ICSharpCode.SharpDevelop.Editor.AvalonEdit; +using ICSharpCode.XmlEditor; +using NUnit.Framework; +using XmlEditor.Tests.Utils; + +namespace XmlEditor.Tests.Editor +{ + [TestFixture] + public class NoElementEndAddedAfterGreaterThanCharTypedTests + { + XmlFormattingStrategy formattingStrategy; + MockTextEditor textEditor; + MockTextEditorOptions options; + AvalonEditDocumentAdapter document; + TextDocument textDocument; + + [SetUp] + public void Init() + { + formattingStrategy = new XmlFormattingStrategy(); + + options = new MockTextEditorOptions(); + textEditor = new MockTextEditor(); + textEditor.Options = options; + + textDocument = new TextDocument(); + document = new AvalonEditDocumentAdapter(textDocument, null); + textEditor.SetDocument(document); + } + + [Test] + public void TextNotChangedWhenGreaterThanCharTypedAndChildEndElementAlreadyExists() + { + string text = + "\r\n" + + "\t\r\n" + + "\r\n"; + document.Text = text; + + // Just typed the '>' character of the element + textEditor.Caret.Offset = 16; + formattingStrategy.FormatLine(textEditor, '>'); + + Assert.AreEqual(text, document.Text); + } + + [Test] + public void TextNotChangedWhenGreaterThanCharTypedAndChildElementIsEmptyElement() + { + string text = + "\r\n" + + "\t\r\n" + + "\r\n"; + document.Text = text; + + // Just typed the '>' character of the element + textEditor.Caret.Offset = 17; + formattingStrategy.FormatLine(textEditor, '>'); + + Assert.AreEqual(text, document.Text); + } + + [Test] + public void TextNotChangedWhenGreaterThanCharTypedForCommentTag() + { + string text = ""; + document.Text = text; + + // Just typed the '>' character of the comment tag + textEditor.Caret.Offset = 10; + formattingStrategy.FormatLine(textEditor, '>'); + + Assert.AreEqual(text, document.Text); + } + + [Test] + public void TextNotChangedWhenGreaterThanCharTypedForPreProcessingInstruction() + { + string text = ""; + document.Text = text; + + // Just typed the '>' character of the pre-processing instruction + textEditor.Caret.Offset = 21; + formattingStrategy.FormatLine(textEditor, '>'); + + Assert.AreEqual(text, document.Text); + } + } +} diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/SurroundTextWithCommentBlockTestFixture.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/SurroundTextWithCommentBlockTestFixture.cs new file mode 100644 index 0000000000..cf4861b7db --- /dev/null +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Editor/SurroundTextWithCommentBlockTestFixture.cs @@ -0,0 +1,77 @@ +// +// +// +// +// $Revision$ +// + +using ICSharpCode.AvalonEdit.Document; +using ICSharpCode.NRefactory; +using ICSharpCode.SharpDevelop.Editor.AvalonEdit; +using ICSharpCode.XmlEditor; +using NUnit.Framework; +using XmlEditor.Tests.Utils; + +namespace XmlEditor.Tests.Editor +{ + [TestFixture] + public class SurroundTextWithCommentBlockTestFixture + { + XmlFormattingStrategy formattingStrategy; + MockTextEditor textEditor; + MockTextEditorOptions options; + AvalonEditDocumentAdapter document; + TextDocument textDocument; + + [SetUp] + public void Init() + { + formattingStrategy = new XmlFormattingStrategy(); + + options = new MockTextEditorOptions(); + textEditor = new MockTextEditor(); + textEditor.Options = options; + + textDocument = new TextDocument(); + document = new AvalonEditDocumentAdapter(textDocument, null); + textEditor.SetDocument(document); + + textDocument.Text = + "\r\n" + + "\t\r\n" + + ""; + + int selectionStart = 9; + int selectionLength = 15; + textEditor.Select(selectionStart, selectionLength); + + formattingStrategy.SurroundSelectionWithComment(textEditor); + } + + [Test] + public void ChildElementSurroundedByCommentTags() + { + string expectedText = + "\r\n" + + "\t\r\n" + + ""; + Assert.AreEqual(expectedText, document.Text); + } + + [Test] + public void CallingSurroundSelectionWithCommentRemovesCommentTagsWhenCommentTagsExist() + { + int selectionStart = 14; + int selectionLength = 2; + textEditor.Select(selectionStart, selectionLength); + formattingStrategy.SurroundSelectionWithComment(textEditor); + + string expectedText = + "\r\n" + + "\t\r\n" + + ""; + + Assert.AreEqual(expectedText, document.Text); + } + } +} diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockCaret.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockCaret.cs index 95af853e67..6293c6d644 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockCaret.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockCaret.cs @@ -17,6 +17,7 @@ namespace XmlEditor.Tests.Utils public MockCaret() { + Position = Location.Empty; } public event EventHandler PositionChanged; @@ -51,13 +52,6 @@ namespace XmlEditor.Tests.Utils } } - public Location Position { - get { - throw new NotImplementedException(); - } - set { - throw new NotImplementedException(); - } - } + public Location Position { get; set; } } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockDocumentLine.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockDocumentLine.cs new file mode 100644 index 0000000000..f78e9ee3d3 --- /dev/null +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockDocumentLine.cs @@ -0,0 +1,57 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop.Editor; + +namespace XmlEditor.Tests.Utils +{ + public class MockDocumentLine : IDocumentLine + { + public MockDocumentLine() + { + } + + public int Offset { + get { + throw new NotImplementedException(); + } + } + + public int Length { + get { + throw new NotImplementedException(); + } + } + + public int EndOffset { + get { + throw new NotImplementedException(); + } + } + + public int TotalLength { + get { + throw new NotImplementedException(); + } + } + + public int DelimiterLength { + get { + throw new NotImplementedException(); + } + } + + public int LineNumber { get; set; } + + public string Text { + get { + throw new NotImplementedException(); + } + } + } +} diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextEditor.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextEditor.cs index 5261ed2624..808e22edeb 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextEditor.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextEditor.cs @@ -21,10 +21,13 @@ namespace XmlEditor.Tests.Utils MockCompletionListWindow completionWindowDisplayed; ICompletionItemList completionItemsDisplayed; MockCaret caret = new MockCaret(); - MockDocument document = new MockDocument(); + IDocument document = new MockDocument(); + ITextEditorOptions options = new MockTextEditorOptions(); FileName fileName; bool showCompletionWindowReturnsNull; bool showCompletionWindowMethodCalled; + int selectionStart; + int selectionLength; public MockTextEditor() { @@ -58,8 +61,13 @@ namespace XmlEditor.Tests.Utils get { return document; } } + public void SetDocument(IDocument document) + { + this.document = document; + } + public MockDocument MockDocument { - get { return document; } + get { return document as MockDocument; } } public ITextEditorCaret Caret { @@ -67,9 +75,8 @@ namespace XmlEditor.Tests.Utils } public ITextEditorOptions Options { - get { - throw new NotImplementedException(); - } + get { return options; } + set { options = value; } } public ILanguageBinding Language { @@ -79,21 +86,15 @@ namespace XmlEditor.Tests.Utils } public int SelectionStart { - get { - throw new NotImplementedException(); - } + get { return selectionStart; } } public int SelectionLength { - get { - throw new NotImplementedException(); - } + get { return selectionLength; } } public string SelectedText { - get { - throw new NotImplementedException(); - } + get { return document.GetText(selectionStart, selectionLength); } set { throw new NotImplementedException(); } @@ -118,7 +119,8 @@ namespace XmlEditor.Tests.Utils public void Select(int selectionStart, int selectionLength) { - throw new NotImplementedException(); + this.selectionStart = selectionStart; + this.selectionLength = selectionLength; } public void JumpTo(int line, int column) diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextEditorOptions.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextEditorOptions.cs new file mode 100644 index 0000000000..250bfa5144 --- /dev/null +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextEditorOptions.cs @@ -0,0 +1,46 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop.Editor; + +namespace XmlEditor.Tests.Utils +{ + public class MockTextEditorOptions : ITextEditorOptions + { + public MockTextEditorOptions() + { + IndentationString = "\t"; + } + + public string IndentationString { get; set; } + + public bool AutoInsertBlockEnd { + get { + throw new NotImplementedException(); + } + } + + public bool ConvertTabsToSpaces { + get { + throw new NotImplementedException(); + } + } + + public int IndentationSize { + get { + throw new NotImplementedException(); + } + } + + public int VerticalRulerColumn { + get { + throw new NotImplementedException(); + } + } + } +} diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockCaretTests.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockCaretTests.cs new file mode 100644 index 0000000000..5986b98a9b --- /dev/null +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockCaretTests.cs @@ -0,0 +1,53 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.NRefactory; +using NUnit.Framework; +using XmlEditor.Tests.Utils; + +namespace XmlEditor.Tests.Utils.Tests +{ + [TestFixture] + public class MockCaretTests + { + MockCaret caret; + + [SetUp] + public void Init() + { + caret = new MockCaret(); + } + + [Test] + public void CanSetAndGetCaretOffset() + { + caret.Offset = 3; + Assert.AreEqual(3, caret.Offset); + } + + [Test] + public void InitialCaretOffsetIsMinusOne() + { + Assert.AreEqual(-1, caret.Offset); + } + + [Test] + public void CanGetAndSetCaretPosition() + { + Location location = new Location(3, 2); + caret.Position = location; + Assert.AreEqual(location, caret.Position); + } + + [Test] + public void DefaultCaretPostionIsEmpty() + { + Assert.AreEqual(Location.Empty, caret.Position); + } + } +} diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockDocumentLineTests.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockDocumentLineTests.cs new file mode 100644 index 0000000000..fe198fca66 --- /dev/null +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockDocumentLineTests.cs @@ -0,0 +1,32 @@ +// +// +// +// +// $Revision$ +// + +using System; +using NUnit.Framework; +using XmlEditor.Tests.Utils; + +namespace XmlEditor.Tests.Utils.Tests +{ + [TestFixture] + public class MockDocumentLineTests + { + MockDocumentLine documentLine; + + [SetUp] + public void Init() + { + documentLine = new MockDocumentLine(); + } + + [Test] + public void CanSetAndGetLineNumberProperty() + { + documentLine.LineNumber = 2; + Assert.AreEqual(2, documentLine.LineNumber); + } + } +} diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockDocumentTests.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockDocumentTests.cs index e8a08fdc1f..3aca929fad 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockDocumentTests.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockDocumentTests.cs @@ -19,12 +19,19 @@ namespace XmlEditor.Tests.Utils.Tests [TestFixture] public class MockDocumentTests { + MockDocument document; + + [SetUp] + public void Init() + { + document = new MockDocument(); + } + [Test] public void TextEditorDocumentCanGetOffsetAndLengthUsedAsParametersInGetTextMethod() { TextSection expectedSection = new TextSection(0, 5); - MockDocument document = new MockDocument(); document.Text = "abcdefghi"; document.GetText(0, 5); @@ -58,7 +65,7 @@ namespace XmlEditor.Tests.Utils.Tests TextSection rhs = new TextSection(1, 1); Assert.IsFalse(lhs.Equals(rhs)); - } + } [Test] public void TextSectionWithDifferentLengthAreNotEqual() @@ -67,6 +74,6 @@ namespace XmlEditor.Tests.Utils.Tests TextSection rhs = new TextSection(0, 1); Assert.IsFalse(lhs.Equals(rhs)); - } + } } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockTextEditorOptionsTests.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockTextEditorOptionsTests.cs new file mode 100644 index 0000000000..260d76ea48 --- /dev/null +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockTextEditorOptionsTests.cs @@ -0,0 +1,38 @@ +// +// +// +// +// $Revision$ +// + +using System; +using NUnit.Framework; +using XmlEditor.Tests.Utils; + +namespace XmlEditor.Tests.Utils.Tests +{ + [TestFixture] + public class MockTextEditorOptionsTests + { + MockTextEditorOptions options; + + [SetUp] + public void Init() + { + options = new MockTextEditorOptions(); + } + + [Test] + public void IndentationStringIsSingleTabByDefault() + { + Assert.AreEqual("\t", options.IndentationString); + } + + [Test] + public void CanSetAndGetIndentationString() + { + options.IndentationString = "abc"; + Assert.AreEqual("abc", options.IndentationString); + } + } +} diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockTextEditorTests.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockTextEditorTests.cs index 1e79ebf6a8..49b0ee0a3d 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockTextEditorTests.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockTextEditorTests.cs @@ -112,5 +112,60 @@ namespace XmlEditor.Tests.Utils.Tests { Assert.IsFalse(editor.IsShowCompletionWindowMethodCalled); } + + [Test] + public void CanSetAndGetTextEditorOptions() + { + MockTextEditorOptions options = new MockTextEditorOptions(); + editor.Options = options; + Assert.AreSame(options, editor.Options); + } + + [Test] + public void TextEditorHasNonNullTextEditorOptionsWhenCreated() + { + Assert.IsNotNull(editor.Options); + } + + [Test] + public void CanReplaceDocumentObjectUsed() + { + MockDocument doc = new MockDocument(); + editor.SetDocument(doc); + Assert.AreSame(doc, editor.Document); + } + + [Test] + public void CanGetAndSetSelectionStart() + { + editor.Document.Text = "abc"; + int selectionStart = 1; + int selectionLength = 2; + editor.Select(selectionStart, selectionLength); + + Assert.AreEqual(selectionStart, editor.SelectionStart); + } + + [Test] + public void CanGetAndSetSelectionLength() + { + editor.Document.Text = "abc"; + int selectionStart = 1; + int selectionLength = 2; + editor.Select(selectionStart, selectionLength); + + Assert.AreEqual(selectionLength, editor.SelectionLength); + } + + [Test] + public void SelectedTextPropertyReturnsSelectedText() + { + editor.Document.Text = "abc"; + int selectionStart = 1; + int selectionLength = 2; + editor.Select(selectionStart, selectionLength); + + Assert.AreEqual("bc", editor.SelectedText); + } } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj b/src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj index 4fab261725..49fd56dbee 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj @@ -96,10 +96,14 @@ + + + + @@ -111,6 +115,7 @@ + @@ -218,11 +223,13 @@ + + @@ -231,11 +238,14 @@ + + + @@ -298,6 +308,10 @@ + + {6C55B776-26D4-4DB3-A6AB-87E783B2F3D1} + ICSharpCode.AvalonEdit + {2D18BE89-D210-49EB-A9DD-2246FBB3DF6D} ICSharpCode.TextEditor