Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5295 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
62 changed files with 1185 additions and 282 deletions
@ -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 System.Collections.Generic; |
||||||
|
using System.Collections.ObjectModel; |
||||||
|
|
||||||
|
namespace ICSharpCode.XmlEditor |
||||||
|
{ |
||||||
|
public class XmlElementPathsByNamespace : Collection<XmlElementPath> |
||||||
|
{ |
||||||
|
Dictionary<string, XmlElementPath> pathsByNamespace = new Dictionary<string, XmlElementPath>(); |
||||||
|
XmlNamespaceCollection namespacesWithoutPaths = new XmlNamespaceCollection(); |
||||||
|
|
||||||
|
public XmlElementPathsByNamespace(XmlElementPath path) |
||||||
|
{ |
||||||
|
SeparateIntoPathsByNamespace(path); |
||||||
|
AddSeparatedPathsToCollection(); |
||||||
|
FindNamespacesWithoutAssociatedPaths(path.NamespacesInScope); |
||||||
|
pathsByNamespace.Clear(); |
||||||
|
} |
||||||
|
|
||||||
|
void SeparateIntoPathsByNamespace(XmlElementPath path) |
||||||
|
{ |
||||||
|
foreach (QualifiedName elementName in path.Elements) { |
||||||
|
XmlElementPath matchedPath = FindOrCreatePath(elementName.Namespace); |
||||||
|
matchedPath.AddElement(elementName); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
XmlElementPath FindOrCreatePath(string elementNamespace) |
||||||
|
{ |
||||||
|
XmlElementPath path = FindPath(elementNamespace); |
||||||
|
if (path != null) { |
||||||
|
return path; |
||||||
|
} |
||||||
|
return CreatePath(elementNamespace); |
||||||
|
} |
||||||
|
|
||||||
|
XmlElementPath FindPath(string elementNamespace) |
||||||
|
{ |
||||||
|
XmlElementPath path; |
||||||
|
if (pathsByNamespace.TryGetValue(elementNamespace, out path)) { |
||||||
|
return path; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
XmlElementPath CreatePath(string elementNamespace) |
||||||
|
{ |
||||||
|
XmlElementPath path = new XmlElementPath(); |
||||||
|
pathsByNamespace.Add(elementNamespace, path); |
||||||
|
return path; |
||||||
|
} |
||||||
|
|
||||||
|
void AddSeparatedPathsToCollection() |
||||||
|
{ |
||||||
|
foreach (KeyValuePair<string, XmlElementPath> dictionaryEntry in pathsByNamespace) { |
||||||
|
Add(dictionaryEntry.Value); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void FindNamespacesWithoutAssociatedPaths(XmlNamespaceCollection namespacesInScope) |
||||||
|
{ |
||||||
|
foreach (XmlNamespace ns in namespacesInScope) { |
||||||
|
if (!HavePathForNamespace(ns)) { |
||||||
|
namespacesWithoutPaths.Add(ns); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
bool HavePathForNamespace(XmlNamespace ns) |
||||||
|
{ |
||||||
|
return pathsByNamespace.ContainsKey(ns.Name); |
||||||
|
} |
||||||
|
|
||||||
|
public XmlNamespaceCollection NamespacesWithoutPaths { |
||||||
|
get { return namespacesWithoutPaths; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,36 @@ |
|||||||
|
// <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; |
||||||
|
|
||||||
|
namespace ICSharpCode.XmlEditor |
||||||
|
{ |
||||||
|
public class XmlNamespaceCollection : Collection<XmlNamespace> |
||||||
|
{ |
||||||
|
public XmlNamespaceCollection() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public XmlNamespace[] ToArray() |
||||||
|
{ |
||||||
|
List<XmlNamespace> namespaces = new List<XmlNamespace>(this); |
||||||
|
return namespaces.ToArray(); |
||||||
|
} |
||||||
|
|
||||||
|
public string GetNamespaceForPrefix(string prefix) |
||||||
|
{ |
||||||
|
foreach (XmlNamespace ns in this) { |
||||||
|
if (ns.Prefix == prefix) { |
||||||
|
return ns.Name; |
||||||
|
} |
||||||
|
} |
||||||
|
return String.Empty; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,48 @@ |
|||||||
|
// <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.Parser |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class NamespacesInScopeForPathTests |
||||||
|
{ |
||||||
|
XmlNamespace xmlNamespace; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
xmlNamespace = new XmlNamespace("xml", "http://www.w3.org/XML/1998/namespace"); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void XmlNamespaceInScopeForRootElementWithNoNamespace() |
||||||
|
{ |
||||||
|
string xml = "<root "; |
||||||
|
XmlElementPath path = XmlParser.GetActiveElementStartPath(xml, xml.Length); |
||||||
|
|
||||||
|
XmlNamespace[] expectedNamespaces = new XmlNamespace[] {xmlNamespace}; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedNamespaces, path.NamespacesInScope.ToArray()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TwoNamespacesInScopeForRootElement() |
||||||
|
{ |
||||||
|
string xml = "<root xmlns='test' "; |
||||||
|
XmlElementPath path = XmlParser.GetActiveElementStartPath(xml, xml.Length); |
||||||
|
|
||||||
|
XmlNamespace testNamespace = new XmlNamespace(String.Empty, "test"); |
||||||
|
XmlNamespace[] expectedNamespaces = new XmlNamespace[] {xmlNamespace, testNamespace}; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedNamespaces, path.NamespacesInScope.ToArray()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,32 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Paths |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class EmptyElementPathsByNamespaceTestFixture |
||||||
|
{ |
||||||
|
XmlElementPathsByNamespace paths; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
XmlElementPath path = new XmlElementPath(); |
||||||
|
paths = new XmlElementPathsByNamespace(path); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void HasNoItemsWhenCreated() |
||||||
|
{ |
||||||
|
Assert.AreEqual(0, paths.Count); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,42 @@ |
|||||||
|
// <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.Paths |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class NamespacesWithoutPathsTests |
||||||
|
{ |
||||||
|
XmlElementPath path; |
||||||
|
XmlNamespace fooNamespace; |
||||||
|
XmlNamespace barNamespace; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
path = new XmlElementPath(); |
||||||
|
fooNamespace = new XmlNamespace("foo", "http://foo"); |
||||||
|
barNamespace = new XmlNamespace("bar", "http://bar"); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TwoNamespacesInScopeAndOneNamespaceUsedInPathNamespacesWithoutPathsReturnsUnusedNamespace() |
||||||
|
{ |
||||||
|
path.AddElement(new QualifiedName("foo-root", "http://foo")); |
||||||
|
path.NamespacesInScope.Add(fooNamespace); |
||||||
|
path.NamespacesInScope.Add(barNamespace); |
||||||
|
|
||||||
|
XmlElementPathsByNamespace pathsByNamespaces = new XmlElementPathsByNamespace(path); |
||||||
|
|
||||||
|
XmlNamespace[] expectedNamespaces = new XmlNamespace[] {barNamespace}; |
||||||
|
Assert.AreEqual(expectedNamespaces, pathsByNamespaces.NamespacesWithoutPaths.ToArray()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -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 ICSharpCode.XmlEditor; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Paths |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class OneAndTwoElementPathsByNamespaceTestFixture |
||||||
|
{ |
||||||
|
XmlElementPathsByNamespace paths; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
XmlElementPath path = new XmlElementPath(); |
||||||
|
path.AddElement(new QualifiedName("a", "a-namespace")); |
||||||
|
path.AddElement(new QualifiedName("b", "b-namespace")); |
||||||
|
path.AddElement(new QualifiedName("aa", "a-namespace")); |
||||||
|
paths = new XmlElementPathsByNamespace(path); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void HasTwoXmlElementPaths() |
||||||
|
{ |
||||||
|
Assert.AreEqual(2, paths.Count); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void FirstXmlElementPathHasTwoElements() |
||||||
|
{ |
||||||
|
XmlElementPath expectedPath = new XmlElementPath(); |
||||||
|
expectedPath.AddElement(new QualifiedName("a", "a-namespace")); |
||||||
|
expectedPath.AddElement(new QualifiedName("aa", "a-namespace")); |
||||||
|
|
||||||
|
Assert.AreEqual(expectedPath, paths[0]); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void SecondXmlElementPathHasOneElement() |
||||||
|
{ |
||||||
|
XmlElementPath expectedPath = new XmlElementPath(); |
||||||
|
expectedPath.AddElement(new QualifiedName("b", "b-namespace")); |
||||||
|
|
||||||
|
Assert.AreEqual(expectedPath, paths[1]); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,42 @@ |
|||||||
|
// <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.Paths |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class SingleElementPathByNamespaceTestFixture |
||||||
|
{ |
||||||
|
XmlElementPathsByNamespace paths; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
XmlElementPath path = new XmlElementPath(); |
||||||
|
path.AddElement(new QualifiedName("a", "a-namespace")); |
||||||
|
paths = new XmlElementPathsByNamespace(path); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void HasSingleXmlElementPath() |
||||||
|
{ |
||||||
|
Assert.AreEqual(1, paths.Count); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void XmlElementPathHasOneElement() |
||||||
|
{ |
||||||
|
XmlElementPath expectedPath = new XmlElementPath(); |
||||||
|
expectedPath.AddElement(new QualifiedName("a", "a-namespace")); |
||||||
|
|
||||||
|
Assert.AreEqual(expectedPath, paths[0]); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,52 @@ |
|||||||
|
// <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.Paths |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class TwoElementPathsByNamespaceTestFixture |
||||||
|
{ |
||||||
|
XmlElementPathsByNamespace paths; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
XmlElementPath path = new XmlElementPath(); |
||||||
|
path.AddElement(new QualifiedName("a", "a-namespace")); |
||||||
|
path.AddElement(new QualifiedName("b", "b-namespace")); |
||||||
|
paths = new XmlElementPathsByNamespace(path); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void HasTwoXmlElementPaths() |
||||||
|
{ |
||||||
|
Assert.AreEqual(2, paths.Count); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void FirstXmlElementPathHasOneElement() |
||||||
|
{ |
||||||
|
XmlElementPath expectedPath = new XmlElementPath(); |
||||||
|
expectedPath.AddElement(new QualifiedName("a", "a-namespace")); |
||||||
|
|
||||||
|
Assert.AreEqual(expectedPath, paths[0]); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void SecondXmlElementPathHasOneElement() |
||||||
|
{ |
||||||
|
XmlElementPath expectedPath = new XmlElementPath(); |
||||||
|
expectedPath.AddElement(new QualifiedName("b", "b-namespace")); |
||||||
|
|
||||||
|
Assert.AreEqual(expectedPath, paths[1]); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,87 @@ |
|||||||
|
// <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.Paths |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class XmlNamespaceCollectionTests |
||||||
|
{ |
||||||
|
XmlNamespaceCollection namespaceCollection; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
namespaceCollection = new XmlNamespaceCollection(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ToArrayReturnsXmlNamespaceItemsInCollection() |
||||||
|
{ |
||||||
|
XmlNamespace a = new XmlNamespace("a", "a-ns"); |
||||||
|
XmlNamespace b = new XmlNamespace("b", "b-ns"); |
||||||
|
|
||||||
|
namespaceCollection.Add(a); |
||||||
|
namespaceCollection.Add(b); |
||||||
|
|
||||||
|
XmlNamespace[] expectedArray = new XmlNamespace[] { a, b }; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedArray, namespaceCollection.ToArray()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetNamespaceForPrefixReturnsPrefixForKnownNamespaceInCollection() |
||||||
|
{ |
||||||
|
XmlNamespace ns = new XmlNamespace("prefix", "namespace"); |
||||||
|
namespaceCollection.Add(ns); |
||||||
|
|
||||||
|
Assert.AreEqual("namespace", namespaceCollection.GetNamespaceForPrefix("prefix")); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GetNamespaceForPrefixReturnsEmptyStringForUnknownNamespaceInCollection() |
||||||
|
{ |
||||||
|
XmlNamespace ns = new XmlNamespace("prefix", "namespace"); |
||||||
|
namespaceCollection.Add(ns); |
||||||
|
|
||||||
|
Assert.AreEqual(String.Empty, namespaceCollection.GetNamespaceForPrefix("unknown-prefix")); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ContainsReturnsFalseForKnownNamespaceWhenPrefixDoesNotMatch() |
||||||
|
{ |
||||||
|
XmlNamespace ns = new XmlNamespace("prefix", "namespace"); |
||||||
|
namespaceCollection.Add(ns); |
||||||
|
XmlNamespace namespaceWithDifferentPrefix = new XmlNamespace(String.Empty, "namespace"); |
||||||
|
|
||||||
|
Assert.IsFalse(namespaceCollection.Contains(namespaceWithDifferentPrefix)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ContainsReturnsTrueForKnownNamespaceWhenPrefixIsEmptyString() |
||||||
|
{ |
||||||
|
XmlNamespace ns = new XmlNamespace(String.Empty, "namespace"); |
||||||
|
namespaceCollection.Add(ns); |
||||||
|
|
||||||
|
Assert.IsTrue(namespaceCollection.Contains(ns)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ContainsReturnsFalseForUnknownNamespace() |
||||||
|
{ |
||||||
|
XmlNamespace ns = new XmlNamespace("prefix", "namespace"); |
||||||
|
namespaceCollection.Add(ns); |
||||||
|
|
||||||
|
XmlNamespace unknownNamespace = new XmlNamespace("prefix", "unknown-namespace"); |
||||||
|
|
||||||
|
Assert.IsFalse(namespaceCollection.Contains(unknownNamespace)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,75 @@ |
|||||||
|
// <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.Paths |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class XmlNamespaceEqualsTests |
||||||
|
{ |
||||||
|
XmlNamespace lhs; |
||||||
|
XmlNamespace rhs; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
lhs = new XmlNamespace(); |
||||||
|
rhs = new XmlNamespace(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void EmptyNamespacesAreEqual() |
||||||
|
{ |
||||||
|
Assert.IsTrue(lhs.Equals(rhs)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NullNamespaceIsNotEqual() |
||||||
|
{ |
||||||
|
Assert.IsFalse(lhs.Equals(null)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void SameNamespaceAndPrefixAreEqual() |
||||||
|
{ |
||||||
|
lhs.Name = "a-ns"; |
||||||
|
lhs.Prefix = "a"; |
||||||
|
|
||||||
|
rhs.Name = "a-ns"; |
||||||
|
rhs.Prefix = "a"; |
||||||
|
|
||||||
|
Assert.IsTrue(lhs.Equals(rhs)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void DifferentNamespacesAreNotEqual() |
||||||
|
{ |
||||||
|
lhs.Name = "namespace"; |
||||||
|
lhs.Prefix = "a"; |
||||||
|
|
||||||
|
rhs.Name = "different-namespace"; |
||||||
|
rhs.Prefix = "a"; |
||||||
|
|
||||||
|
Assert.IsFalse(lhs.Equals(rhs)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void SameNamespaceButDifferentPrefixAreNotEqual() |
||||||
|
{ |
||||||
|
lhs.Name = "namespace"; |
||||||
|
lhs.Prefix = "a"; |
||||||
|
|
||||||
|
rhs.Name = "namespace"; |
||||||
|
rhs.Prefix = "b"; |
||||||
|
|
||||||
|
Assert.IsFalse(lhs.Equals(rhs)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,225 @@ |
|||||||
|
// <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.XmlEditor; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Schema.Multiple |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class TwoSchemaChildElementCompletionTestFixture |
||||||
|
{ |
||||||
|
XmlSchemaCompletionCollection schemas; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
schemas = new XmlSchemaCompletionCollection(); |
||||||
|
foreach (string schema in GetSchemas()) { |
||||||
|
StringReader reader = new StringReader(schema); |
||||||
|
schemas.Add(new XmlSchemaCompletion(reader)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
string[] GetSchemas() |
||||||
|
{ |
||||||
|
return new string[] { GetFooSchema(), GetBarSchema() }; |
||||||
|
} |
||||||
|
|
||||||
|
string GetFooSchema() |
||||||
|
{ |
||||||
|
return |
||||||
|
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"foo\" xmlns=\"foo\" elementFormDefault=\"qualified\">\r\n" + |
||||||
|
" <xs:element name=\"foo-note\">\r\n" + |
||||||
|
" <xs:complexType> \r\n" + |
||||||
|
" <xs:sequence>\r\n" + |
||||||
|
" <xs:element name=\"foo-text\" type=\"text-type\"/>\r\n" + |
||||||
|
" </xs:sequence>\r\n" + |
||||||
|
" </xs:complexType>\r\n" + |
||||||
|
" </xs:element>\r\n" + |
||||||
|
" <xs:complexType name=\"text-type\">\r\n" + |
||||||
|
" <xs:attribute name=\"foo-text-attribute\">\r\n" + |
||||||
|
" <xs:simpleType>\r\n" + |
||||||
|
" <xs:restriction base=\"xs:string\">\r\n" + |
||||||
|
" <xs:enumeration value=\"first\"/>\r\n" + |
||||||
|
" <xs:enumeration value=\"second\"/>\r\n" + |
||||||
|
" <xs:enumeration value=\"third\"/>\r\n" + |
||||||
|
" <xs:enumeration value=\"fourth\"/>\r\n" + |
||||||
|
" </xs:restriction>\r\n" + |
||||||
|
" </xs:simpleType>\r\n" + |
||||||
|
" </xs:attribute>\r\n" + |
||||||
|
" </xs:complexType>\r\n" + |
||||||
|
"</xs:schema>"; |
||||||
|
} |
||||||
|
|
||||||
|
string GetBarSchema() |
||||||
|
{ |
||||||
|
return |
||||||
|
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"bar\" xmlns=\"bar\" elementFormDefault=\"qualified\">\r\n" + |
||||||
|
" <xs:element name=\"bar-note\">\r\n" + |
||||||
|
" <xs:complexType> \r\n" + |
||||||
|
" <xs:sequence>\r\n" + |
||||||
|
" <xs:element name=\"bar-text\" type=\"text-type\"/>\r\n" + |
||||||
|
" </xs:sequence>\r\n" + |
||||||
|
" </xs:complexType>\r\n" + |
||||||
|
" </xs:element>\r\n" + |
||||||
|
" <xs:complexType name=\"text-type\">\r\n" + |
||||||
|
" <xs:attribute name=\"bar-text-attribute\">\r\n" + |
||||||
|
" <xs:simpleType>\r\n" + |
||||||
|
" <xs:restriction base=\"xs:string\">\r\n" + |
||||||
|
" <xs:enumeration value=\"bar-first\"/>\r\n" + |
||||||
|
" <xs:enumeration value=\"bar-second\"/>\r\n" + |
||||||
|
" <xs:enumeration value=\"bar-third\"/>\r\n" + |
||||||
|
" <xs:enumeration value=\"bar-fourth\"/>\r\n" + |
||||||
|
" </xs:restriction>\r\n" + |
||||||
|
" </xs:simpleType>\r\n" + |
||||||
|
" </xs:attribute>\r\n" + |
||||||
|
" </xs:complexType>\r\n" + |
||||||
|
"</xs:schema>"; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void FooSchemaRootElementAndBarRootElementInPath() |
||||||
|
{ |
||||||
|
XmlElementPath path = new XmlElementPath(); |
||||||
|
path.AddElement(new QualifiedName("foo-note", "foo")); |
||||||
|
path.AddElement(new QualifiedName("bar-note", "bar", "b")); |
||||||
|
XmlCompletionItemCollection items = schemas.GetElementCompletionForAllNamespaces(path, null); |
||||||
|
items.Sort(); |
||||||
|
|
||||||
|
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection(); |
||||||
|
expectedItems.Add(new XmlCompletionItem("b:bar-text", XmlCompletionItemType.XmlElement)); |
||||||
|
expectedItems.Add(new XmlCompletionItem("foo-text", XmlCompletionItemType.XmlElement)); |
||||||
|
|
||||||
|
Assert.AreEqual(expectedItems, items); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void FooSchemaElementAndBarElementInXml() |
||||||
|
{ |
||||||
|
string xml = |
||||||
|
"<foo-note xmlns='foo' xmlns:b='bar'>\r\n" + |
||||||
|
" <b:bar-note>\r\n" + |
||||||
|
" <"; |
||||||
|
|
||||||
|
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection(); |
||||||
|
expectedItems.Add(new XmlCompletionItem("b:bar-text", XmlCompletionItemType.XmlElement)); |
||||||
|
expectedItems.Add(new XmlCompletionItem("foo-text", XmlCompletionItemType.XmlElement)); |
||||||
|
|
||||||
|
XmlCompletionItemCollection items = schemas.GetElementCompletion(xml, null); |
||||||
|
items.Sort(); |
||||||
|
|
||||||
|
Assert.AreEqual(expectedItems, items); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void FooSchemaRootElementOnlyInPath() |
||||||
|
{ |
||||||
|
XmlElementPath path = new XmlElementPath(); |
||||||
|
path.NamespacesInScope.Add(new XmlNamespace("b", "bar")); |
||||||
|
path.AddElement(new QualifiedName("foo-note", "foo")); |
||||||
|
|
||||||
|
XmlCompletionItemCollection items = schemas.GetElementCompletionForAllNamespaces(path, null); |
||||||
|
items.Sort(); |
||||||
|
|
||||||
|
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection(); |
||||||
|
expectedItems.Add(new XmlCompletionItem("b:bar-note", XmlCompletionItemType.XmlElement)); |
||||||
|
expectedItems.Add(new XmlCompletionItem("foo-text", XmlCompletionItemType.XmlElement)); |
||||||
|
|
||||||
|
Assert.AreEqual(expectedItems, items); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void UnusedNamespaceInScopeCannotBeFoundInSchemaCollection() |
||||||
|
{ |
||||||
|
XmlElementPath path = new XmlElementPath(); |
||||||
|
path.NamespacesInScope.Add(new XmlNamespace("b", "namespace-which-does-not-exist-in-schema-collection")); |
||||||
|
path.AddElement(new QualifiedName("foo-note", "foo")); |
||||||
|
|
||||||
|
XmlCompletionItemCollection items = schemas.GetElementCompletionForAllNamespaces(path, null); |
||||||
|
items.Sort(); |
||||||
|
|
||||||
|
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection(); |
||||||
|
expectedItems.Add(new XmlCompletionItem("foo-text", XmlCompletionItemType.XmlElement)); |
||||||
|
|
||||||
|
Assert.AreEqual(expectedItems, items); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void DefaultSchemaRootElementsReturnedWhenNoNamespaceExplicitlyDefinedInXmlAndXmlIsEmpty() |
||||||
|
{ |
||||||
|
XmlSchemaCompletion defaultSchema = schemas["foo"]; |
||||||
|
string xml = "<"; |
||||||
|
|
||||||
|
XmlCompletionItemCollection items = schemas.GetElementCompletion(xml, defaultSchema); |
||||||
|
items.Sort(); |
||||||
|
|
||||||
|
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection(); |
||||||
|
expectedItems.Add(new XmlCompletionItem("foo-note", XmlCompletionItemType.XmlElement)); |
||||||
|
|
||||||
|
Assert.AreEqual(expectedItems, items); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void DefaultSchemaRootElementsReturnedOnceWhenNamespaceDefinedButNoElementsExistForthatNamespace() |
||||||
|
{ |
||||||
|
XmlSchemaCompletion defaultSchema = schemas["foo"]; |
||||||
|
string xml = "<b:bar-note xmlns='foo' xmlns:b='bar'><"; |
||||||
|
|
||||||
|
XmlCompletionItemCollection items = schemas.GetElementCompletion(xml, defaultSchema); |
||||||
|
items.Sort(); |
||||||
|
|
||||||
|
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection(); |
||||||
|
expectedItems.Add(new XmlCompletionItem("b:bar-text", XmlCompletionItemType.XmlElement)); |
||||||
|
expectedItems.Add(new XmlCompletionItem("foo-note", XmlCompletionItemType.XmlElement)); |
||||||
|
|
||||||
|
Assert.AreEqual(expectedItems, items); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CorrectAttributesReturnedForElementWhenTwoNamespacesInXml() |
||||||
|
{ |
||||||
|
string xml = |
||||||
|
"<b:bar-note xmlns='foo' xmlns:b='bar'>\r\n" + |
||||||
|
" <foo-note>\r\n" + |
||||||
|
" <b:bar-text/>\r\n" + |
||||||
|
" <foo-text "; |
||||||
|
|
||||||
|
XmlCompletionItemCollection items = schemas.GetAttributeCompletion(xml, null); |
||||||
|
|
||||||
|
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection(); |
||||||
|
expectedItems.Add(new XmlCompletionItem("foo-text-attribute", XmlCompletionItemType.XmlAttribute)); |
||||||
|
|
||||||
|
Assert.AreEqual(expectedItems, items); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void CorrectAttributeValuesReturnedForElementWhenTwoNamespacesInXml() |
||||||
|
{ |
||||||
|
string xml = |
||||||
|
"<b:bar-note xmlns='foo' xmlns:b='bar'>\r\n" + |
||||||
|
" <foo-note>\r\n" + |
||||||
|
" <b:bar-text/>\r\n" + |
||||||
|
" <foo-text foo-text-attribute='f'"; |
||||||
|
|
||||||
|
string xmlUpToCursor = xml.Substring(0, xml.Length - 1); |
||||||
|
|
||||||
|
XmlCompletionItemCollection items = schemas.GetAttributeValueCompletion('f', xmlUpToCursor, null); |
||||||
|
items.Sort(); |
||||||
|
|
||||||
|
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection(); |
||||||
|
expectedItems.Add(new XmlCompletionItem("first", XmlCompletionItemType.XmlAttributeValue)); |
||||||
|
expectedItems.Add(new XmlCompletionItem("fourth", XmlCompletionItemType.XmlAttributeValue)); |
||||||
|
expectedItems.Add(new XmlCompletionItem("second", XmlCompletionItemType.XmlAttributeValue)); |
||||||
|
expectedItems.Add(new XmlCompletionItem("third", XmlCompletionItemType.XmlAttributeValue)); |
||||||
|
|
||||||
|
Assert.AreEqual(expectedItems, items); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue