Browse Source

Fix XML attribute value completion with union member types.

<xs:union memberTypes="YesNoType Preprocessor"/>
pull/30/head
Matt Ward 13 years ago
parent
commit
e27c96cb31
  1. 8
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletion.cs
  2. 63
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/InvalidUnionMemberTypesTests.cs
  3. 65
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/UnionMemberTypesTests.cs
  4. 2
      src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

8
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletion.cs

@ -1014,7 +1014,13 @@ namespace ICSharpCode.XmlEditor @@ -1014,7 +1014,13 @@ namespace ICSharpCode.XmlEditor
completionItems.AddRange(GetAttributeValueCompletion(simpleType));
}
}
if (union.BaseMemberTypes != null) {
foreach (XmlSchemaSimpleType simpleType in union.BaseMemberTypes) {
completionItems.AddRange(GetAttributeValueCompletion(simpleType));
}
}
return completionItems;
}

63
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/InvalidUnionMemberTypesTests.cs

@ -0,0 +1,63 @@ @@ -0,0 +1,63 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
namespace XmlEditor.Tests.Schema
{
/// <summary>
/// Tests that a null reference exception is not thrown when
/// a xs:union memberTypes attribute is set which points to an unknown type.
/// </summary>
[TestFixture]
public class InvalidUnionMemberTypesTests : SchemaTestFixtureBase
{
const string namespaceURI = "http://schemas.microsoft.com/wix/2006/wi";
const string prefix = "w";
protected override string GetSchema()
{
return
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" \r\n" +
" xmlns:xse=\"http://schemas.microsoft.com/wix/2005/XmlSchemaExtension\" \r\n" +
" xmlns:html=\"http://www.w3.org/1999/xhtml\" \r\n" +
" targetNamespace=\"http://schemas.microsoft.com/wix/2006/wi\" \r\n" +
" xmlns=\"http://schemas.microsoft.com/wix/2006/wi\">\r\n" +
" <xs:element name=\"Component\">\r\n" +
" <xs:complexType>\r\n" +
" <xs:attribute name=\"KeyPath\" type=\"YesNoTypeUnion\">\r\n" +
" </xs:attribute>\r\n" +
" </xs:complexType>\r\n" +
" </xs:element>\r\n" +
" <xs:simpleType name=\"YesNoTypeUnion\">\r\n" +
" <xs:union memberTypes=\"YesNoType UNKNOWN\"/>\r\n" +
" </xs:simpleType>\r\n" +
" <xs:simpleType name=\"YesNoType\">\r\n" +
" <xs:restriction base=\"xs:NMTOKEN\">\r\n" +
" <xs:enumeration value=\"no\" />\r\n" +
" <xs:enumeration value=\"yes\" />\r\n" +
" </xs:restriction>\r\n" +
" </xs:simpleType>\r\n" +
" <xs:simpleType name=\"Another\">\r\n" +
" <xs:restriction base=\"xs:string\">\r\n" +
" <xs:enumeration value=\"1\" />\r\n" +
" <xs:enumeration value=\"0\" />\r\n" +
" </xs:restriction>\r\n" +
" </xs:simpleType>\r\n" +
"</xs:schema>";
}
[Test]
public void GetAttributeValueCompletion_UnionMemberTypesJoinsTwoSimpleTypesButOneDoesNotExist_DoesNotThrowException()
{
var path = new XmlElementPath();
path.AddElement(new QualifiedName("Component", namespaceURI));
XmlCompletionItemCollection items = SchemaCompletion.GetAttributeValueCompletion(path, "KeyPath");
Assert.AreEqual(0, items.Count);
}
}
}

65
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/UnionMemberTypesTests.cs

