Browse Source

Added unit tests for XmlFormattingStrategy.

Xml element end tag now indents to the same level as the opening tag when the return key is pressed.
Xml attributes now indent to the same level when the return key is pressed.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5289 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Matt Ward 17 years ago
parent
commit
0b148f5fbd
  1. 10
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFormattingStrategy.cs
  2. 82
      src/AddIns/DisplayBindings/XmlEditor/Test/Editor/ElementEndAddedAfterGreaterThanCharTypedTestFixture.cs
  3. 88
      src/AddIns/DisplayBindings/XmlEditor/Test/Editor/IndentChildElementEndTagAfterNewLineTypedTestFixture.cs
  4. 245
      src/AddIns/DisplayBindings/XmlEditor/Test/Editor/IndentLinesTests.cs
  5. 100
      src/AddIns/DisplayBindings/XmlEditor/Test/Editor/NoElementEndAddedAfterGreaterThanCharTypedTests.cs
  6. 77
      src/AddIns/DisplayBindings/XmlEditor/Test/Editor/SurroundTextWithCommentBlockTestFixture.cs
  7. 10
      src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockCaret.cs
  8. 57
      src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockDocumentLine.cs
  9. 32
      src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextEditor.cs
  10. 46
      src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextEditorOptions.cs
  11. 53
      src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockCaretTests.cs
  12. 32
      src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockDocumentLineTests.cs
  13. 9
      src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockDocumentTests.cs
  14. 38
      src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockTextEditorOptionsTests.cs
  15. 55
      src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockTextEditorTests.cs
  16. 14
      src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

10
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFormattingStrategy.cs

@ -14,6 +14,7 @@ using System.Text; @@ -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 @@ -112,6 +113,7 @@ namespace ICSharpCode.XmlEditor
string currentIndentation = "";
Stack<string> tagStack = new Stack<string>();
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 @@ -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 @@ -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 @@ -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 @@ -190,6 +195,5 @@ namespace ICSharpCode.XmlEditor
r.Close();
}
}
}
}

82
src/AddIns/DisplayBindings/XmlEditor/Test/Editor/ElementEndAddedAfterGreaterThanCharTypedTestFixture.cs

@ -0,0 +1,82 @@ @@ -0,0 +1,82 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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 =
"<root>\r\n" +
"\t<child>\r\n" +
"</root>\r\n";
// Just typed the '>' character of the <child> element
textEditor.Caret.Offset = 16;
formattingStrategy.FormatLine(textEditor, '>');
}
[Test]
public void ChildEndElementAddedAfterGreaterThanCharTyped()
{
string expectedText =
"<root>\r\n" +
"\t<child></child>\r\n" +
"</root>\r\n";
Assert.AreEqual(expectedText, document.Text);
}
[Test]
public void IndentCanBeUndoneInOneStep()
{
string expectedText =
"<root>\r\n" +
"\t<child>\r\n" +
"</root>\r\n";
textDocument.UndoStack.Undo();
Assert.AreEqual(expectedText, textDocument.Text);
}
[Test]
public void CursorIsJustBeforeEndElementTagAfterLinesFormatted()
{
int newCaretOffset = 16;
Assert.AreEqual(newCaretOffset, textEditor.Caret.Offset);
}
}
}

88
src/AddIns/DisplayBindings/XmlEditor/Test/Editor/IndentChildElementEndTagAfterNewLineTypedTestFixture.cs

@ -0,0 +1,88 @@ @@ -0,0 +1,88 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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 =
"<root>\r\n" +
"\t<child>\r\n" +
"</child>\r\n" +
"</root>\r\n";
docLine = new MockDocumentLine();
docLine.LineNumber = 3;
formattingStrategy.IndentLine(textEditor, docLine);
}
[Test]
public void ChildEndElementIndentedBySameLevelAsStartElementAfterNewLineTyped()
{
string expectedText =
"<root>\r\n" +
"\t<child>\r\n" +
"\t</child>\r\n" +
"</root>\r\n";
Assert.AreEqual(expectedText, document.Text);
}
[Test]
public void IndentCanBeUndoneInOneStep()
{
string expectedText =
"<root>\r\n" +
"\t<child>\r\n" +
"</child>\r\n" +
"</root>\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);
}
}
}

245
src/AddIns/DisplayBindings/XmlEditor/Test/Editor/IndentLinesTests.cs

@ -0,0 +1,245 @@ @@ -0,0 +1,245 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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 =
"<root>\r\n" +
"<child>\r\n" +
"</child>\r\n" +
"</root>";
string expectedText =
"<root>\r\n" +
"\t<child>\r\n" +
"\t</child>\r\n" +
"</root>";
formattingStrategy.IndentLines(textEditor, 1, 4);
Assert.AreEqual(expectedText, document.Text);
}
public void IndentLinesIndentsChildElementUsingTextEditorIndentationString()
{
document.Text =
"<root>\r\n" +
"<child>\r\n" +
"</child>\r\n" +
"</root>";
string expectedText =
"<root>\r\n" +
" <child>\r\n" +
" </child>\r\n" +
"</root>";
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 =
"<root>\r\n" +
"<child\r\n" +
"attribute1='1'\r\n" +
"attribute2='2'>\r\n" +
"</child>\r\n" +
"</root>";
string expectedText =
"<root>\r\n" +
"\t<child\r\n" +
"\t\tattribute1='1'\r\n" +
"\t\tattribute2='2'>\r\n" +
"\t</child>\r\n" +
"</root>";
formattingStrategy.IndentLines(textEditor, 1, 6);
Assert.AreEqual(expectedText, document.Text, document.Text);
}
[Test]
public void IndentsChildElementAttributeWithSpacesWhenFirstAttributeOnStartElementLine()
{
document.Text =
"<root>\r\n" +
"<child attribute1='1'\r\n" +
"attribute2='2'\r\n" +
"attribute3='3'>\r\n" +
"</child>\r\n" +
"</root>";
string expectedText =
"<root>\r\n" +
"\t<child attribute1='1'\r\n" +
"\t attribute2='2'\r\n" +
"\t attribute3='3'>\r\n" +
"\t</child>\r\n" +
"</root>";
formattingStrategy.IndentLines(textEditor, 1, 6);
Assert.AreEqual(expectedText, document.Text, document.Text);
}
[Test]
public void IndentsChildElementAttributeWithTabsWhenChildElementNameIsLargerThan16Chars()
{
document.Text =
"<root>\r\n" +
"<verylongchildelementname attribute1='1'\r\n" +
"attribute2='2'\r\n" +
"attribute3='3'>\r\n" +
"</verylongchildelementname>\r\n" +
"</root>";
string expectedText =
"<root>\r\n" +
"\t<verylongchildelementname attribute1='1'\r\n" +
"\t\tattribute2='2'\r\n" +
"\t\tattribute3='3'>\r\n" +
"\t</verylongchildelementname>\r\n" +
"</root>";
formattingStrategy.IndentLines(textEditor, 1, 6);
Assert.AreEqual(expectedText, document.Text, document.Text);
}
[Test]
public void SingleCommentLineIsIndented()
{
document.Text =
"<root>\r\n" +
"<!-- abc -->\r\n" +
"<child/>\r\n" +
"</root>";
string expectedText =
"<root>\r\n" +
"\t<!-- abc -->\r\n" +
"\t<child/>\r\n" +
"</root>";
formattingStrategy.IndentLines(textEditor, 1, 4);
Assert.AreEqual(expectedText, document.Text, document.Text);
}
[Test]
public void MultipleLineCommentOnlyHasFirstLineIndented()
{
document.Text =
"<root>\r\n" +
"<!-- 1st\r\n" +
"2nd\r\n" +
"3rd -->\r\n" +
"<child/>\r\n" +
"</root>";
string expectedText =
"<root>\r\n" +
"\t<!-- 1st\r\n" +
"2nd\r\n" +
"3rd -->\r\n" +
"\t<child/>\r\n" +
"</root>";
formattingStrategy.IndentLines(textEditor, 1, 6);
Assert.AreEqual(expectedText, document.Text, document.Text);
}
[Test]
public void SingleCDataIsIndented()
{
document.Text =
"<root>\r\n" +
"<![CDATA[ abc ]]>\r\n" +
"<child/>\r\n" +
"</root>";
string expectedText =
"<root>\r\n" +
"\t<![CDATA[ abc ]]>\r\n" +
"\t<child/>\r\n" +
"</root>";
formattingStrategy.IndentLines(textEditor, 1, 4);
Assert.AreEqual(expectedText, document.Text, document.Text);
}
[Test]
public void MultipleLineCDataOnlyHasFirstLineIndented()
{
document.Text =
"<root>\r\n" +
"<![CDATA[ 1st\r\n" +
"2nd\r\n" +
"3rd ]]>\r\n" +
"<child/>\r\n" +
"</root>";
string expectedText =
"<root>\r\n" +
"\t<![CDATA[ 1st\r\n" +
"2nd\r\n" +
"3rd ]]>\r\n" +
"\t<child/>\r\n" +
"</root>";
formattingStrategy.IndentLines(textEditor, 1, 6);
Assert.AreEqual(expectedText, document.Text, document.Text);
}
}
}

