Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5336 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
58 changed files with 2302 additions and 608 deletions
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
// <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 ICSharpCode.XmlEditor |
||||
{ |
||||
public class SelectedXmlElement |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
string selectedAttribute = String.Empty; |
||||
string selectedAttributeValue = String.Empty; |
||||
|
||||
public SelectedXmlElement(ITextEditor textEditor) |
||||
: this(textEditor.Document.Text, textEditor.Caret.Offset) |
||||
{ |
||||
} |
||||
|
||||
public SelectedXmlElement(string xml, int index) |
||||
{ |
||||
FindSelectedElement(xml, index); |
||||
FindSelectedAttribute(xml, index); |
||||
FindSelectedAttributeValue(xml, index); |
||||
} |
||||
|
||||
void FindSelectedElement(string xml, int index) |
||||
{ |
||||
path = XmlParser.GetActiveElementStartPathAtIndex(xml, index); |
||||
} |
||||
|
||||
void FindSelectedAttribute(string xml, int index) |
||||
{ |
||||
selectedAttribute = XmlParser.GetAttributeNameAtIndex(xml, index); |
||||
} |
||||
|
||||
void FindSelectedAttributeValue(string xml, int index) |
||||
{ |
||||
selectedAttributeValue = XmlParser.GetAttributeValueAtIndex(xml, index); |
||||
} |
||||
|
||||
public XmlElementPath Path { |
||||
get { return path; } |
||||
} |
||||
|
||||
public string SelectedAttribute { |
||||
get { return selectedAttribute; } |
||||
} |
||||
|
||||
public bool HasSelectedAttribute { |
||||
get { return selectedAttribute.Length > 0; } |
||||
} |
||||
|
||||
public string SelectedAttributeValue { |
||||
get { return selectedAttributeValue; } |
||||
} |
||||
|
||||
public bool HasSelectedAttributeValue { |
||||
get { return selectedAttributeValue.Length > 0; } |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
// <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 System.Xml; |
||||
using System.Xml.XPath; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
public class XPathQuery |
||||
{ |
||||
string xml; |
||||
XmlNamespaceCollection namespaces; |
||||
|
||||
public XPathQuery(string xml) |
||||
: this(xml, new XmlNamespaceCollection()) |
||||
{ |
||||
} |
||||
|
||||
public XPathQuery(ITextEditor textEditor, XmlNamespaceCollection namespaces) |
||||
: this(textEditor.Document.Text, namespaces) |
||||
{ |
||||
} |
||||
|
||||
public XPathQuery(string xml, XmlNamespaceCollection namespaces) |
||||
{ |
||||
this.xml = xml; |
||||
this.namespaces = namespaces; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Finds the xml nodes that match the specified xpath.
|
||||
/// </summary>
|
||||
/// <returns>An array of XPathNodeMatch items. These include line number
|
||||
/// and line position information aswell as the node found.</returns>
|
||||
public XPathNodeMatch[] FindNodes(string xpath) |
||||
{ |
||||
XmlTextReader xmlReader = new XmlTextReader(new StringReader(xml)); |
||||
xmlReader.XmlResolver = null; |
||||
XPathDocument doc = new XPathDocument(xmlReader); |
||||
XPathNavigator navigator = doc.CreateNavigator(); |
||||
|
||||
// Add namespaces.
|
||||
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(navigator.NameTable); |
||||
foreach (XmlNamespace xmlNamespace in namespaces) { |
||||
namespaceManager.AddNamespace(xmlNamespace.Prefix, xmlNamespace.Name); |
||||
} |
||||
|
||||
// Run the xpath query.
|
||||
XPathNodeIterator iterator = navigator.Select(xpath, namespaceManager); |
||||
|
||||
List<XPathNodeMatch> nodes = new List<XPathNodeMatch>(); |
||||
while (iterator.MoveNext()) { |
||||
nodes.Add(new XPathNodeMatch(iterator.Current)); |
||||
} |
||||
return nodes.ToArray(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,214 @@
@@ -0,0 +1,214 @@
|
||||
// <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.Xml; |
||||
using System.Xml.Schema; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
public class XmlSchemaDefinition |
||||
{ |
||||
public const string XmlSchemaNamespace = "http://www.w3.org/2001/XMLSchema"; |
||||
|
||||
XmlSchemaCompletionCollection schemas; |
||||
XmlSchemaCompletion currentSchema; |
||||
SelectedXmlElement selectedElement; |
||||
|
||||
public XmlSchemaDefinition(XmlSchemaCompletionCollection schemas, XmlSchemaCompletion currentSchema) |
||||
{ |
||||
this.schemas = schemas; |
||||
this.currentSchema = currentSchema; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified namespace is actually the W3C namespace for
|
||||
/// XSD files.
|
||||
/// </summary>
|
||||
public static bool IsXmlSchemaNamespace(string schemaNamespace) |
||||
{ |
||||
return schemaNamespace == XmlSchemaNamespace; |
||||
} |
||||
|
||||
public XmlSchemaObjectLocation GetSelectedSchemaObjectLocation(string xml, int index) |
||||
{ |
||||
XmlSchemaObject schemaObject = GetSelectedSchemaObject(xml, index); |
||||
return new XmlSchemaObjectLocation(schemaObject); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the XmlSchemaObject that defines the currently selected xml element or
|
||||
/// attribute.
|
||||
/// </summary>
|
||||
/// <param name="text">The complete xml text.</param>
|
||||
/// <param name="index">The current cursor index.</param>
|
||||
/// <param name="currentSchemaCompletionData">This is the schema completion data for the
|
||||
/// schema currently being displayed. This can be null if the document is
|
||||
/// not a schema.</param>
|
||||
public XmlSchemaObject GetSelectedSchemaObject(string xml, int index) |
||||
{ |
||||
FindSelectedElement(xml, index); |
||||
return GetSelectedSchemaObject(); |
||||
} |
||||
|
||||
XmlSchemaObject GetSelectedSchemaObject() |
||||
{ |
||||
XmlSchemaCompletion schemaForSelectedElement = FindSchemaForSelectedElement(); |
||||
if (schemaForSelectedElement == null) { |
||||
return null; |
||||
} |
||||
|
||||
XmlSchemaElement selectedSchemaElement = FindSchemaObjectForSelectedElement(schemaForSelectedElement); |
||||
if (selectedSchemaElement == null) { |
||||
return null; |
||||
} |
||||
|
||||
if (selectedElement.HasSelectedAttribute) { |
||||
XmlSchemaAttribute attribute = FindSchemaObjectForSelectedAttribute(schemaForSelectedElement, selectedSchemaElement); |
||||
if (attribute == null) { |
||||
return selectedSchemaElement; |
||||
} |
||||
|
||||
if (selectedElement.HasSelectedAttributeValue) { |
||||
XmlSchemaObject schemaObject = FindSchemaObjectReferencedByAttributeValue(selectedSchemaElement, attribute); |
||||
if (schemaObject != null) { |
||||
return schemaObject; |
||||
} |
||||
} |
||||
return attribute; |
||||
} |
||||
return selectedSchemaElement; |
||||
} |
||||
|
||||
void FindSelectedElement(string xml, int index) |
||||
{ |
||||
selectedElement = new SelectedXmlElement(xml, index); |
||||
} |
||||
|
||||
XmlSchemaCompletion FindSchemaForSelectedElement() |
||||
{ |
||||
return schemas[selectedElement.Path.GetRootNamespace()]; |
||||
} |
||||
|
||||
XmlSchemaElement FindSchemaObjectForSelectedElement(XmlSchemaCompletion schemaForSelectedElement) |
||||
{ |
||||
return schemaForSelectedElement.FindElement(selectedElement.Path); |
||||
} |
||||
|
||||
XmlSchemaAttribute FindSchemaObjectForSelectedAttribute(XmlSchemaCompletion schemaForSelectedElement, XmlSchemaElement selectedSchemaElement) |
||||
{ |
||||
return schemaForSelectedElement.FindAttribute(selectedSchemaElement, selectedElement.SelectedAttribute); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// If the attribute value found references another item in the schema
|
||||
/// return this instead of the attribute schema object. For example, if the
|
||||
/// user can select the attribute value and the code will work out the schema object pointed to by the ref
|
||||
/// or type attribute:
|
||||
///
|
||||
/// xs:element ref="ref-name"
|
||||
/// xs:attribute type="type-name"
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The <paramref name="attribute"/> if no schema object was referenced.
|
||||
/// </returns>
|
||||
XmlSchemaObject FindSchemaObjectReferencedByAttributeValue(XmlSchemaElement element, XmlSchemaAttribute attribute) |
||||
{ |
||||
if ((currentSchema != null) && IsXmlSchemaNamespaceElement(element)) { |
||||
return GetSchemaObjectReferencedByAttributeValue(element.Name, attribute.Name); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
XmlSchemaObject GetSchemaObjectReferencedByAttributeValue(string elementName, string attributeName) |
||||
{ |
||||
if (attributeName == "ref") { |
||||
return FindSchemaObjectReference(selectedElement.SelectedAttributeValue, elementName); |
||||
} else if (attributeName == "type") { |
||||
return FindSchemaObjectType(selectedElement.SelectedAttributeValue, elementName); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Attempts to locate the reference name in the specified schema.
|
||||
/// </summary>
|
||||
/// <param name="name">The reference to look up.</param>
|
||||
/// <param name="schemaCompletionData">The schema completion data to use to
|
||||
/// find the reference.</param>
|
||||
/// <param name="elementName">The element to determine what sort of reference it is
|
||||
/// (e.g. group, attribute, element).</param>
|
||||
/// <returns><see langword="null"/> if no match can be found.</returns>
|
||||
XmlSchemaObject FindSchemaObjectReference(string name, string elementName) |
||||
{ |
||||
QualifiedName qualifiedName = currentSchema.CreateQualifiedName(name); |
||||
XmlSchemaCompletion schema = GetSchemaForQualifiedName(qualifiedName); |
||||
return FindSchemaObjectReference(qualifiedName, elementName, schema); |
||||
} |
||||
|
||||
XmlSchemaObject FindSchemaObjectReference(QualifiedName qualifiedName, string elementName, XmlSchemaCompletion schema) |
||||
{ |
||||
switch (elementName) { |
||||
case "element": |
||||
return schema.FindRootElement(qualifiedName); |
||||
case "attribute": |
||||
return schema.FindAttribute(qualifiedName.Name); |
||||
case "group": |
||||
return schema.FindGroup(qualifiedName.Name); |
||||
case "attributeGroup": |
||||
return schema.FindAttributeGroup(qualifiedName.Name); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
XmlSchemaCompletion GetSchemaForQualifiedName(QualifiedName name) |
||||
{ |
||||
XmlSchemaCompletion schema = schemas[name.Namespace]; |
||||
if (schema != null) { |
||||
return schema; |
||||
} |
||||
return currentSchema; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Attempts to locate the type name in the specified schema.
|
||||
/// </summary>
|
||||
/// <param name="name">The type to look up.</param>
|
||||
/// <param name="elementName">The element to determine what sort of type it is
|
||||
/// (e.g. group, attribute, element).</param>
|
||||
/// <returns><see langword="null"/> if no match can be found.</returns>
|
||||
XmlSchemaObject FindSchemaObjectType(string name, string elementName) |
||||
{ |
||||
QualifiedName qualifiedName = currentSchema.CreateQualifiedName(name); |
||||
XmlSchemaCompletion schema = GetSchemaForQualifiedName(qualifiedName); |
||||
return FindSchemaObjectType(qualifiedName, elementName, schema); |
||||
} |
||||
|
||||
XmlSchemaObject FindSchemaObjectType(QualifiedName qualifiedName, string elementName, XmlSchemaCompletion schema) |
||||
{ |
||||
switch (elementName) { |
||||
case "element": |
||||
return schema.FindComplexType(qualifiedName); |
||||
case "attribute": |
||||
return schema.FindSimpleType(qualifiedName.Name); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Checks whether the element belongs to the XSD namespace.
|
||||
/// </summary>
|
||||
static bool IsXmlSchemaNamespaceElement(XmlSchemaElement element) |
||||
{ |
||||
XmlQualifiedName qualifiedName = element.QualifiedName; |
||||
if (qualifiedName != null) { |
||||
return IsXmlSchemaNamespace(qualifiedName.Namespace); |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
// <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; |
||||
using System.Xml.Schema; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
public class XmlSchemaObjectLocation |
||||
{ |
||||
string fileName = String.Empty; |
||||
int lineNumber = -1; |
||||
int linePosition = -1; |
||||
|
||||
public XmlSchemaObjectLocation(XmlSchemaObject schemaObject) |
||||
{ |
||||
if (schemaObject != null) { |
||||
ReadLocation(schemaObject); |
||||
} |
||||
} |
||||
|
||||
void ReadLocation(XmlSchemaObject schemaObject) |
||||
{ |
||||
if (schemaObject.SourceUri != null) { |
||||
fileName = schemaObject.SourceUri.Replace("file:///", String.Empty); |
||||
} |
||||
lineNumber = schemaObject.LineNumber; |
||||
linePosition = schemaObject.LinePosition; |
||||
} |
||||
|
||||
public string FileName { |
||||
get { return fileName; } |
||||
} |
||||
|
||||
public int LineNumber { |
||||
get { return lineNumber; } |
||||
} |
||||
|
||||
public int LinePosition { |
||||
get { return linePosition; } |
||||
} |
||||
|
||||
public void JumpToFilePosition() |
||||
{ |
||||
if (!String.IsNullOrEmpty(fileName)) { |
||||
JumpToFilePosition(fileName, lineNumber, linePosition); |
||||
} |
||||
} |
||||
|
||||
protected virtual void JumpToFilePosition(string fileName, int line, int column) |
||||
{ |
||||
FileService.JumpToFilePosition(fileName, line, column); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
// <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; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.FindSchemaObject |
||||
{ |
||||
[TestFixture] |
||||
public class FindSelectedAttributeInTextEditorTestFixture |
||||
{ |
||||
SelectedXmlElement selectedElement; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
string xml = "<root attribute1=''></root>"; |
||||
int index = 10; |
||||
|
||||
MockTextEditor textEditor = new MockTextEditor(); |
||||
textEditor.Document.Text = xml; |
||||
textEditor.Caret.Offset = index; |
||||
|
||||
selectedElement = new SelectedXmlElement(textEditor); |
||||
} |
||||
|
||||
[Test] |
||||
public void ElementPathContainsSingleRootElement() |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.AddElement(new QualifiedName("root", String.Empty)); |
||||
|
||||
Assert.AreEqual(path, selectedElement.Path); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasSelectedAttribute() |
||||
{ |
||||
Assert.IsTrue(selectedElement.HasSelectedAttribute); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasNoSelectedAttributeValue() |
||||
{ |
||||
Assert.IsFalse(selectedElement.HasSelectedAttributeValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectedAttributeIsFirstAttribute() |
||||
{ |
||||
Assert.AreEqual("attribute1", selectedElement.SelectedAttribute); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectedAttributeValueIsEmptyString() |
||||
{ |
||||
Assert.AreEqual(String.Empty, selectedElement.SelectedAttributeValue); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
// <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; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.FindSchemaObject |
||||
{ |
||||
[TestFixture] |
||||
public class FindSelectedAttributeValueInTextEditorTestFixture |
||||
{ |
||||
SelectedXmlElement selectedElement; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
string xml = "<parent a='attributeValue'></parent>"; |
||||
int index = 15; |
||||
|
||||
MockTextEditor textEditor = new MockTextEditor(); |
||||
textEditor.Document.Text = xml; |
||||
textEditor.Caret.Offset = index; |
||||
|
||||
selectedElement = new SelectedXmlElement(textEditor); |
||||
} |
||||
|
||||
[Test] |
||||
public void ElementPathContainsSingleRootElement() |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.AddElement(new QualifiedName("parent", String.Empty)); |
||||
|
||||
Assert.AreEqual(path, selectedElement.Path); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasSelectedAttribute() |
||||
{ |
||||
Assert.IsTrue(selectedElement.HasSelectedAttribute); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasSelectedAttributeValue() |
||||
{ |
||||
Assert.IsTrue(selectedElement.HasSelectedAttributeValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectedAttributeIsFirstAttribute() |
||||
{ |
||||
Assert.AreEqual("a", selectedElement.SelectedAttribute); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectedAttributeValueIsFirstAttributeValue() |
||||
{ |
||||
Assert.AreEqual("attributeValue", selectedElement.SelectedAttributeValue); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
// <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; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.FindSchemaObject |
||||
{ |
||||
[TestFixture] |
||||
public class FindSelectedElementInTextEditorTestFixture |
||||
{ |
||||
SelectedXmlElement selectedElement; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
string xml = "<abc></abc>"; |
||||
int index = 2; |
||||
|
||||
MockTextEditor textEditor = new MockTextEditor(); |
||||
textEditor.Document.Text = xml; |
||||
textEditor.Caret.Offset = index; |
||||
|
||||
selectedElement = new SelectedXmlElement(textEditor); |
||||
} |
||||
|
||||
[Test] |
||||
public void ElementPathContainsSingleRootElement() |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.AddElement(new QualifiedName("abc", String.Empty)); |
||||
|
||||
Assert.AreEqual(path, selectedElement.Path); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasNoSelectedAttribute() |
||||
{ |
||||
Assert.IsFalse(selectedElement.HasSelectedAttribute); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasNoSelectedAttributeValue() |
||||
{ |
||||
Assert.IsFalse(selectedElement.HasSelectedAttributeValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectedAttributeIsEmptyString() |
||||
{ |
||||
Assert.AreEqual(String.Empty, selectedElement.SelectedAttribute); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectedAttributeValueIsEmptyString() |
||||
{ |
||||
Assert.AreEqual(String.Empty, selectedElement.SelectedAttributeValue); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,54 @@
@@ -0,0 +1,54 @@
|
||||
// <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.Xml.Schema; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.FindSchemaObject |
||||
{ |
||||
[TestFixture] |
||||
public class NullSchemaObjectPassedToSchemaObjectLocationTestFixture |
||||
{ |
||||
DerivedXmlSchemaObjectLocation location; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
XmlSchemaObject schemaObject = null; |
||||
location = new DerivedXmlSchemaObjectLocation(schemaObject); |
||||
location.JumpToFilePosition(); |
||||
} |
||||
|
||||
[Test] |
||||
public void FileNameIsEmptyString() |
||||
{ |
||||
Assert.AreEqual(String.Empty, location.FileName); |
||||
} |
||||
|
||||
[Test] |
||||
public void LineNumberIsMinusOne() |
||||
{ |
||||
Assert.AreEqual(-1, location.LineNumber); |
||||
} |
||||
|
||||
[Test] |
||||
public void LinePositionIsMinusOne() |
||||
{ |
||||
Assert.AreEqual(-1, location.LinePosition); |
||||
} |
||||
|
||||
[Test] |
||||
public void JumpToFilePositionMethodDoesNothing() |
||||
{ |
||||
location.JumpToFilePosition(); |
||||
Assert.IsFalse(location.IsDerivedJumpToFilePositionMethodCalled); |
||||
} |
||||
} |
||||
} |
@ -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 System.Xml.Schema; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
|
||||
namespace XmlEditor.Tests.FindSchemaObject |
||||
{ |
||||
[TestFixture] |
||||
public class SchemaObjectLocationFileNameTests |
||||
{ |
||||
[Test] |
||||
public void FileColonTripleSlashUrlRemovedFromSchemaObjectFileName() |
||||
{ |
||||
XmlSchema schemaObject = new XmlSchema(); |
||||
schemaObject.SourceUri = @"file:///d:\schemas\test.xsd"; |
||||
XmlSchemaObjectLocation location = new XmlSchemaObjectLocation(schemaObject); |
||||
|
||||
Assert.AreEqual(@"d:\schemas\test.xsd", location.FileName); |
||||
} |
||||
|
||||
[Test] |
||||
public void SchemaLocationFileNameIsEmptyStringIfSchemaObjectFileNameIsNull() |
||||
{ |
||||
XmlSchema schemaObject = new XmlSchema(); |
||||
schemaObject.SourceUri = null; |
||||
XmlSchemaObjectLocation location = new XmlSchemaObjectLocation(schemaObject); |
||||
|
||||
Assert.AreEqual(String.Empty, location.FileName); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
// <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.Xml.Schema; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.FindSchemaObject |
||||
{ |
||||
[TestFixture] |
||||
public class SchemaObjectLocationJumpToTests |
||||
{ |
||||
DerivedXmlSchemaObjectLocation location; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
XmlSchema schemaObject = new XmlSchema(); |
||||
schemaObject.SourceUri = @"d:\test\a.xsd"; |
||||
schemaObject.LineNumber = 2; |
||||
schemaObject.LinePosition = 4; |
||||
location = new DerivedXmlSchemaObjectLocation(schemaObject); |
||||
location.JumpToFilePosition(); |
||||
} |
||||
|
||||
[Test] |
||||
public void FileNameJumpedTo() |
||||
{ |
||||
Assert.AreEqual(@"d:\test\a.xsd", location.JumpToFilePositionMethodFileNameParameter); |
||||
} |
||||
|
||||
[Test] |
||||
public void LineNumberJumpedTo() |
||||
{ |
||||
Assert.AreEqual(2, location.JumpToFilePositionMethodLineParameter); |
||||
} |
||||
|
||||
[Test] |
||||
public void LinePositionJumpedTo() |
||||
{ |
||||
Assert.AreEqual(4, location.JumpToFilePositionMethodColumnParameter); |
||||
} |
||||
|
||||
[Test] |
||||
public void JumpToDoesNothingWhenFileNameIsEmptyString() |
||||
{ |
||||
XmlSchema schemaObject = new XmlSchema(); |
||||
schemaObject.SourceUri = String.Empty; |
||||
DerivedXmlSchemaObjectLocation location = new DerivedXmlSchemaObjectLocation(schemaObject); |
||||
Assert.IsFalse(location.IsDerivedJumpToFilePositionMethodCalled); |
||||
} |
||||
} |
||||
} |
@ -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 System.Xml.Schema; |
||||
using ICSharpCode.XmlEditor; |
||||
|
||||
namespace XmlEditor.Tests.Utils |
||||
{ |
||||
public class DerivedXmlSchemaObjectLocation : XmlSchemaObjectLocation |
||||
{ |
||||
bool jumpToFilePositionCalled; |
||||
string jumpToFilePositionMethodFileNameParameter; |
||||
int jumpToFilePositionMethodLineParameter = -1; |
||||
int jumpToFilePositionMethodColumnParameter = -1; |
||||
|
||||
public DerivedXmlSchemaObjectLocation(XmlSchemaObject schemaObject) |
||||
: base(schemaObject) |
||||
{ |
||||
} |
||||
|
||||
public bool IsDerivedJumpToFilePositionMethodCalled { |
||||
get { return jumpToFilePositionCalled; } |
||||
} |
||||
|
||||
public string JumpToFilePositionMethodFileNameParameter { |
||||
get { return jumpToFilePositionMethodFileNameParameter; } |
||||
} |
||||
|
||||
public int JumpToFilePositionMethodLineParameter { |
||||
get { return jumpToFilePositionMethodLineParameter; } |
||||
} |
||||
|
||||
public int JumpToFilePositionMethodColumnParameter { |
||||
get { return jumpToFilePositionMethodColumnParameter; } |
||||
} |
||||
|
||||
public void CallJumpToFilePosition(string fileName, int line, int column) |
||||
{ |
||||
JumpToFilePosition(fileName, line, column); |
||||
} |
||||
|
||||
protected override void JumpToFilePosition(string fileName, int line, int column) |
||||
{ |
||||
jumpToFilePositionCalled = true; |
||||
jumpToFilePositionMethodFileNameParameter = fileName; |
||||
jumpToFilePositionMethodLineParameter = line; |
||||
jumpToFilePositionMethodColumnParameter = column; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
// <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; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
|
||||
namespace XmlEditor.Tests.Utils |
||||
{ |
||||
public class MockTextEditorProviderViewContent : MockViewContent, ITextEditorProvider |
||||
{ |
||||
MockTextEditor textEditor = new MockTextEditor(); |
||||
|
||||
public ITextEditor TextEditor { |
||||
get { return textEditor; } |
||||
} |
||||
|
||||
public MockTextEditor MockTextEditor { |
||||
get { return textEditor; } |
||||
} |
||||
|
||||
public IDocument GetDocumentForFile(OpenedFile file) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,166 @@
@@ -0,0 +1,166 @@
|
||||
// <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.Gui; |
||||
|
||||
namespace XmlEditor.Tests.Utils |
||||
{ |
||||
public class MockViewContent : IViewContent |
||||
{ |
||||
public event EventHandler TabPageTextChanged; |
||||
|
||||
protected virtual void OnTabPageTextChanged(EventArgs e) |
||||
{ |
||||
if (TabPageTextChanged != null) { |
||||
TabPageTextChanged(this, e); |
||||
} |
||||
} |
||||
|
||||
public event EventHandler TitleNameChanged; |
||||
|
||||
protected virtual void OnTitleNameChanged(EventArgs e) |
||||
{ |
||||
if (TitleNameChanged != null) { |
||||
TitleNameChanged(this, e); |
||||
} |
||||
} |
||||
|
||||
public event EventHandler Disposed; |
||||
|
||||
protected virtual void OnDisposed(EventArgs e) |
||||
{ |
||||
if (Disposed != null) { |
||||
Disposed(this, e); |
||||
} |
||||
} |
||||
|
||||
public event EventHandler IsDirtyChanged; |
||||
|
||||
protected virtual void OnIsDirtyChanged(EventArgs e) |
||||
{ |
||||
if (IsDirtyChanged != null) { |
||||
IsDirtyChanged(this, e); |
||||
} |
||||
} |
||||
|
||||
public object Control { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IWorkbenchWindow WorkbenchWindow { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public string TabPageText { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public string TitleName { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public System.Collections.Generic.IList<ICSharpCode.SharpDevelop.OpenedFile> Files { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ICSharpCode.SharpDevelop.OpenedFile PrimaryFile { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ICSharpCode.Core.FileName PrimaryFileName { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsDisposed { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsReadOnly { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsViewOnly { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public System.Collections.Generic.ICollection<IViewContent> SecondaryViewContents { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsDirty { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public void Save(ICSharpCode.SharpDevelop.OpenedFile file, System.IO.Stream stream) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void Load(ICSharpCode.SharpDevelop.OpenedFile file, System.IO.Stream stream) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public ICSharpCode.SharpDevelop.INavigationPoint BuildNavPoint() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public bool SupportsSwitchFromThisWithoutSaveLoad(ICSharpCode.SharpDevelop.OpenedFile file, IViewContent newView) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public bool SupportsSwitchToThisWithoutSaveLoad(ICSharpCode.SharpDevelop.OpenedFile file, IViewContent oldView) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void SwitchFromThisWithoutSaveLoad(ICSharpCode.SharpDevelop.OpenedFile file, IViewContent newView) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void SwitchToThisWithoutSaveLoad(ICSharpCode.SharpDevelop.OpenedFile file, IViewContent oldView) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,194 @@
@@ -0,0 +1,194 @@
|
||||
// <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.SharpDevelop.Gui; |
||||
|
||||
namespace XmlEditor.Tests.Utils |
||||
{ |
||||
public class MockWorkbench : IWorkbench |
||||
{ |
||||
List<IViewContent> viewContentCollection = new List<IViewContent>(); |
||||
|
||||
public MockWorkbench() |
||||
{ |
||||
} |
||||
|
||||
public event EventHandler ActiveWorkbenchWindowChanged; |
||||
|
||||
protected virtual void OnActiveWorkbenchWindowChanged(EventArgs e) |
||||
{ |
||||
if (ActiveWorkbenchWindowChanged != null) { |
||||
ActiveWorkbenchWindowChanged(this, e); |
||||
} |
||||
} |
||||
|
||||
public event EventHandler ActiveViewContentChanged; |
||||
|
||||
protected virtual void OnActiveViewContentChanged(EventArgs e) |
||||
{ |
||||
if (ActiveViewContentChanged != null) { |
||||
ActiveViewContentChanged(this, e); |
||||
} |
||||
} |
||||
|
||||
public event EventHandler ActiveContentChanged; |
||||
|
||||
protected virtual void OnActiveContentChanged(EventArgs e) |
||||
{ |
||||
if (ActiveContentChanged != null) { |
||||
ActiveContentChanged(this, e); |
||||
} |
||||
} |
||||
|
||||
public event ViewContentEventHandler ViewOpened; |
||||
|
||||
protected virtual void OnViewOpened(ViewContentEventArgs e) |
||||
{ |
||||
if (ViewOpened != null) { |
||||
ViewOpened(this, e); |
||||
} |
||||
} |
||||
|
||||
public event ViewContentEventHandler ViewClosed; |
||||
|
||||
protected virtual void OnViewClosed(ViewContentEventArgs e) |
||||
{ |
||||
if (ViewClosed != null) { |
||||
ViewClosed(this, e); |
||||
} |
||||
} |
||||
|
||||
public System.Windows.Forms.IWin32Window MainWin32Window { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public System.ComponentModel.ISynchronizeInvoke SynchronizingObject { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public System.Windows.Window MainWindow { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public string Title { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ICollection<IViewContent> ViewContentCollection { |
||||
get { return viewContentCollection; } |
||||
} |
||||
|
||||
public ICollection<IViewContent> PrimaryViewContents { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IList<IWorkbenchWindow> WorkbenchWindowCollection { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IList<ICSharpCode.SharpDevelop.PadDescriptor> PadContentCollection { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IWorkbenchWindow ActiveWorkbenchWindow { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IViewContent ActiveViewContent { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public object ActiveContent { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IWorkbenchLayout WorkbenchLayout { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsActiveWindow { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public void Initialize() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void ShowView(IViewContent content) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void ShowView(IViewContent content, bool switchToOpenedView) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void ShowPad(ICSharpCode.SharpDevelop.PadDescriptor content) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void UnloadPad(ICSharpCode.SharpDevelop.PadDescriptor content) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public ICSharpCode.SharpDevelop.PadDescriptor GetPad(Type type) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void CloseAllViews() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public ICSharpCode.Core.Properties CreateMemento() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void SetMemento(ICSharpCode.Core.Properties memento) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,80 @@
@@ -0,0 +1,80 @@
|
||||
// <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.Xml.Schema; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Utils.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class DerivedXmlSchemaObjectLocationTests |
||||
{ |
||||
DerivedXmlSchemaObjectLocation location; |
||||
|
||||
[Test] |
||||
public void DefaultIsDerivedJumpToFilePositionMethodCalledIsFalse() |
||||
{ |
||||
DerivedXmlSchemaObjectLocation location = new DerivedXmlSchemaObjectLocation(null); |
||||
Assert.IsFalse(location.IsDerivedJumpToFilePositionMethodCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void DefaultJumpToFilePositionMethodFileNameParameter() |
||||
{ |
||||
DerivedXmlSchemaObjectLocation location = new DerivedXmlSchemaObjectLocation(null); |
||||
Assert.IsNull(location.JumpToFilePositionMethodFileNameParameter); |
||||
} |
||||
|
||||
[Test] |
||||
public void DefaultJumpToFilePositionMethodLineParameter() |
||||
{ |
||||
DerivedXmlSchemaObjectLocation location = new DerivedXmlSchemaObjectLocation(null); |
||||
Assert.AreEqual(-1, location.JumpToFilePositionMethodLineParameter); |
||||
} |
||||
|
||||
[Test] |
||||
public void DefaultJumpToFilePositionMethodColumnParameter() |
||||
{ |
||||
DerivedXmlSchemaObjectLocation location = new DerivedXmlSchemaObjectLocation(null); |
||||
Assert.AreEqual(-1, location.JumpToFilePositionMethodColumnParameter); |
||||
} |
||||
|
||||
[Test] |
||||
public void JumpToFilePositionMethodCallIsRecorded() |
||||
{ |
||||
int line = 2; |
||||
int column = 3; |
||||
location = new DerivedXmlSchemaObjectLocation(null); |
||||
location.CallJumpToFilePosition("test.xml", line, column); |
||||
|
||||
Assert.IsTrue(location.IsDerivedJumpToFilePositionMethodCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void JumpToFilePositionMethodCallRecordsLineParameter() |
||||
{ |
||||
JumpToFilePositionMethodCallIsRecorded(); |
||||
Assert.AreEqual(2, location.JumpToFilePositionMethodLineParameter); |
||||
} |
||||
|
||||
[Test] |
||||
public void JumpToFilePositionMethodCallRecordsColumnParameter() |
||||
{ |
||||
JumpToFilePositionMethodCallIsRecorded(); |
||||
Assert.AreEqual(3, location.JumpToFilePositionMethodColumnParameter); |
||||
} |
||||
|
||||
[Test] |
||||
public void JumpToFilePositionMethodCallRecordsFileNameParameter() |
||||
{ |
||||
JumpToFilePositionMethodCallIsRecorded(); |
||||
Assert.AreEqual("test.xml", location.JumpToFilePositionMethodFileNameParameter); |
||||
} |
||||
} |
||||
} |
@ -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 XmlEditor.Tests.Utils; |
||||
using NUnit.Framework; |
||||
|
||||
namespace XmlEditor.Tests.Utils.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class XPathNodeMatchComparisonResultTests |
||||
{ |
||||
[Test] |
||||
public void ComparisonResultsAreEqualWhenResultAndMessageAreSame() |
||||
{ |
||||
XPathNodeMatchComparisonResult lhs = new XPathNodeMatchComparisonResult(true, "abc"); |
||||
XPathNodeMatchComparisonResult rhs = new XPathNodeMatchComparisonResult(true, "abc"); |
||||
Assert.AreEqual(lhs, rhs); |
||||
} |
||||
|
||||
[Test] |
||||
public void ComparisonResultsAreNotEqualWhenResultIsDifferent() |
||||
{ |
||||
XPathNodeMatchComparisonResult lhs = new XPathNodeMatchComparisonResult(false, "abc"); |
||||
XPathNodeMatchComparisonResult rhs = new XPathNodeMatchComparisonResult(true, "abc"); |
||||
Assert.AreNotEqual(lhs, rhs); |
||||
} |
||||
|
||||
[Test] |
||||
public void ComparisonResultsAreNotEqualWhenMessageIsDifferent() |
||||
{ |
||||
XPathNodeMatchComparisonResult lhs = new XPathNodeMatchComparisonResult(false, "aaa"); |
||||
XPathNodeMatchComparisonResult rhs = new XPathNodeMatchComparisonResult(false, "bbb"); |
||||
Assert.AreNotEqual(lhs, rhs); |
||||
} |
||||
|
||||
[Test] |
||||
public void ComparisonResultToString() |
||||
{ |
||||
XPathNodeMatchComparisonResult lhs = new XPathNodeMatchComparisonResult(true, "message"); |
||||
Assert.AreEqual("Result: True, Message: 'message'", lhs.ToString()); |
||||
} |
||||
|
||||
[Test] |
||||
public void ComparisonResultEqualsReturnsFalseForNull() |
||||
{ |
||||
XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult(); |
||||
Assert.IsFalse(result.Equals(null)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,131 @@
@@ -0,0 +1,131 @@
|
||||
// <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.Xml.XPath; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Utils.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class XPathNodeMatchComparisonTests |
||||
{ |
||||
[Test] |
||||
public void ResultEqualsReturnsTrueWhenXPathNodesAreSame() |
||||
{ |
||||
XPathNodeMatch lhs = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 2, XPathNodeType.Text); |
||||
XPathNodeMatch rhs = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 2, XPathNodeType.Text); |
||||
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); |
||||
|
||||
XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult(); |
||||
result.Result = comparison.AreEqual(lhs, rhs); |
||||
result.Message = comparison.GetReasonForNotMatching(); |
||||
|
||||
XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(true, String.Empty); |
||||
Assert.AreEqual(expectedResult, result); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResultEqualsReturnsFalseWhenXPathNodeDisplayValueAreDifferent() |
||||
{ |
||||
XPathNodeMatch lhs = new XPathNodeMatch("nodeValue", "DisplayValue1", 1, 2, XPathNodeType.Text); |
||||
XPathNodeMatch rhs = new XPathNodeMatch("nodeValue", "DisplayValue2", 1, 2, XPathNodeType.Text); |
||||
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); |
||||
|
||||
XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult(); |
||||
result.Result = comparison.AreEqual(lhs, rhs); |
||||
result.Message = comparison.GetReasonForNotMatching(); |
||||
|
||||
string expectedReason = "DisplayValues do not match. Expected 'DisplayValue1' but was 'DisplayValue2'."; |
||||
XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason); |
||||
Assert.AreEqual(expectedResult, result); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResultEqualsReturnsFalseWhenXPathNodeLineNumbersAreDifferent() |
||||
{ |
||||
XPathNodeMatch lhs = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 2, XPathNodeType.Text); |
||||
XPathNodeMatch rhs = new XPathNodeMatch("nodeValue", "DisplayValue", 3, 2, XPathNodeType.Text); |
||||
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); |
||||
|
||||
XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult(); |
||||
result.Result = comparison.AreEqual(lhs, rhs); |
||||
result.Message = comparison.GetReasonForNotMatching(); |
||||
|
||||
string expectedReason = "LineNumbers do not match. Expected '1' but was '3'."; |
||||
XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason); |
||||
Assert.AreEqual(expectedResult, result); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResultEqualsReturnsFalseWhenXPathNodeValuesAreDifferent() |
||||
{ |
||||
XPathNodeMatch lhs = new XPathNodeMatch("nodeValue1", "DisplayValue", 1, 2, XPathNodeType.Text); |
||||
XPathNodeMatch rhs = new XPathNodeMatch("nodeValue2", "DisplayValue", 1, 2, XPathNodeType.Text); |
||||
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); |
||||
|
||||
XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult(); |
||||
result.Result = comparison.AreEqual(lhs, rhs); |
||||
result.Message = comparison.GetReasonForNotMatching(); |
||||
|
||||
string expectedReason = "Values do not match. Expected 'nodeValue1' but was 'nodeValue2'."; |
||||
XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason); |
||||
Assert.AreEqual(expectedResult, result); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResultEqualsReturnsFalseWhenXPathNodeLinePositionsAreDifferent() |
||||
{ |
||||
XPathNodeMatch lhs = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 2, XPathNodeType.Text); |
||||
XPathNodeMatch rhs = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 3, XPathNodeType.Text); |
||||
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); |
||||
|
||||
XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult(); |
||||
result.Result = comparison.AreEqual(lhs, rhs); |
||||
result.Message = comparison.GetReasonForNotMatching(); |
||||
|
||||
string expectedReason = "LinePositions do not match. Expected '2' but was '3'."; |
||||
XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason); |
||||
Assert.AreEqual(expectedResult, result); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResultEqualsReturnsFalseWhenXPathNodeNodeTypesAreDifferent() |
||||
{ |
||||
XPathNodeMatch lhs = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 2, XPathNodeType.Text); |
||||
XPathNodeMatch rhs = new XPathNodeMatch("nodeValue", "DisplayValue", 1, 2, XPathNodeType.Element); |
||||
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); |
||||
|
||||
XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult(); |
||||
result.Result = comparison.AreEqual(lhs, rhs); |
||||
result.Message = comparison.GetReasonForNotMatching(); |
||||
|
||||
string expectedReason = "NodeTypes do not match. Expected 'Text' but was 'Element'."; |
||||
XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason); |
||||
Assert.AreEqual(expectedResult, result); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResultEqualsReturnsFalseWhenOneXPathNodeLineNumberIsNull() |
||||
{ |
||||
int? lineNumber = null; |
||||
XPathNodeMatch lhs = new XPathNodeMatch("nodeValue", "DisplayValue", lineNumber, 2, XPathNodeType.Text); |
||||
XPathNodeMatch rhs = new XPathNodeMatch("nodeValue", "DisplayValue", 0, 2, XPathNodeType.Text); |
||||
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); |
||||
|
||||
XPathNodeMatchComparisonResult result = new XPathNodeMatchComparisonResult(); |
||||
result.Result = comparison.AreEqual(lhs, rhs); |
||||
result.Message = comparison.GetReasonForNotMatching(); |
||||
|
||||
string expectedReason = "LineNumbers do not match. Expected 'null' but was '0'."; |
||||
XPathNodeMatchComparisonResult expectedResult = new XPathNodeMatchComparisonResult(false, expectedReason); |
||||
Assert.AreEqual(expectedResult, result); |
||||
} |
||||
} |
||||
} |
@ -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.Reflection; |
||||
using System.Text; |
||||
using ICSharpCode.XmlEditor; |
||||
|
||||
namespace XmlEditor.Tests.Utils |
||||
{ |
||||
public class XPathNodeMatchComparison |
||||
{ |
||||
StringBuilder reason = new StringBuilder(); |
||||
|
||||
public XPathNodeMatchComparison() |
||||
{ |
||||
} |
||||
|
||||
public bool AreEqual(XPathNodeMatch lhs, XPathNodeMatch rhs) |
||||
{ |
||||
reason.Clear(); |
||||
|
||||
foreach (PropertyInfo property in typeof(XPathNodeMatch).GetProperties()) { |
||||
ComparePropertyValues(property, lhs, rhs); |
||||
} |
||||
if (lhs.HasLineInfo() != rhs.HasLineInfo()) { |
||||
AppendPropertyDoesNotMatchMessage("LineNumber", GetLineNumberIfHasLineInfo(lhs), GetLineNumberIfHasLineInfo(rhs)); |
||||
} |
||||
return !HasReasonForNotMatching; |
||||
} |
||||
|
||||
void ComparePropertyValues(PropertyInfo property, XPathNodeMatch lhs, XPathNodeMatch rhs) |
||||
{ |
||||
string lhsPropertyValue = GetPropertyValue(property, lhs); |
||||
string rhsPropertyValue = GetPropertyValue(property, rhs); |
||||
if (lhsPropertyValue != rhsPropertyValue) { |
||||
AppendPropertyDoesNotMatchMessage(property.Name, lhsPropertyValue, rhsPropertyValue); |
||||
} |
||||
} |
||||
|
||||
bool HasReasonForNotMatching { |
||||
get { return reason.Length > 0; } |
||||
} |
||||
|
||||
string GetPropertyValue(PropertyInfo property, XPathNodeMatch nodeMatch) |
||||
{ |
||||
return property.GetValue(nodeMatch, new object[0]).ToString(); |
||||
} |
||||
|
||||
void AppendPropertyDoesNotMatchMessage(string name, string lhs, string rhs) |
||||
{ |
||||
reason.AppendFormat("{0}s do not match. Expected '{1}' but was '{2}'.\r\n", name, lhs, rhs); |
||||
} |
||||
|
||||
string GetLineNumberIfHasLineInfo(XPathNodeMatch nodeMatch) |
||||
{ |
||||
if (nodeMatch.HasLineInfo()) { |
||||
return nodeMatch.LineNumber.ToString(); |
||||
} |
||||
return "null"; |
||||
} |
||||
|
||||
public string GetReasonForNotMatching() |
||||
{ |
||||
return reason.ToString().Trim(); |
||||
} |
||||
} |
||||
} |
@ -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; |
||||
|
||||
namespace XmlEditor.Tests.Utils |
||||
{ |
||||
public class XPathNodeMatchComparisonResult |
||||
{ |
||||
public XPathNodeMatchComparisonResult(bool result, string message) |
||||
{ |
||||
this.Result = result; |
||||
this.Message = message; |
||||
} |
||||
|
||||
public XPathNodeMatchComparisonResult() |
||||
{ |
||||
} |
||||
|
||||
public bool Result { get; set; } |
||||
public string Message { get; set; } |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("Result: {0}, Message: '{1}'", Result, Message); |
||||
} |
||||
|
||||
public override int GetHashCode() |
||||
{ |
||||
return base.GetHashCode(); |
||||
} |
||||
|
||||
public override bool Equals(object obj) |
||||
{ |
||||
XPathNodeMatchComparisonResult rhs = obj as XPathNodeMatchComparisonResult; |
||||
if (rhs != null) { |
||||
return (rhs.Result == Result) && (rhs.Message == Message); |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
// <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.Collections.ObjectModel; |
||||
using System.Xml; |
||||
using System.Xml.XPath; |
||||
|
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.XPath |
||||
{ |
||||
[TestFixture] |
||||
public class NamespaceXPathQueryTestFixture |
||||
{ |
||||
XPathNodeMatch node; |
||||
XPathNodeMatch xmlNamespaceNode; |
||||
XPathNodeMatch[] nodes; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
string xml = "<root xmlns='http://foo.com'/>"; |
||||
XPathQuery query = new XPathQuery(xml); |
||||
nodes = query.FindNodes("//namespace::*"); |
||||
node = nodes[0]; |
||||
xmlNamespaceNode = nodes[1]; |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoNamespaceNodesFoundByXPath() |
||||
{ |
||||
Assert.AreEqual(2, nodes.Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void FooNamespaceNodeFoundByXPath() |
||||
{ |
||||
string nodeValue = "xmlns=\"http://foo.com\""; |
||||
string displayValue = "xmlns=\"http://foo.com\""; |
||||
int lineNumber = 0; |
||||
int linePosition = 6; |
||||
XPathNodeType nodeType = XPathNodeType.Namespace; |
||||
XPathNodeMatch expectedMatch = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType); |
||||
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); |
||||
Assert.IsTrue(comparison.AreEqual(expectedMatch, node), comparison.GetReasonForNotMatching()); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlNamespaceNodeFoundByXPathHasNoLineInfo() |
||||
{ |
||||
Assert.IsFalse(xmlNamespaceNode.HasLineInfo()); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlNamespaceNodeFoundByXPathHasW3OrgSchemaNamespace() |
||||
{ |
||||
Assert.AreEqual("xmlns:xml=\"http://www.w3.org/XML/1998/namespace\"", xmlNamespaceNode.Value); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
// <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.ComponentModel.Design; |
||||
using System.Xml.XPath; |
||||
|
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Editor.AvalonEdit; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Tests.Utils; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.XPath |
||||
{ |
||||
[TestFixture] |
||||
public class RemoveXPathHighlightingCommandTestFixture |
||||
{ |
||||
MockWorkbench workbench; |
||||
ITextMarkerService markerService; |
||||
RemoveXPathHighlightingCommand command; |
||||
MockViewContent nonTextEditorProviderView; |
||||
MockTextEditorProviderViewContent textEditorView; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
ServiceContainer container = new ServiceContainer(); |
||||
markerService = new MockTextMarkerService(); |
||||
container.AddService(typeof(ITextMarkerService), markerService); |
||||
|
||||
// Add xpath marker to document.
|
||||
AvalonEditDocumentAdapter doc = new AvalonEditDocumentAdapter(container); |
||||
doc.Text = "<Test/>"; |
||||
XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc); |
||||
XPathNodeMatch nodeMatch = new XPathNodeMatch("Test", "<Test/>", 0, 1, XPathNodeType.Element); |
||||
xpathNodeMarker.AddMarker(nodeMatch); |
||||
|
||||
// Add non text editor provider view to workbench.
|
||||
workbench = new MockWorkbench(); |
||||
|
||||
nonTextEditorProviderView = new MockViewContent(); |
||||
workbench.ViewContentCollection.Add(nonTextEditorProviderView); |
||||
|
||||
// Add document to view content.
|
||||
textEditorView = new MockTextEditorProviderViewContent(); |
||||
textEditorView.MockTextEditor.SetDocument(doc); |
||||
workbench.ViewContentCollection.Add(textEditorView); |
||||
|
||||
command = new RemoveXPathHighlightingCommand(workbench); |
||||
} |
||||
|
||||
[Test] |
||||
public void CommandRunRemovesAllXPathNodeTextMarkersRemovedFromAllTextEditorWindows() |
||||
{ |
||||
command.Run(); |
||||
Assert.AreEqual(0, GetAllXPathTextMarkers().Count); |
||||
} |
||||
|
||||
List<ITextMarker> GetAllXPathTextMarkers() |
||||
{ |
||||
return new List<ITextMarker>(markerService.TextMarkers); |
||||
} |
||||
|
||||
[Test] |
||||
public void WorkbenchTextEditorsHaveAtLeastOneTextMarker() |
||||
{ |
||||
Assert.IsTrue(GetAllXPathTextMarkers().Count > 0); |
||||
} |
||||
|
||||
[Test] |
||||
public void MockViewContentDoesNotImplementITextEditorProviderInterface() |
||||
{ |
||||
Assert.IsNull(nonTextEditorProviderView as ITextEditorProvider); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,209 @@
@@ -0,0 +1,209 @@
|
||||
// <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.Collections.ObjectModel; |
||||
using System.Xml; |
||||
using System.Xml.XPath; |
||||
|
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.XPath |
||||
{ |
||||
[TestFixture] |
||||
public class RunXPathQueryTests |
||||
{ |
||||
[Test] |
||||
public void SingleEmptyElementNodeFoundByXPath() |
||||
{ |
||||
string xml = |
||||
"<root>\r\n" + |
||||
"\t<foo/>\r\n" + |
||||
"</root>"; |
||||
XPathQuery query = new XPathQuery(xml); |
||||
XPathNodeMatch[] nodes = query.FindNodes("//foo"); |
||||
XPathNodeMatch node = nodes[0]; |
||||
|
||||
string nodeValue = "foo"; |
||||
string displayValue = "<foo/>"; |
||||
int lineNumber = 1; |
||||
int linePosition = 2; |
||||
XPathNodeType nodeType = XPathNodeType.Element; |
||||
XPathNodeMatch expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType); |
||||
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); |
||||
Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching()); |
||||
Assert.AreEqual(1, nodes.Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void XPathNodeMatchImplementsIXmlLineInfoInterface() |
||||
{ |
||||
XPathNodeMatch node = new XPathNodeMatch(String.Empty, String.Empty, 1, 1, XPathNodeType.Text); |
||||
Assert.IsNotNull(node as IXmlLineInfo); |
||||
} |
||||
|
||||
[Test] |
||||
public void OneElementNodeWithNamespaceFoundByXPath() |
||||
{ |
||||
string xml = |
||||
"<root xmlns='http://foo.com'>\r\n" + |
||||
"\t<foo></foo>\r\n" + |
||||
"</root>"; |
||||
XmlNamespaceCollection namespaces = new XmlNamespaceCollection(); |
||||
namespaces.Add(new XmlNamespace("f", "http://foo.com")); |
||||
XPathQuery query = new XPathQuery(xml, namespaces); |
||||
XPathNodeMatch[] nodes = query.FindNodes("//f:foo"); |
||||
XPathNodeMatch node = nodes[0]; |
||||
|
||||
string nodeValue = "foo"; |
||||
string displayValue = "<foo>"; |
||||
int lineNumber = 1; |
||||
int linePosition = 2; |
||||
XPathNodeType nodeType = XPathNodeType.Element; |
||||
XPathNodeMatch expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType); |
||||
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); |
||||
Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching()); |
||||
Assert.AreEqual(1, nodes.Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void SingleElementWithNamespacePrefixFoundByXPath() |
||||
{ |
||||
string xml = |
||||
"<f:root xmlns:f='http://foo.com'>\r\n" + |
||||
"\t<f:foo></f:foo>\r\n" + |
||||
"</f:root>"; |
||||
XmlNamespaceCollection namespaces = new XmlNamespaceCollection(); |
||||
namespaces.Add(new XmlNamespace("fo", "http://foo.com")); |
||||
XPathQuery query = new XPathQuery(xml, namespaces); |
||||
XPathNodeMatch[] nodes = query.FindNodes("//fo:foo"); |
||||
XPathNodeMatch node = nodes[0]; |
||||
|
||||
string nodeValue = "f:foo"; |
||||
string displayValue = "<f:foo>"; |
||||
int lineNumber = 1; |
||||
int linePosition = 2; |
||||
XPathNodeType nodeType = XPathNodeType.Element; |
||||
XPathNodeMatch expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType); |
||||
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); |
||||
Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching()); |
||||
Assert.AreEqual(1, nodes.Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoXPathNodeFoundForUnknownElementInXPathQuery() |
||||
{ |
||||
string xml = |
||||
"<root>\r\n" + |
||||
"\t<foo/>\r\n" + |
||||
"</root>"; |
||||
XPathQuery query = new XPathQuery(xml); |
||||
XPathNodeMatch[] nodes = query.FindNodes("//bar"); |
||||
Assert.AreEqual(0, nodes.Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextNodeMatchedWithXPath() |
||||
{ |
||||
string xml = |
||||
"<root>\r\n" + |
||||
"\t<foo>test</foo>\r\n" + |
||||
"</root>"; |
||||
XPathQuery query = new XPathQuery(xml); |
||||
XPathNodeMatch[] nodes = query.FindNodes("//foo/text()"); |
||||
XPathNodeMatch node = nodes[0]; |
||||
|
||||
string nodeValue = "test"; |
||||
string displayValue = "test"; |
||||
int lineNumber = 1; |
||||
int linePosition = 6; |
||||
XPathNodeType nodeType = XPathNodeType.Text; |
||||
XPathNodeMatch expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType); |
||||
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); |
||||
Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching()); |
||||
Assert.AreEqual(1, nodes.Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void CommentNodeFoundByXPath() |
||||
{ |
||||
string xml = "<!-- Test --><root/>"; |
||||
XPathQuery query = new XPathQuery(xml); |
||||
XPathNodeMatch[] nodes = query.FindNodes("//comment()"); |
||||
XPathNodeMatch node = nodes[0]; |
||||
|
||||
string nodeValue = " Test "; |
||||
string displayValue = "<!-- Test -->"; |
||||
int lineNumber = 0; |
||||
int linePosition = 4; |
||||
XPathNodeType nodeType = XPathNodeType.Comment; |
||||
XPathNodeMatch expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType); |
||||
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); |
||||
Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching()); |
||||
} |
||||
|
||||
[Test] |
||||
public void EmptyCommentNodeFoundByXPath() |
||||
{ |
||||
string xml = "<!----><root/>"; |
||||
XPathQuery query = new XPathQuery(xml); |
||||
XPathNodeMatch[] nodes = query.FindNodes("//comment()"); |
||||
XPathNodeMatch node = nodes[0]; |
||||
|
||||
string nodeValue = String.Empty; |
||||
string displayValue = "<!---->"; |
||||
int lineNumber = 0; |
||||
int linePosition = 4; |
||||
XPathNodeType nodeType = XPathNodeType.Comment; |
||||
XPathNodeMatch expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType); |
||||
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); |
||||
Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching()); |
||||
Assert.AreEqual(1, nodes.Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProcessingInstructionNodeFoundByXPath() |
||||
{ |
||||
string xml = "<root><?test processinstruction='1.0'?></root>"; |
||||
XPathQuery query = new XPathQuery(xml); |
||||
XPathNodeMatch[] nodes = query.FindNodes("//processing-instruction()"); |
||||
XPathNodeMatch node = nodes[0]; |
||||
|
||||
string nodeValue = "test"; |
||||
string displayValue = "<?test processinstruction='1.0'?>"; |
||||
int lineNumber = 0; |
||||
int linePosition = 8; |
||||
XPathNodeType nodeType = XPathNodeType.ProcessingInstruction; |
||||
XPathNodeMatch expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType); |
||||
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); |
||||
Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching()); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeNodeFoundByXPath() |
||||
{ |
||||
string xml = "<root>\r\n" + |
||||
"\t<foo Id='ab'></foo>\r\n" + |
||||
"</root>"; |
||||
XPathQuery query = new XPathQuery(xml); |
||||
XPathNodeMatch[] nodes = query.FindNodes("//foo/@Id"); |
||||
XPathNodeMatch node = nodes[0]; |
||||
|
||||
string nodeValue = "Id"; |
||||
string displayValue = "@Id"; |
||||
int lineNumber = 1; |
||||
int linePosition = 6; |
||||
XPathNodeType nodeType = XPathNodeType.Attribute; |
||||
XPathNodeMatch expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType); |
||||
XPathNodeMatchComparison comparison = new XPathNodeMatchComparison(); |
||||
Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,73 @@
@@ -0,0 +1,73 @@
|
||||
// <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.ComponentModel.Design; |
||||
|
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Editor.AvalonEdit; |
||||
using ICSharpCode.SharpDevelop.Tests.Utils; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
|
||||
namespace XmlEditor.Tests.XPath |
||||
{ |
||||
[TestFixture] |
||||
public class SingleXPathQueryElementMarkedTestFixture |
||||
{ |
||||
ITextMarker xpathNodeTextMarker; |
||||
List<ITextMarker> markers; |
||||
List<ITextMarker> markersAfterRemove; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
string xml = "<root><foo/></root>"; |
||||
XPathQuery query = new XPathQuery(xml); |
||||
XPathNodeMatch[] nodes = query.FindNodes("//root"); |
||||
|
||||
IDocument doc = MockTextMarkerService.CreateDocumentWithMockService(); |
||||
doc.Text = xml; |
||||
XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc); |
||||
xpathNodeMarker.AddMarkers(nodes); |
||||
|
||||
ITextMarkerService service = doc.GetService(typeof(ITextMarkerService)) as ITextMarkerService; |
||||
markers = new List<ITextMarker>(service.TextMarkers); |
||||
|
||||
// Remove markers.
|
||||
xpathNodeMarker.RemoveMarkers(); |
||||
markersAfterRemove = new List<ITextMarker>(service.TextMarkers); |
||||
|
||||
xpathNodeTextMarker = markers[0]; |
||||
} |
||||
|
||||
[Test] |
||||
public void OneTextMarkerAddedForXPathMatch() |
||||
{ |
||||
Assert.AreEqual(1, markers.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void StartOffsetForXPathNodeMarkerIsOne() |
||||
{ |
||||
Assert.AreEqual(1, xpathNodeTextMarker.StartOffset); |
||||
} |
||||
|
||||
[Test] |
||||
public void LengthForXpathNodeMarkerIsFour() |
||||
{ |
||||
Assert.AreEqual(4, xpathNodeTextMarker.Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoTextMarkersAfterXPathNodeMarkerRemoveMarkersCalled() |
||||
{ |
||||
Assert.AreEqual(0, markersAfterRemove.Count); |
||||
} |
||||
} |
||||
} |
@ -1,175 +0,0 @@
@@ -1,175 +0,0 @@
|
||||
// <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.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Collections.ObjectModel; |
||||
using System.Xml; |
||||
using System.Xml.XPath; |
||||
|
||||
namespace XmlEditor.Tests.XPathQuery |
||||
{ |
||||
[TestFixture] |
||||
public class RunXPathQueryTests |
||||
{ |
||||
[Test] |
||||
public void OneElementNode() |
||||
{ |
||||
string xml = "<root>\r\n" + |
||||
"\t<foo/>\r\n" + |
||||
"</root>"; |
||||
XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//foo"); |
||||
XPathNodeMatch node = nodes[0]; |
||||
IXmlLineInfo lineInfo = node as IXmlLineInfo; |
||||
Assert.AreEqual(1, nodes.Length); |
||||
Assert.AreEqual(1, node.LineNumber); |
||||
Assert.AreEqual(2, node.LinePosition); |
||||
Assert.AreEqual("foo", node.Value); |
||||
Assert.AreEqual("<foo/>", node.DisplayValue); |
||||
Assert.AreEqual(XPathNodeType.Element, node.NodeType); |
||||
Assert.IsNotNull(lineInfo); |
||||
} |
||||
|
||||
[Test] |
||||
public void OneElementNodeWithNamespace() |
||||
{ |
||||
string xml = "<root xmlns='http://foo.com'>\r\n" + |
||||
"\t<foo></foo>\r\n" + |
||||
"</root>"; |
||||
List<XmlNamespace> namespaces = new List<XmlNamespace>(); |
||||
namespaces.Add(new XmlNamespace("f", "http://foo.com")); |
||||
ReadOnlyCollection<XmlNamespace> readOnlyNamespaces = new ReadOnlyCollection<XmlNamespace>(namespaces); |
||||
XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//f:foo", readOnlyNamespaces); |
||||
XPathNodeMatch node = nodes[0]; |
||||
IXmlLineInfo lineInfo = node as IXmlLineInfo; |
||||
Assert.AreEqual(1, nodes.Length); |
||||
Assert.AreEqual(1, node.LineNumber); |
||||
Assert.AreEqual(2, node.LinePosition); |
||||
Assert.AreEqual("foo", node.Value); |
||||
Assert.AreEqual("<foo>", node.DisplayValue); |
||||
Assert.AreEqual(XPathNodeType.Element, node.NodeType); |
||||
Assert.IsNotNull(lineInfo); |
||||
} |
||||
|
||||
[Test] |
||||
public void ElementWithNamespacePrefix() |
||||
{ |
||||
string xml = "<f:root xmlns:f='http://foo.com'>\r\n" + |
||||
"\t<f:foo></f:foo>\r\n" + |
||||
"</f:root>"; |
||||
List<XmlNamespace> namespaces = new List<XmlNamespace>(); |
||||
namespaces.Add(new XmlNamespace("fo", "http://foo.com")); |
||||
ReadOnlyCollection<XmlNamespace> readOnlyNamespaces = new ReadOnlyCollection<XmlNamespace>(namespaces); |
||||
XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//fo:foo", readOnlyNamespaces); |
||||
XPathNodeMatch node = nodes[0]; |
||||
IXmlLineInfo lineInfo = node as IXmlLineInfo; |
||||
Assert.AreEqual(1, nodes.Length); |
||||
Assert.AreEqual(1, node.LineNumber); |
||||
Assert.AreEqual(2, node.LinePosition); |
||||
Assert.AreEqual("f:foo", node.Value); |
||||
Assert.AreEqual("<f:foo>", node.DisplayValue); |
||||
Assert.AreEqual(XPathNodeType.Element, node.NodeType); |
||||
Assert.IsNotNull(lineInfo); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoNodeFound() |
||||
{ |
||||
string xml = "<root>\r\n" + |
||||
"\t<foo/>\r\n" + |
||||
"</root>"; |
||||
XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//bar"); |
||||
Assert.AreEqual(0, nodes.Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void TextNode() |
||||
{ |
||||
string xml = "<root>\r\n" + |
||||
"\t<foo>test</foo>\r\n" + |
||||
"</root>"; |
||||
XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//foo/text()"); |
||||
XPathNodeMatch node = nodes[0]; |
||||
Assert.AreEqual(1, nodes.Length); |
||||
Assert.AreEqual(1, node.LineNumber); |
||||
Assert.AreEqual(6, node.LinePosition); |
||||
Assert.AreEqual("test", node.Value); |
||||
Assert.AreEqual("test", node.DisplayValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void CommentNode() |
||||
{ |
||||
string xml = "<!-- Test --><root/>"; |
||||
XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//comment()"); |
||||
XPathNodeMatch node = nodes[0]; |
||||
Assert.AreEqual(1, nodes.Length); |
||||
Assert.AreEqual(0, node.LineNumber); |
||||
Assert.AreEqual(4, node.LinePosition); |
||||
Assert.AreEqual(" Test ", node.Value); |
||||
Assert.AreEqual("<!-- Test -->", node.DisplayValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void EmptyCommentNode() |
||||
{ |
||||
string xml = "<!----><root/>"; |
||||
XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//comment()"); |
||||
XPathNodeMatch node = nodes[0]; |
||||
Assert.AreEqual(1, nodes.Length); |
||||
Assert.AreEqual(0, node.LineNumber); |
||||
Assert.AreEqual(4, node.LinePosition); |
||||
Assert.AreEqual(String.Empty, node.Value); |
||||
Assert.AreEqual("<!---->", node.DisplayValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void NamespaceNode() |
||||
{ |
||||
string xml = "<root xmlns='http://foo.com'/>"; |
||||
XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//namespace::*"); |
||||
XPathNodeMatch node = nodes[0]; |
||||
XPathNodeMatch xmlNamespaceNode = nodes[1]; |
||||
Assert.AreEqual(2, nodes.Length); |
||||
Assert.AreEqual(0, node.LineNumber); |
||||
Assert.AreEqual(6, node.LinePosition); |
||||
Assert.AreEqual("xmlns=\"http://foo.com\"", node.Value); |
||||
Assert.AreEqual("xmlns=\"http://foo.com\"", node.DisplayValue); |
||||
Assert.IsFalse(xmlNamespaceNode.HasLineInfo()); |
||||
Assert.AreEqual("xmlns:xml=\"http://www.w3.org/XML/1998/namespace\"", xmlNamespaceNode.Value); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProcessingInstructionNode() |
||||
{ |
||||
string xml = "<root><?test processinstruction='1.0'?></root>"; |
||||
XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//processing-instruction()"); |
||||
XPathNodeMatch node = nodes[0]; |
||||
Assert.AreEqual("test", node.Value); |
||||
Assert.AreEqual("<?test processinstruction='1.0'?>", node.DisplayValue); |
||||
Assert.AreEqual(0, node.LineNumber); |
||||
Assert.AreEqual(8, node.LinePosition); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeNode() |
||||
{ |
||||
string xml = "<root>\r\n" + |
||||
"\t<foo Id='ab'></foo>\r\n" + |
||||
"</root>"; |
||||
XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//foo/@Id"); |
||||
XPathNodeMatch node = nodes[0]; |
||||
Assert.AreEqual(1, nodes.Length); |
||||
Assert.AreEqual(1, node.LineNumber); |
||||
Assert.AreEqual(6, node.LinePosition); |
||||
Assert.AreEqual("Id", node.Value); |
||||
Assert.AreEqual("@Id", node.DisplayValue); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue