Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5247 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
39 changed files with 1532 additions and 137 deletions
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
// <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 System.Collections.Generic; |
||||
using System.IO; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Completion |
||||
{ |
||||
[TestFixture] |
||||
public class AttributeCompletionWindowTestFixture |
||||
{ |
||||
MockTextEditor textEditor; |
||||
CodeCompletionKeyPressResult keyPressResult; |
||||
XmlSchemaCompletionDataCollection schemas; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
schemas = new XmlSchemaCompletionDataCollection(); |
||||
schemas.Add(new XmlSchemaCompletionData(ResourceManager.GetXsdSchema())); |
||||
|
||||
XmlEditorOptions options = new XmlEditorOptions(new Properties(), new DefaultXmlSchemaFileAssociations(new AddInTreeNode()), schemas); |
||||
options.SetSchemaFileAssociation(new XmlSchemaFileAssociation(".xsd", "http://www.w3.org/2001/XMLSchema", "xs")); |
||||
|
||||
textEditor = new MockTextEditor(); |
||||
textEditor.FileName = new FileName(@"c:\projects\test.xsd"); |
||||
textEditor.Document.Text = "<xs:schema></xs:schema>"; |
||||
|
||||
// Put cursor after the first 'a' in "<xs:schema>"
|
||||
textEditor.Caret.Offset = 10; |
||||
|
||||
XmlCodeCompletionBinding completionBinding = new XmlCodeCompletionBinding(options); |
||||
keyPressResult = completionBinding.HandleKeyPress(textEditor, ' '); |
||||
} |
||||
|
||||
[Test] |
||||
public void KeyPressResultIsCompletedAfterPressingSpaceBar() |
||||
{ |
||||
Assert.AreEqual(CodeCompletionKeyPressResult.Completed, keyPressResult); |
||||
} |
||||
|
||||
[Test] |
||||
public void CompletionListUsedInShowCompletionWindowHasItems() |
||||
{ |
||||
Assert.IsTrue(textEditor.CompletionItemsDisplayedToArray().Length > 0); |
||||
} |
||||
} |
||||
} |
||||
@ -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.Core; |
||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Completion |
||||
{ |
||||
[TestFixture] |
||||
public class CtrlSpaceAttributeValueCompletionTestFixture |
||||
{ |
||||
bool result; |
||||
MockTextEditor textEditor; |
||||
XmlCodeCompletionBinding completionBinding; |
||||
XmlEditorOptions options; |
||||
XmlSchemaCompletionData xsdSchema; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); |
||||
xsdSchema = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema()); |
||||
schemas.Add(xsdSchema); |
||||
|
||||
options = new XmlEditorOptions(new Properties(), new DefaultXmlSchemaFileAssociations(new AddInTreeNode()), schemas); |
||||
options.SetSchemaFileAssociation(new XmlSchemaFileAssociation(".xsd", "http://www.w3.org/2001/XMLSchema", "xs")); |
||||
|
||||
textEditor = new MockTextEditor(); |
||||
textEditor.FileName = new FileName(@"c:\projects\test.xsd"); |
||||
textEditor.Document.Text = "<xs:schema elementFormDefault=\"\"></xs:schema>"; |
||||
|
||||
// Put cursor inside the double quotes following the elementFormDefault attribute
|
||||
textEditor.Caret.Offset = 31; |
||||
|
||||
completionBinding = new XmlCodeCompletionBinding(options); |
||||
result = completionBinding.CtrlSpace(textEditor); |
||||
} |
||||
|
||||
[Test] |
||||
public void CtrlSpaceMethodResultIsTrueWhenCursorIsInsideAttributeValue() |
||||
{ |
||||
Assert.IsTrue(result); |
||||
} |
||||
|
||||
[Test] |
||||
public void CtrlSpaceMethodResultIsFalseWhenCursorIsOutsideAttributeValue() |
||||
{ |
||||
textEditor.Caret.Offset = 0; |
||||
Assert.IsFalse(completionBinding.CtrlSpace(textEditor)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShowCompletionWindowCalledWithCompletionItems() |
||||
{ |
||||
ICompletionItem[] items = textEditor.CompletionItemsDisplayedToArray(); |
||||
ICompletionItem[] expectedItems = GetXsdSchemaElementFormDefaultAttributeValues(); |
||||
|
||||
Assert.AreEqual(expectedItems, items); |
||||
} |
||||
|
||||
ICompletionItem[] GetXsdSchemaElementFormDefaultAttributeValues() |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("schema", "http://www.w3.org/2001/XMLSchema", "xs")); |
||||
return xsdSchema.GetAttributeValueCompletionData(path, "elementFormDefault"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ElementFormDefaultAttributeHasAttributeValues() |
||||
{ |
||||
Assert.IsTrue(GetXsdSchemaElementFormDefaultAttributeValues().Length > 0); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
// <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.Core; |
||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Completion |
||||
{ |
||||
[TestFixture] |
||||
public class CtrlSpaceNoAttributeValuesForCompletionTestFixture |
||||
{ |
||||
bool result; |
||||
MockTextEditor textEditor; |
||||
XmlCodeCompletionBinding completionBinding; |
||||
XmlEditorOptions options; |
||||
XmlSchemaCompletionData xsdSchema; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); |
||||
options = new XmlEditorOptions(new Properties(), new DefaultXmlSchemaFileAssociations(new AddInTreeNode()), schemas); |
||||
|
||||
textEditor = new MockTextEditor(); |
||||
textEditor.FileName = new FileName(@"c:\projects\test.xsd"); |
||||
textEditor.Document.Text = "<xs:schema elementFormDefault=\"\"></xs:schema>"; |
||||
|
||||
// Put cursor inside the double quotes following the elementFormDefault attribute
|
||||
textEditor.Caret.Offset = 31; |
||||
|
||||
completionBinding = new XmlCodeCompletionBinding(options); |
||||
result = completionBinding.CtrlSpace(textEditor); |
||||
} |
||||
|
||||
[Test] |
||||
public void ShowCompletionWindowIsNotCalledWhenThereAreNoCompletionItems() |
||||
{ |
||||
Assert.IsFalse(textEditor.IsShowCompletionWindowMethodCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void CtrlSpaceMethodReturnsFalse() |
||||
{ |
||||
Assert.IsFalse(result); |
||||
} |
||||
} |
||||
} |
||||
@ -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 System.Collections.Generic; |
||||
using System.IO; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Completion |
||||
{ |
||||
[TestFixture] |
||||
public class ElementCompletionWindowTestFixture |
||||
{ |
||||
MockTextEditor textEditor; |
||||
CodeCompletionKeyPressResult keyPressResult; |
||||
XmlSchemaCompletionDataCollection schemas; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
schemas = new XmlSchemaCompletionDataCollection(); |
||||
schemas.Add(new XmlSchemaCompletionData(ResourceManager.GetXhtmlStrictSchema())); |
||||
|
||||
XmlEditorOptions options = new XmlEditorOptions(new Properties(), new DefaultXmlSchemaFileAssociations(new AddInTreeNode()), schemas); |
||||
options.SetSchemaFileAssociation(new XmlSchemaFileAssociation(".xml", "http://www.w3.org/1999/xhtml")); |
||||
|
||||
textEditor = new MockTextEditor(); |
||||
textEditor.Document.Text = String.Empty; |
||||
textEditor.FileName = new FileName(@"c:\projects\test.xml"); |
||||
|
||||
textEditor.Caret.Offset = 0; |
||||
|
||||
XmlCodeCompletionBinding completionBinding = new XmlCodeCompletionBinding(options); |
||||
keyPressResult = completionBinding.HandleKeyPress(textEditor, '<'); |
||||
} |
||||
|
||||
[Test] |
||||
public void KeyPressResultIsCompletedAfterPressingEqualsSign() |
||||
{ |
||||
Assert.AreEqual(CodeCompletionKeyPressResult.Completed, keyPressResult); |
||||
} |
||||
|
||||
[Test] |
||||
public void CompletionWindowWidthIsNotSetToMatchLongestNamespaceTextWidth() |
||||
{ |
||||
Assert.AreNotEqual(double.NaN, textEditor.CompletionWindowDisplayed.Width); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
// <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 System.IO; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
|
||||
namespace XmlEditor.Tests.Completion |
||||
{ |
||||
[TestFixture] |
||||
public class GetCompletionDataProviderTestFixture |
||||
{ |
||||
XmlCompletionDataProvider completionProvider; |
||||
XmlSchemaCompletionData defaultSchemaCompletionData; |
||||
XmlEditorOptions options; |
||||
XmlSchemaCompletionData otherSchema; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); |
||||
options = new XmlEditorOptions(new Properties(), new DefaultXmlSchemaFileAssociations(new AddInTreeNode()), schemas); |
||||
|
||||
XmlSchemaFileAssociation schemaFileAssociation = new XmlSchemaFileAssociation(".xml", "http://test", "x"); |
||||
options.SetSchemaFileAssociation(schemaFileAssociation); |
||||
|
||||
string xml = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='http://test' />"; |
||||
defaultSchemaCompletionData = new XmlSchemaCompletionData(new StringReader(xml)); |
||||
schemas.Add(defaultSchemaCompletionData); |
||||
|
||||
xml = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='http://other-schema' />"; |
||||
otherSchema = new XmlSchemaCompletionData(new StringReader(xml)); |
||||
schemas.Add(otherSchema); |
||||
|
||||
completionProvider = options.GetProvider(".xml"); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlCompletionDataProviderCreatedWithCorrectDefaultNamespacePrefix() |
||||
{ |
||||
Assert.AreEqual("x", completionProvider.DefaultNamespacePrefix); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlCompletionDataProviderCreatedWithCorrectDefaultSchemaCompletionData() |
||||
{ |
||||
Assert.AreSame(defaultSchemaCompletionData, completionProvider.DefaultSchemaCompletionData); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlCompletionDataProviderCreatedWithSchemasCollection() |
||||
{ |
||||
Assert.AreSame(otherSchema, completionProvider.FindSchema("http://other-schema")); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,61 @@
@@ -0,0 +1,61 @@
|
||||
// <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 System.Collections.Generic; |
||||
using System.IO; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Completion |
||||
{ |
||||
[TestFixture] |
||||
public class NamespaceCompletionWindowTestFixture : NamespaceCompletionWindowTestFixtureBase |
||||
{ |
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
base.InitBase(); |
||||
|
||||
XmlCodeCompletionBinding completionBinding = new XmlCodeCompletionBinding(options); |
||||
keyPressResult = completionBinding.HandleKeyPress(textEditor, '='); |
||||
} |
||||
|
||||
[Test] |
||||
public void KeyPressResultIsCompletedAfterPressingEqualsSign() |
||||
{ |
||||
Assert.AreEqual(CodeCompletionKeyPressResult.Completed, keyPressResult); |
||||
} |
||||
|
||||
[Test] |
||||
public void CompletionWindowWidthSetToMatchLongestNamespaceTextWidth() |
||||
{ |
||||
Assert.AreEqual(double.NaN, textEditor.CompletionWindowDisplayed.Width); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExpectedCompletionDataItems() |
||||
{ |
||||
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection(); |
||||
expectedItems.Add(new XmlCompletionItem("a", XmlCompletionDataType.NamespaceUri)); |
||||
expectedItems.Add(new XmlCompletionItem("b", XmlCompletionDataType.NamespaceUri)); |
||||
expectedItems.Add(new XmlCompletionItem("c", XmlCompletionDataType.NamespaceUri)); |
||||
|
||||
Assert.AreEqual(expectedItems.ToArray(), textEditor.CompletionItemsDisplayedToArray()); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextEditorDocumentGetTextCalledWithOffsetAndLength() |
||||
{ |
||||
TextSection expectedTextSection = new TextSection(0, 8); |
||||
Assert.AreEqual(expectedTextSection, textEditor.MockDocument.GetTextSectionUsedWithGetTextMethod()); |
||||
} |
||||
} |
||||
} |
||||
@ -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 System.Collections.Generic; |
||||
using System.IO; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Completion |
||||
{ |
||||
public class NamespaceCompletionWindowTestFixtureBase |
||||
{ |
||||
protected MockTextEditor textEditor; |
||||
protected CodeCompletionKeyPressResult keyPressResult; |
||||
protected XmlSchemaCompletionDataCollection schemas; |
||||
protected XmlEditorOptions options; |
||||
|
||||
protected void InitBase() |
||||
{ |
||||
schemas = new XmlSchemaCompletionDataCollection(); |
||||
AddSchemas(); |
||||
|
||||
options = new XmlEditorOptions(new Properties(), new DefaultXmlSchemaFileAssociations(new AddInTreeNode()), schemas); |
||||
|
||||
textEditor = new MockTextEditor(); |
||||
textEditor.Document.Text = "<a xmlns></a>"; |
||||
textEditor.FileName = new FileName(@"c:\projects\test.xml"); |
||||
|
||||
// Put caret just after "xmlns".
|
||||
textEditor.Caret.Offset = 8; |
||||
} |
||||
|
||||
void AddSchemas() |
||||
{ |
||||
string xml = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='c' />"; |
||||
schemas.Add(new XmlSchemaCompletionData(new StringReader(xml))); |
||||
|
||||
xml = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='b' />"; |
||||
schemas.Add(new XmlSchemaCompletionData(new StringReader(xml))); |
||||
|
||||
xml = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='a' />"; |
||||
schemas.Add(new XmlSchemaCompletionData(new StringReader(xml))); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
// <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.XmlEditor; |
||||
using NUnit.Framework; |
||||
|
||||
namespace XmlEditor.Tests.Completion |
||||
{ |
||||
[TestFixture] |
||||
public class NoCompletionItemsTestFixture : NamespaceCompletionWindowTestFixtureBase |
||||
{ |
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
base.InitBase(); |
||||
|
||||
schemas.Clear(); |
||||
|
||||
XmlCodeCompletionBinding completionBinding = new XmlCodeCompletionBinding(options); |
||||
keyPressResult = completionBinding.HandleKeyPress(textEditor, '='); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextEditorShowCompletionWindowNotCalledWhenNoCompletionItems() |
||||
{ |
||||
Assert.IsFalse(textEditor.IsShowCompletionWindowMethodCalled); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
// <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 System.Collections.Generic; |
||||
using System.IO; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Completion |
||||
{ |
||||
[TestFixture] |
||||
public class NullCompletionItemsReturnedTestFixture |
||||
{ |
||||
MockTextEditor textEditor; |
||||
XmlSchemaCompletionDataCollection schemas; |
||||
XmlCodeCompletionBinding completionBinding; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
schemas = new XmlSchemaCompletionDataCollection(); |
||||
|
||||
XmlEditorOptions options = new XmlEditorOptions(new Properties(), new DefaultXmlSchemaFileAssociations(new AddInTreeNode()), schemas); |
||||
|
||||
textEditor = new MockTextEditor(); |
||||
textEditor.FileName = new FileName(@"c:\projects\test.xsd"); |
||||
textEditor.Document.Text = ""; |
||||
textEditor.Caret.Offset = 0; |
||||
|
||||
completionBinding = new XmlCodeCompletionBinding(options); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullReferenceExceptionNotThrownWhenCallingHandleKeyPress() |
||||
{ |
||||
Assert.DoesNotThrow(delegate { completionBinding.HandleKeyPress(textEditor, '='); } ); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
// <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 System.Collections.Generic; |
||||
using System.IO; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Completion |
||||
{ |
||||
[TestFixture] |
||||
public class ShowCompletionWindowReturnsNullTestFixture : NamespaceCompletionWindowTestFixtureBase |
||||
{ |
||||
[Test] |
||||
public void CompletionBindingHandleKeyPressDoesNotThrowNullReferenceException() |
||||
{ |
||||
base.InitBase(); |
||||
|
||||
textEditor.ShowCompletionWindowReturnsNull = true; |
||||
|
||||
XmlCodeCompletionBinding completionBinding = new XmlCodeCompletionBinding(options); |
||||
Assert.DoesNotThrow(delegate { keyPressResult = completionBinding.HandleKeyPress(textEditor, '='); }); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
// <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 System.Collections.Generic; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
|
||||
namespace XmlEditor.Tests.Completion |
||||
{ |
||||
[TestFixture] |
||||
public class XmlCompletionItemCollectionTests |
||||
{ |
||||
[Test] |
||||
public void CollectionToArrayReturnsExpectedArray() |
||||
{ |
||||
XmlCompletionItem firstItem = new XmlCompletionItem("text", "desc", XmlCompletionDataType.XmlElement); |
||||
XmlCompletionItem secondItem = new XmlCompletionItem("text2", "desc", XmlCompletionDataType.XmlAttribute); |
||||
|
||||
List<XmlCompletionItem> items = new List<XmlCompletionItem>(); |
||||
items.Add(firstItem); |
||||
items.Add(secondItem); |
||||
|
||||
XmlCompletionItemCollection itemCollection = new XmlCompletionItemCollection(); |
||||
itemCollection.Add(firstItem); |
||||
itemCollection.Add(secondItem); |
||||
|
||||
Assert.AreEqual(items.ToArray(), itemCollection.ToArray()); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
// <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.XmlEditor; |
||||
using NUnit.Framework; |
||||
|
||||
namespace XmlEditor.Tests.Completion |
||||
{ |
||||
[TestFixture] |
||||
public class XmlCompletionItemIsEqualTests |
||||
{ |
||||
[Test] |
||||
public void TwoItemsAreEqualIfTextAndXmlCompletionDataTypeAreEqual() |
||||
{ |
||||
XmlCompletionItem lhs = new XmlCompletionItem("text", "description", XmlCompletionDataType.XmlElement); |
||||
XmlCompletionItem rhs = new XmlCompletionItem("text", "description", XmlCompletionDataType.XmlElement); |
||||
|
||||
Assert.IsTrue(lhs.Equals(rhs)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoItemsAreNotEqualIfTextIsDifferent() |
||||
{ |
||||
XmlCompletionItem lhs = new XmlCompletionItem("text", "description", XmlCompletionDataType.XmlElement); |
||||
XmlCompletionItem rhs = new XmlCompletionItem("different-text", "description", XmlCompletionDataType.XmlElement); |
||||
|
||||
Assert.IsFalse(lhs.Equals(rhs)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoItemsAreNotEqualIfXmlCompletionDataTypeIsDifferent() |
||||
{ |
||||
XmlCompletionItem lhs = new XmlCompletionItem("text", "description", XmlCompletionDataType.XmlElement); |
||||
XmlCompletionItem rhs = new XmlCompletionItem("text", "description", XmlCompletionDataType.XmlAttribute); |
||||
|
||||
Assert.IsFalse(lhs.Equals(rhs)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullIsNotEqualToCompletionItem() |
||||
{ |
||||
XmlCompletionItem lhs = new XmlCompletionItem("text"); |
||||
Assert.IsFalse(lhs.Equals(null)); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,63 @@
@@ -0,0 +1,63 @@
|
||||
// <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 ICSharpCode.SharpDevelop.Editor; |
||||
|
||||
namespace XmlEditor.Tests.Utils |
||||
{ |
||||
public class MockCaret : ITextEditorCaret |
||||
{ |
||||
int offset = -1; |
||||
|
||||
public MockCaret() |
||||
{ |
||||
} |
||||
|
||||
public event EventHandler PositionChanged; |
||||
|
||||
protected virtual void OnPositionChanged(EventArgs e) |
||||
{ |
||||
if (PositionChanged != null) { |
||||
PositionChanged(this, e); |
||||
} |
||||
} |
||||
|
||||
public int Offset { |
||||
get { return offset; } |
||||
set { offset = value; } |
||||
} |
||||
|
||||
public int Line { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public int Column { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public Location Position { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,85 @@
@@ -0,0 +1,85 @@
|
||||
// <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.CodeCompletion; |
||||
|
||||
namespace XmlEditor.Tests.Utils |
||||
{ |
||||
public class MockCompletionListWindow : ICompletionListWindow |
||||
{ |
||||
double width = 0.0; |
||||
|
||||
public MockCompletionListWindow() |
||||
{ |
||||
} |
||||
|
||||
public event EventHandler Closed; |
||||
|
||||
protected virtual void OnClosed(EventArgs e) |
||||
{ |
||||
if (Closed != null) { |
||||
Closed(this, e); |
||||
} |
||||
} |
||||
|
||||
public ICompletionItem SelectedItem { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public double Width { |
||||
get { return width; } |
||||
set { width = value; } |
||||
} |
||||
|
||||
public double Height { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool CloseAutomatically { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public int StartOffset { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public int EndOffset { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public void Close() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,148 @@
@@ -0,0 +1,148 @@
|
||||
// <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 System.IO; |
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
|
||||
namespace XmlEditor.Tests.Utils |
||||
{ |
||||
public class MockDocument : IDocument |
||||
{ |
||||
string text = String.Empty; |
||||
TextSection textSectionUsedWithGetTextMethod; |
||||
|
||||
public MockDocument() |
||||
{ |
||||
} |
||||
|
||||
public event EventHandler TextChanged; |
||||
|
||||
protected virtual void OnTextChanged(EventArgs e) |
||||
{ |
||||
if (TextChanged != null) { |
||||
TextChanged(this, e); |
||||
} |
||||
} |
||||
|
||||
public string Text { |
||||
get { return text; } |
||||
set { text = value; } |
||||
} |
||||
|
||||
public int TotalNumberOfLines { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ITextBufferVersion Version { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public int TextLength { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IDocumentLine GetLine(int lineNumber) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public IDocumentLine GetLineForOffset(int offset) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public int PositionToOffset(int line, int column) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public Location OffsetToPosition(int offset) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void Insert(int offset, string text) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void Remove(int offset, int length) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void Replace(int offset, int length, string newText) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void StartUndoableAction() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void EndUndoableAction() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public IDisposable OpenUndoGroup() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public ITextAnchor CreateAnchor(int offset) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public ITextBuffer CreateSnapshot() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public ITextBuffer CreateSnapshot(int offset, int length) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public TextReader CreateReader() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public char GetCharAt(int offset) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public string GetText(int offset, int length) |
||||
{ |
||||
textSectionUsedWithGetTextMethod = new TextSection(offset, length); |
||||
return text.Substring(offset, length); |
||||
} |
||||
|
||||
public TextSection GetTextSectionUsedWithGetTextMethod() |
||||
{ |
||||
return textSectionUsedWithGetTextMethod; |
||||
} |
||||
|
||||
public object GetService(Type serviceType) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,188 @@
@@ -0,0 +1,188 @@
|
||||
// <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 System.Collections.Generic; |
||||
using System.Windows.Input; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
|
||||
namespace XmlEditor.Tests.Utils |
||||
{ |
||||
public class MockTextEditor : ITextEditor |
||||
{ |
||||
MockCompletionListWindow completionWindowDisplayed; |
||||
ICompletionItemList completionItemsDisplayed; |
||||
MockCaret caret = new MockCaret(); |
||||
MockDocument document = new MockDocument(); |
||||
FileName fileName; |
||||
bool showCompletionWindowReturnsNull; |
||||
bool showCompletionWindowMethodCalled; |
||||
|
||||
public MockTextEditor() |
||||
{ |
||||
} |
||||
|
||||
public event EventHandler SelectionChanged; |
||||
|
||||
protected virtual void OnSelectionChanged(EventArgs e) |
||||
{ |
||||
if (SelectionChanged != null) { |
||||
SelectionChanged(this, e); |
||||
} |
||||
} |
||||
|
||||
public event KeyEventHandler KeyPress; |
||||
|
||||
protected virtual void OnKeyPress(KeyEventArgs e) |
||||
{ |
||||
if (KeyPress != null) { |
||||
KeyPress(this, e); |
||||
} |
||||
} |
||||
|
||||
public ITextEditor PrimaryView { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IDocument Document { |
||||
get { return document; } |
||||
} |
||||
|
||||
public MockDocument MockDocument { |
||||
get { return document; } |
||||
} |
||||
|
||||
public ITextEditorCaret Caret { |
||||
get { return caret; } |
||||
} |
||||
|
||||
public ITextEditorOptions Options { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ILanguageBinding Language { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public int SelectionStart { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public int SelectionLength { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public string SelectedText { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public FileName FileName { |
||||
get { return fileName; } |
||||
set { fileName = value; } |
||||
} |
||||
|
||||
public ICompletionListWindow ActiveCompletionWindow { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IInsightWindow ActiveInsightWindow { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public void Select(int selectionStart, int selectionLength) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void JumpTo(int line, int column) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public ICompletionListWindow ShowCompletionWindow(ICompletionItemList data) |
||||
{ |
||||
completionItemsDisplayed = data; |
||||
showCompletionWindowMethodCalled = true; |
||||
|
||||
if (showCompletionWindowReturnsNull) { |
||||
completionWindowDisplayed = null; |
||||
} else { |
||||
completionWindowDisplayed = new MockCompletionListWindow(); |
||||
} |
||||
return completionWindowDisplayed; |
||||
} |
||||
|
||||
public bool IsShowCompletionWindowMethodCalled { |
||||
get { return showCompletionWindowMethodCalled; } |
||||
} |
||||
|
||||
public bool ShowCompletionWindowReturnsNull { |
||||
get { return showCompletionWindowReturnsNull; } |
||||
set { showCompletionWindowReturnsNull = value; } |
||||
} |
||||
|
||||
public MockCompletionListWindow CompletionWindowDisplayed { |
||||
get { return completionWindowDisplayed; } |
||||
} |
||||
|
||||
public ICompletionItemList CompletionItemsDisplayed { |
||||
get { return completionItemsDisplayed; } |
||||
} |
||||
|
||||
public ICompletionItem[] CompletionItemsDisplayedToArray() |
||||
{ |
||||
List<ICompletionItem> items = new List<ICompletionItem>(); |
||||
foreach (ICompletionItem item in completionItemsDisplayed.Items) { |
||||
items.Add(item); |
||||
} |
||||
return items.ToArray(); |
||||
} |
||||
|
||||
public IInsightWindow ShowInsightWindow(IEnumerable<IInsightItem> items) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public IEnumerable<ICompletionItem> GetSnippets() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void ShowCompletionWindow(ICompletionDataProvider provider, char ch) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object GetService(Type serviceType) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
// <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 System.Collections.Generic; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Utils.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class MockDocumentTests |
||||
{ |
||||
[Test] |
||||
public void TextEditorDocumentCanGetOffsetAndLengthUsedAsParametersInGetTextMethod() |
||||
{ |
||||
TextSection expectedSection = new TextSection(0, 5); |
||||
|
||||
MockDocument document = new MockDocument(); |
||||
document.Text = "abcdefghi"; |
||||
document.GetText(0, 5); |
||||
|
||||
Assert.AreEqual(expectedSection, document.GetTextSectionUsedWithGetTextMethod()); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextEditorDocumentGetTextReturnsCorrectSectionOfText() |
||||
{ |
||||
TextSection expectedSection = new TextSection(0, 5); |
||||
|
||||
MockDocument document = new MockDocument(); |
||||
document.Text = "abcdefghi"; |
||||
|
||||
Assert.AreEqual("def", document.GetText(3, 3)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextSectionWithSameOffsetAndLengthAreEqual() |
||||
{ |
||||
TextSection lhs = new TextSection(0, 1); |
||||
TextSection rhs = new TextSection(0, 1); |
||||
|
||||
Assert.IsTrue(lhs.Equals(rhs)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextSectionWithDifferentOffsetAreNotEqual() |
||||
{ |
||||
TextSection lhs = new TextSection(0, 1); |
||||
TextSection rhs = new TextSection(1, 1); |
||||
|
||||
Assert.IsFalse(lhs.Equals(rhs)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextSectionWithDifferentLengthAreNotEqual() |
||||
{ |
||||
TextSection lhs = new TextSection(0, 15); |
||||
TextSection rhs = new TextSection(0, 1); |
||||
|
||||
Assert.IsFalse(lhs.Equals(rhs)); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,116 @@
@@ -0,0 +1,116 @@
|
||||
// <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 System.Collections.Generic; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Utils.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class MockTextEditorTests |
||||
{ |
||||
MockTextEditor editor; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
editor = new MockTextEditor(); |
||||
} |
||||
|
||||
[Test] |
||||
public void CanCheckCompletionWindowFromShowCompletionHasWidthPropertyModified() |
||||
{ |
||||
XmlCompletionItemList list = new XmlCompletionItemList(); |
||||
list.Items.Add(new XmlCompletionItem("a")); |
||||
ICompletionListWindow window = editor.ShowCompletionWindow(list); |
||||
window.Width = double.NaN; |
||||
|
||||
Assert.AreEqual(double.NaN, editor.CompletionWindowDisplayed.Width); |
||||
} |
||||
|
||||
[Test] |
||||
public void CanGetCompletionItemsUsedAsShowCompletionMethodParameters() |
||||
{ |
||||
XmlCompletionItemList list = new XmlCompletionItemList(); |
||||
list.Items.Add(new XmlCompletionItem("a")); |
||||
editor.ShowCompletionWindow(list); |
||||
|
||||
Assert.AreSame(list, editor.CompletionItemsDisplayed); |
||||
} |
||||
|
||||
[Test] |
||||
public void CanConvertCompletionItemsUsedAsShowCompletionMethodParametersToArray() |
||||
{ |
||||
XmlCompletionItem item = new XmlCompletionItem("a"); |
||||
List<XmlCompletionItem> expectedArray = new List<XmlCompletionItem>(); |
||||
expectedArray.Add(item); |
||||
|
||||
XmlCompletionItemList list = new XmlCompletionItemList(); |
||||
list.Items.Add(item); |
||||
editor.ShowCompletionWindow(list); |
||||
|
||||
Assert.AreEqual(expectedArray.ToArray(), editor.CompletionItemsDisplayedToArray()); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextEditorDocumentCanGetAndSetText() |
||||
{ |
||||
editor.Document.Text = "test"; |
||||
Assert.AreEqual("test", editor.Document.Text); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextEditorCaretCanGetAndSetCaretOffset() |
||||
{ |
||||
editor.Caret.Offset = 5; |
||||
Assert.AreEqual(5, editor.Caret.Offset); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextEditorMockDocumentPropertyIsSameAsTextEditorDocumentProperty() |
||||
{ |
||||
Assert.AreSame(editor.MockDocument, editor.Document); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextEditorCanGetAndSetFileName() |
||||
{ |
||||
editor.FileName = new FileName(@"c:\projects\a.xml"); |
||||
Assert.AreEqual(@"c:\projects\a.xml", editor.FileName.ToString()); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextEditorShowCompletionListReturnsNullWhenConfigured() |
||||
{ |
||||
XmlCompletionItemList list = new XmlCompletionItemList(); |
||||
list.Items.Add(new XmlCompletionItem("a")); |
||||
|
||||
editor.ShowCompletionWindowReturnsNull = true; |
||||
|
||||
Assert.IsNull(editor.ShowCompletionWindow(list)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextEditorShowCompletionListIsCalledReturnsTrueIfShowCompletionListMethodReturnsNullWindow() |
||||
{ |
||||
TextEditorShowCompletionListReturnsNullWhenConfigured(); |
||||
Assert.IsTrue(editor.IsShowCompletionWindowMethodCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsShowCompletionWindowMethodCalledReturnsFalseByDefault() |
||||
{ |
||||
Assert.IsFalse(editor.IsShowCompletionWindowMethodCalled); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
// <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; |
||||
|
||||
namespace XmlEditor.Tests.Utils |
||||
{ |
||||
public class TextSection |
||||
{ |
||||
int offset; |
||||
int length; |
||||
|
||||
public TextSection(int offset, int length) |
||||
{ |
||||
this.offset = offset; |
||||
this.length = length; |
||||
} |
||||
|
||||
public override bool Equals(object obj) |
||||
{ |
||||
TextSection rhs = obj as TextSection; |
||||
return (rhs.offset == offset) && (rhs.length == length); |
||||
} |
||||
|
||||
public override int GetHashCode() |
||||
{ |
||||
return base.GetHashCode(); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue