From 2c64f4131b6f5d39966e7400c7fd232084bdfe9c Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Thu, 13 Apr 2006 16:13:36 +0000 Subject: [PATCH] SD2-758. XML element completion now working for xs:all child elements. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1303 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/XmlSchemaCompletionData.cs | 16 ++++-- .../Test/Parser/AttributeNameTestFixture.cs | 8 ++- .../Test/Schema/AllElementTestFixture.cs | 54 +++++++++++++++++++ .../Test/Schema/XsdSchemaTestFixture.cs | 48 ++++++++++++++++- .../XmlEditor/Test/XmlEditor.Tests.csproj | 1 + 5 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AllElementTestFixture.cs diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionData.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionData.cs index 22123e124d..125dc3b814 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionData.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionData.cs @@ -320,6 +320,7 @@ namespace ICSharpCode.XmlEditor XmlSchemaChoice choice = complexType.Particle as XmlSchemaChoice; XmlSchemaGroupRef groupRef = complexType.Particle as XmlSchemaGroupRef; XmlSchemaComplexContent complexContent = complexType.ContentModel as XmlSchemaComplexContent; + XmlSchemaAll all = complexType.Particle as XmlSchemaAll; if (sequence != null) { data = GetChildElementCompletionData(sequence.Items, prefix); @@ -329,6 +330,8 @@ namespace ICSharpCode.XmlEditor data = GetChildElementCompletionData(complexContent, prefix); } else if (groupRef != null) { data = GetChildElementCompletionData(groupRef, prefix); + } else if (all != null) { + data = GetChildElementCompletionData(all.Items, prefix); } return data; @@ -445,12 +448,15 @@ namespace ICSharpCode.XmlEditor if (restriction.Particle != null) { XmlSchemaSequence sequence = restriction.Particle as XmlSchemaSequence; XmlSchemaChoice choice = restriction.Particle as XmlSchemaChoice; + XmlSchemaGroupRef groupRef = restriction.Particle as XmlSchemaGroupRef; if(sequence != null) { data = GetChildElementCompletionData(sequence.Items, prefix); } else if (choice != null) { data = GetChildElementCompletionData(choice.Items, prefix); - } + } else if (groupRef != null) { + data = GetChildElementCompletionData(groupRef, prefix); + } } return data; @@ -765,7 +771,6 @@ namespace ICSharpCode.XmlEditor return matchedComplexType; } - /// /// Finds an element that matches the specified /// from the children of the given . @@ -847,10 +852,13 @@ namespace ICSharpCode.XmlEditor { XmlSchemaElement matchedElement = null; XmlSchemaSequence sequence = restriction.Particle as XmlSchemaSequence; - + XmlSchemaGroupRef groupRef = restriction.Particle as XmlSchemaGroupRef; + if (sequence != null) { matchedElement = FindElement(sequence.Items, name); - } + } else if (groupRef != null) { + matchedElement = FindElement(groupRef, name); + } return matchedElement; } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeNameTestFixture.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeNameTestFixture.cs index 7b78661b02..a1a3233599 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeNameTestFixture.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeNameTestFixture.cs @@ -86,6 +86,12 @@ namespace XmlEditor.Tests.Parser { string text = " a"; Assert.AreEqual(String.Empty, XmlParser.GetAttributeName(text, text.Length), "Should have retrieved the attribute name 'foo'"); - } + } + + [Test] + public void EmptyString() + { + Assert.AreEqual(String.Empty, XmlParser.GetAttributeName(String.Empty, 10)); + } } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AllElementTestFixture.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AllElementTestFixture.cs new file mode 100644 index 0000000000..4daecf18ea --- /dev/null +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AllElementTestFixture.cs @@ -0,0 +1,54 @@ +// +// +// +// +// $Revision$ +// + +using ICSharpCode.TextEditor.Gui.CompletionWindow; +using ICSharpCode.XmlEditor; +using NUnit.Framework; +using System; +using System.IO; + +namespace XmlEditor.Tests.Schema +{ + /// + /// Tests that element completion works for any child elements + /// inside an xs:all schema element. + /// + [TestFixture] + public class AllElementTestFixture : SchemaTestFixtureBase + { + ICompletionData[] personElementChildren; + + public override void FixtureInit() + { + XmlElementPath path = new XmlElementPath(); + path.Elements.Add(new QualifiedName("person", "http://foo")); + + personElementChildren = SchemaCompletionData.GetChildElementCompletionData(path); + } + + [Test] + public void PersonElementHasTwoChildElements() + { + Assert.AreEqual(2, personElementChildren.Length, + "Should be 2 child elements."); + } + + protected override string GetSchema() + { + return "\r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + ""; + } + } +} diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Schema/XsdSchemaTestFixture.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Schema/XsdSchemaTestFixture.cs index feb04b9708..8cac5bfbda 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Test/Schema/XsdSchemaTestFixture.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Schema/XsdSchemaTestFixture.cs @@ -26,6 +26,8 @@ namespace XmlEditor.Tests.Schema XmlElementPath elementPath; XmlElementPath simpleEnumPath; XmlElementPath enumPath; + XmlElementPath allElementPath; + XmlElementPath allElementAnnotationPath; ICompletionData[] choiceAttributes; ICompletionData[] elementAttributes; ICompletionData[] simpleEnumElements; @@ -35,6 +37,8 @@ namespace XmlEditor.Tests.Schema ICompletionData[] finalDefaultAttributeValues; ICompletionData[] mixedAttributeValues; ICompletionData[] maxOccursAttributeValues; + ICompletionData[] allElementChildElements; + ICompletionData[] allElementAnnotationChildElements; string namespaceURI = "http://www.w3.org/2001/XMLSchema"; string prefix = "xs"; @@ -90,6 +94,27 @@ namespace XmlEditor.Tests.Schema // Get attributes. enumAttributes = schemaCompletionData.GetAttributeCompletionData(enumPath); + + // Set up xs:all path. + allElementPath = new XmlElementPath(); + allElementPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix)); + allElementPath.Elements.Add(new QualifiedName("element", namespaceURI, prefix)); + allElementPath.Elements.Add(new QualifiedName("complexType", namespaceURI, prefix)); + allElementPath.Elements.Add(new QualifiedName("all", namespaceURI, prefix)); + + // Get child elements of the xs:all element. + allElementChildElements = schemaCompletionData.GetChildElementCompletionData(allElementPath); + + // Set up the path to the annotation element that is a child of xs:all. + allElementAnnotationPath = new XmlElementPath(); + allElementAnnotationPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix)); + allElementAnnotationPath.Elements.Add(new QualifiedName("element", namespaceURI, prefix)); + allElementAnnotationPath.Elements.Add(new QualifiedName("complexType", namespaceURI, prefix)); + allElementAnnotationPath.Elements.Add(new QualifiedName("all", namespaceURI, prefix)); + allElementAnnotationPath.Elements.Add(new QualifiedName("annotation", namespaceURI, prefix)); + + // Get the xs:all annotation child element. + allElementAnnotationChildElements = schemaCompletionData.GetChildElementCompletionData(allElementAnnotationPath); } [Test] @@ -206,6 +231,27 @@ namespace XmlEditor.Tests.Schema { Assert.IsTrue(SchemaTestFixtureBase.Contains(maxOccursAttributeValues, "unbounded"), "Attribute value 'unbounded' missing."); - } + } + + [Test] + public void AllElementHasAnnotationChildElement() + { + Assert.IsTrue(SchemaTestFixtureBase.Contains(allElementChildElements, "xs:annotation"), + "Should have an annotation child element."); + } + + [Test] + public void AllElementHasElementChildElement() + { + Assert.IsTrue(SchemaTestFixtureBase.Contains(allElementChildElements, "xs:element"), + "Should have an child element called 'element'."); + } + + [Test] + public void AllElementAnnotationHasDocumentationChildElement() + { + Assert.IsTrue(SchemaTestFixtureBase.Contains(allElementAnnotationChildElements, "xs:documentation"), + "Should have documentation child element."); + } } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj b/src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj index 20c7df8aea..ef15e95782 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj @@ -90,6 +90,7 @@ +