100
src/AddIns/DisplayBindings/XmlEditor/Test/Editor/NoElementEndAddedAfterGreaterThanCharTypedTests.cs

@ -0,0 +1,100 @@ @@ -0,0 +1,100 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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 =
"<root>\r\n" +
"\t<child></child>\r\n" +
"</root>\r\n";
document.Text = text;
// Just typed the '>' character of the <child> element
textEditor.Caret.Offset = 16;
formattingStrategy.FormatLine(textEditor, '>');
Assert.AreEqual(text, document.Text);
}
[Test]
public void TextNotChangedWhenGreaterThanCharTypedAndChildElementIsEmptyElement()
{
string text =
"<root>\r\n" +
"\t<child/>\r\n" +
"</root>\r\n";
document.Text = text;
// Just typed the '>' character of the <child/> element
textEditor.Caret.Offset = 17;
formattingStrategy.FormatLine(textEditor, '>');
Assert.AreEqual(text, document.Text);
}
[Test]
public void TextNotChangedWhenGreaterThanCharTypedForCommentTag()
{
string text = "<!-- a -->";
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 = "<?xml version=\"1.0\"?>";
document.Text = text;
// Just typed the '>' character of the pre-processing instruction
textEditor.Caret.Offset = 21;
formattingStrategy.FormatLine(textEditor, '>');
Assert.AreEqual(text, document.Text);
}
}
}

77
src/AddIns/DisplayBindings/XmlEditor/Test/Editor/SurroundTextWithCommentBlockTestFixture.cs

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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 =
"<root>\r\n" +
"\t<child></child>\r\n" +
"</root>";
int selectionStart = 9;
int selectionLength = 15;
textEditor.Select(selectionStart, selectionLength);
formattingStrategy.SurroundSelectionWithComment(textEditor);
}
[Test]
public void ChildElementSurroundedByCommentTags()
{
string expectedText =
"<root>\r\n" +
"\t<!--<child></child>-->\r\n" +
"</root>";
Assert.AreEqual(expectedText, document.Text);
}
[Test]
public void CallingSurroundSelectionWithCommentRemovesCommentTagsWhenCommentTagsExist()
{
int selectionStart = 14;
int selectionLength = 2;
textEditor.Select(selectionStart, selectionLength);
formattingStrategy.SurroundSelectionWithComment(textEditor);
string expectedText =
"<root>\r\n" +
"\t<child></child>\r\n" +
"</root>";
Assert.AreEqual(expectedText, document.Text);
}
}
}

10
src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockCaret.cs

@ -17,6 +17,7 @@ namespace XmlEditor.Tests.Utils @@ -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 @@ -51,13 +52,6 @@ namespace XmlEditor.Tests.Utils
}
}
public Location Position {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
public Location Position { get; set; }
}
}

57
src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockDocumentLine.cs

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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();
}
}
}
}

32
src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextEditor.cs

@ -21,10 +21,13 @@ namespace XmlEditor.Tests.Utils @@ -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 @@ -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 @@ -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 @@ -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 @@ -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)

46
src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextEditorOptions.cs

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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();
}
}
}
}

53
src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockCaretTests.cs

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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);
}
}
}

32
src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockDocumentLineTests.cs

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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);
}
}
}

9
src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockDocumentTests.cs

@ -19,12 +19,19 @@ namespace XmlEditor.Tests.Utils.Tests @@ -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);

38
src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockTextEditorOptionsTests.cs

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
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);
}
}
}

55
src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/MockTextEditorTests.cs

@ -112,5 +112,60 @@ namespace XmlEditor.Tests.Utils.Tests @@ -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);
}
}
}

14
src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