@ -0,0 +1,65 @@ @@ -0,0 +1,65 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
namespace XmlEditor.Tests.Schema
{
/// <summary>
/// Tests that attribute completion works for union member types:
/// &lt;xs:union memberTypes="YesNoType PreprocessorVariables"/&gt;
/// </summary>
[TestFixture]
public class UnionMemberTypesTests : SchemaTestFixtureBase
{
const string namespaceURI = "http://schemas.microsoft.com/wix/2006/wi";
const string prefix = "w";
protected override string GetSchema()
{
return
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" \r\n" +
" xmlns:xse=\"http://schemas.microsoft.com/wix/2005/XmlSchemaExtension\" \r\n" +
" xmlns:html=\"http://www.w3.org/1999/xhtml\" \r\n" +
" targetNamespace=\"http://schemas.microsoft.com/wix/2006/wi\" \r\n" +
" xmlns=\"http://schemas.microsoft.com/wix/2006/wi\">\r\n" +
" <xs:element name=\"Component\">\r\n" +
" <xs:complexType>\r\n" +
" <xs:attribute name=\"KeyPath\" type=\"YesNoTypeUnion\">\r\n" +
" </xs:attribute>\r\n" +
" </xs:complexType>\r\n" +
" </xs:element>\r\n" +
" <xs:simpleType name=\"YesNoTypeUnion\">\r\n" +
" <xs:union memberTypes=\"YesNoType Another\"/>\r\n" +
" </xs:simpleType>\r\n" +
" <xs:simpleType name=\"YesNoType\">\r\n" +
" <xs:restriction base=\"xs:NMTOKEN\">\r\n" +
" <xs:enumeration value=\"no\" />\r\n" +
" <xs:enumeration value=\"yes\" />\r\n" +
" </xs:restriction>\r\n" +
" </xs:simpleType>\r\n" +
" <xs:simpleType name=\"Another\">\r\n" +
" <xs:restriction base=\"xs:string\">\r\n" +
" <xs:enumeration value=\"1\" />\r\n" +
" <xs:enumeration value=\"0\" />\r\n" +
" </xs:restriction>\r\n" +
" </xs:simpleType>\r\n" +
"</xs:schema>";
}
[Test]
public void GetAttributeValueCompletion_UnionMemberTypesJoinsTwoSimpleTypes_ReturnsUnionOfSimpleTypes()
{
var path = new XmlElementPath();
path.AddElement(new QualifiedName("Component", namespaceURI));
XmlCompletionItemCollection items = SchemaCompletion.GetAttributeValueCompletion(path, "KeyPath");
Assert.AreEqual(4, items.Count);
Assert.IsTrue(items.Contains("yes"));
Assert.IsTrue(items.Contains("1"));
}
}
}

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

@ -162,6 +162,7 @@ @@ -162,6 +162,7 @@
<Compile Include="Schema.Multiple\DuplicateSchemaNamespaceAddedToCollectionTestFixture.cs" />
<Compile Include="Schema.Multiple\TwoSchemaChildElementCompletionTestFixture.cs" />
<Compile Include="Schema\ElementAnnotationWithWhitespaceTestFixture.cs" />
<Compile Include="Schema\InvalidUnionMemberTypesTests.cs" />
<Compile Include="Schema\SchemaHasNamespaceTests.cs" />
<Compile Include="Schema\SimpleContentExtensionBaseTypeWithAttributeTestFixture.cs" />
<Compile Include="Schema\SingleElementSchemaTestFixture.cs" />
@ -190,6 +191,7 @@ @@ -190,6 +191,7 @@
<Compile Include="Paths\TwoElementPathTestFixture.cs" />
<Compile Include="Schema\NestedChoiceTestFixture.cs" />
<Compile Include="Schema\ChildElementAttributesTestFixture.cs" />
<Compile Include="Schema\UnionMemberTypesTests.cs" />
<Compile Include="Tree\AddChildTextNodeTestFixture.cs" />
<Compile Include="Tree\AddNewNodeDialogTestFixture.cs" />
<Compile Include="Tree\DeleteTreeNodeWithDeleteKeyTestFixture.cs" />

Loading…
Cancel
Save