@ -96,10 +96,14 @@ @@ -96,10 +96,14 @@
<Compile Include="Editor\AddUserSchemaTestFixture.cs" />
<Compile Include="Editor\DefaultSchemaFileAssociationsTestFixture.cs" />
<Compile Include="Editor\DefaultXmlEditorOptionsTestFixture.cs" />
<Compile Include="Editor\ElementEndAddedAfterGreaterThanCharTypedTestFixture.cs" />
<Compile Include="Editor\EmptyXmlSchemasPanelTestFixture.cs" />
<Compile Include="Editor\ErrorWhenReadingSchemaTestFixture.cs" />
<Compile Include="Editor\ErrorWhenUserAddsSchemaTestFixture.cs" />
<Compile Include="Editor\IndentChildElementEndTagAfterNewLineTypedTestFixture.cs" />
<Compile Include="Editor\IndentLinesTests.cs" />
<Compile Include="Editor\IsEmptySchemaAssociationTests.cs" />
<Compile Include="Editor\NoElementEndAddedAfterGreaterThanCharTypedTests.cs" />
<Compile Include="Editor\NoRegisteredSchemasTestFixture.cs" />
<Compile Include="Editor\NullDefaultSchemaAssociationAddInTreeNodeTestFixture.cs" />
<Compile Include="Editor\NullXmlEditorFileExtensionsAddInTreeNodeTestFixture.cs" />
@ -111,6 +115,7 @@ @@ -111,6 +115,7 @@
<Compile Include="Editor\SchemaAssociationConvertToStringTests.cs" />
<Compile Include="Editor\SchemaAssociationFileExtensionIsCaseInsensitiveTests.cs" />
<Compile Include="Editor\SchemaAssociationsAreEqualTests.cs" />
<Compile Include="Editor\SurroundTextWithCommentBlockTestFixture.cs" />
<Compile Include="Editor\TwoRegisteredSchemasTestFixture.cs" />
<Compile Include="Editor\UserAddsOneSchemaTestFixture.cs" />
<Compile Include="Editor\UserCancelsAddSchemaDialogTestFixture.cs" />
@ -218,11 +223,13 @@ @@ -218,11 +223,13 @@
<Compile Include="Utils\MockCaret.cs" />
<Compile Include="Utils\MockCompletionListWindow.cs" />
<Compile Include="Utils\MockDocument.cs" />
<Compile Include="Utils\MockDocumentLine.cs" />
<Compile Include="Utils\MockFileSystem.cs" />
<Compile Include="Utils\MockParserService.cs" />
<Compile Include="Utils\MockSelectXmlSchemaWindow.cs" />
<Compile Include="Utils\MockTextBuffer.cs" />
<Compile Include="Utils\MockTextEditor.cs" />
<Compile Include="Utils\MockTextEditorOptions.cs" />
<Compile Include="Utils\MockXmlSchemaCompletionDataFactory.cs" />
<Compile Include="Utils\MockXmlSchemasPanel.cs" />
<Compile Include="Utils\MockXmlTreeView.cs" />
@ -231,11 +238,14 @@ @@ -231,11 +238,14 @@
<Compile Include="Utils\SchemaIncludeTestFixtureHelper.cs" />
<Compile Include="Utils\Tests\ExceptionErrorMessageAreEqualTests.cs" />
<Compile Include="Utils\Tests\FormattedErrorMessageAreEqualTests.cs" />
<Compile Include="Utils\Tests\MockCaretTests.cs" />
<Compile Include="Utils\Tests\MockDocumentLineTests.cs" />
<Compile Include="Utils\Tests\MockDocumentTests.cs" />
<Compile Include="Utils\Tests\MockFileSystemTests.cs" />
<Compile Include="Utils\Tests\MockParserServiceTests.cs" />
<Compile Include="Utils\Tests\MockSelectXmlSchemaWindowTests.cs" />
<Compile Include="Utils\Tests\MockTextBufferTests.cs" />
<Compile Include="Utils\Tests\MockTextEditorOptionsTests.cs" />
<Compile Include="Utils\Tests\MockTextEditorTests.cs" />
<Compile Include="Utils\Tests\MockXmlSchemaCompletionDataFactoryTests.cs" />
<Compile Include="Utils\Tests\MockXmlSchemasPanelTests.cs" />
@ -298,6 +308,10 @@ @@ -298,6 +308,10 @@
<Folder Include="Schema\" />
<Folder Include="Parser\" />
<Folder Include="Paths\" />
<ProjectReference Include="..\..\..\..\Libraries\AvalonEdit\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj">
<Project>{6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}</Project>
<Name>ICSharpCode.AvalonEdit</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj">
<Project>{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}</Project>
<Name>ICSharpCode.TextEditor</Name>

Loading…
Cancel
Save