Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1683 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
34 changed files with 1940 additions and 238 deletions
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
// <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.Windows.Forms; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Finds the definition of the Xml element or attribute under the cursor,
|
||||
/// finds the schema definition for it and then opens the schema and puts the cursor
|
||||
/// on the definition.
|
||||
/// </summary>
|
||||
public class GoToSchemaDefinitionCommand : AbstractMenuCommand |
||||
{ |
||||
public override void Run() |
||||
{ |
||||
XmlView view = XmlView.ActiveXmlView; |
||||
if (view != null) { |
||||
view.GoToSchemaDefinition(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
// <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.TextEditor; |
||||
using ICSharpCode.TextEditor.Actions; |
||||
using System; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Finds the schema definition of the Xml element or attribute under the cursor
|
||||
/// when the user presses Control+Enter
|
||||
/// </summary>
|
||||
public class GoToSchemaDefinitionEditAction : AbstractEditAction |
||||
{ |
||||
public override void Execute(TextArea services) |
||||
{ |
||||
GoToSchemaDefinitionCommand goToDefinitionCommand = new GoToSchemaDefinitionCommand(); |
||||
goToDefinitionCommand.Run(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
// <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.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml.Schema; |
||||
using XmlEditor.Tests.Schema; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.FindSchemaObject |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that an xs:attributeGroup/@ref is located in the schema.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class AttributeGroupReferenceSelectedTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaAttributeGroup schemaAttributeGroup; |
||||
|
||||
public override void FixtureInit() |
||||
{ |
||||
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); |
||||
schemas.Add(SchemaCompletionData); |
||||
XmlSchemaCompletionData xsdSchemaCompletionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema()); |
||||
schemas.Add(xsdSchemaCompletionData); |
||||
XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xsdSchemaCompletionData, String.Empty); |
||||
|
||||
string xml = GetSchema(); |
||||
int index = xml.IndexOf("ref=\"coreattrs\""); |
||||
index = xml.IndexOf("coreattrs", index); |
||||
schemaAttributeGroup = (XmlSchemaAttributeGroup)XmlView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeGroupName() |
||||
{ |
||||
Assert.AreEqual("coreattrs", schemaAttributeGroup.QualifiedName.Name); |
||||
} |
||||
|
||||
protected override string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
"<xs:attributeGroup name=\"coreattrs\">" + |
||||
"\t<xs:attribute name=\"id\" type=\"xs:string\"/>" + |
||||
"\t<xs:attribute name=\"style\" type=\"xs:string\"/>" + |
||||
"\t<xs:attribute name=\"title\" type=\"xs:string\"/>" + |
||||
"</xs:attributeGroup>" + |
||||
"\t<xs:element name=\"note\">\r\n" + |
||||
"\t\t<xs:complexType>\r\n" + |
||||
"\t\t\t<xs:attributeGroup ref=\"coreattrs\"/>" + |
||||
"\t\t\t<xs:attribute name=\"name\" type=\"xs:string\"/>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
// <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.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml.Schema; |
||||
using XmlEditor.Tests.Schema; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.FindSchemaObject |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that an xs:attribute/@ref is located in the schema.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class AttributeReferenceSelectedTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaAttribute schemaAttribute; |
||||
|
||||
public override void FixtureInit() |
||||
{ |
||||
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); |
||||
schemas.Add(SchemaCompletionData); |
||||
XmlSchemaCompletionData xsdSchemaCompletionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema()); |
||||
schemas.Add(xsdSchemaCompletionData); |
||||
XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xsdSchemaCompletionData, String.Empty); |
||||
|
||||
string xml = GetSchema(); |
||||
int index = xml.IndexOf("ref=\"dir\""); |
||||
index = xml.IndexOf("dir", index); |
||||
schemaAttribute = (XmlSchemaAttribute)XmlView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeName() |
||||
{ |
||||
Assert.AreEqual("dir", schemaAttribute.QualifiedName.Name); |
||||
} |
||||
|
||||
protected override string GetSchema() |
||||
{ |
||||
return "<xs:schema version=\"1.0\" xml:lang=\"en\"\r\n" + |
||||
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\r\n" + |
||||
" targetNamespace=\"http://foo/xhtml\"\r\n" + |
||||
" xmlns=\"http://foo/xhtml\"\r\n" + |
||||
" elementFormDefault=\"qualified\">\r\n" + |
||||
" <xs:element name=\"html\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:element ref=\"head\"/>\r\n" + |
||||
" <xs:element ref=\"body\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:attributeGroup ref=\"i18n\"/>\r\n" + |
||||
" <xs:attribute name=\"id\" ref=\"dir\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"head\" type=\"xs:string\"/>\r\n" + |
||||
" <xs:element name=\"body\" type=\"xs:string\"/>\r\n" + |
||||
"\r\n" + |
||||
" <xs:attribute name=\"dir\">\r\n" + |
||||
" <xs:simpleType>\r\n" + |
||||
" <xs:restriction base=\"xs:token\">\r\n" + |
||||
" <xs:enumeration value=\"ltr\"/>\r\n" + |
||||
" <xs:enumeration value=\"rtl\"/>\r\n" + |
||||
" </xs:restriction>\r\n" + |
||||
" </xs:simpleType>\r\n" + |
||||
" </xs:attribute>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
// <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.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml.Schema; |
||||
using XmlEditor.Tests.Schema; |
||||
|
||||
namespace XmlEditor.Tests.FindSchemaObject |
||||
{ |
||||
[TestFixture] |
||||
public class AttributeSelectedTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaAttribute schemaAttribute; |
||||
|
||||
public override void FixtureInit() |
||||
{ |
||||
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); |
||||
schemas.Add(SchemaCompletionData); |
||||
XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, SchemaCompletionData, String.Empty); |
||||
string xml = "<note xmlns='http://www.w3schools.com' name=''></note>"; |
||||
schemaAttribute = (XmlSchemaAttribute)XmlView.GetSchemaObjectSelected(xml, xml.IndexOf("name"), provider); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeName() |
||||
{ |
||||
Assert.AreEqual("name", schemaAttribute.QualifiedName.Name, "Attribute name is incorrect."); |
||||
} |
||||
|
||||
protected override string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
" <xs:element name=\"note\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
"\t<xs:attribute name=\"name\" type=\"xs:string\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,77 @@
@@ -0,0 +1,77 @@
|
||||
// <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.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml.Schema; |
||||
using XmlEditor.Tests.Schema; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.FindSchemaObject |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that a xs:attribute/@type can be located in the schema.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class AttributeTypeSelectedTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaSimpleType schemaSimpleType; |
||||
|
||||
public override void FixtureInit() |
||||
{ |
||||
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); |
||||
schemas.Add(SchemaCompletionData); |
||||
XmlSchemaCompletionData xsdSchemaCompletionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema()); |
||||
schemas.Add(xsdSchemaCompletionData); |
||||
XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xsdSchemaCompletionData, String.Empty); |
||||
|
||||
string xml = GetSchema(); |
||||
int index = xml.IndexOf("type=\"dir\"/>"); |
||||
index = xml.IndexOf("dir", index); |
||||
schemaSimpleType = (XmlSchemaSimpleType)XmlView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleTypeName() |
||||
{ |
||||
Assert.AreEqual("dir", schemaSimpleType.QualifiedName.Name); |
||||
} |
||||
|
||||
protected override string GetSchema() |
||||
{ |
||||
return "<xs:schema version=\"1.0\" xml:lang=\"en\"\r\n" + |
||||
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\r\n" + |
||||
" targetNamespace=\"http://foo/xhtml\"\r\n" + |
||||
" xmlns=\"http://foo/xhtml\"\r\n" + |
||||
" elementFormDefault=\"qualified\">\r\n" + |
||||
" <xs:element name=\"html\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:element ref=\"head\"/>\r\n" + |
||||
" <xs:element ref=\"body\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:attributeGroup ref=\"i18n\"/>\r\n" + |
||||
" <xs:attribute name=\"id\" type=\"dir\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"head\" type=\"xs:string\"/>\r\n" + |
||||
" <xs:element name=\"body\" type=\"xs:string\"/>\r\n" + |
||||
"\r\n" + |
||||
" <xs:simpleType name=\"dir\">\r\n" + |
||||
" <xs:restriction base=\"xs:token\">\r\n" + |
||||
" <xs:enumeration value=\"ltr\"/>\r\n" + |
||||
" <xs:enumeration value=\"rtl\"/>\r\n" + |
||||
" </xs:restriction>\r\n" + |
||||
" </xs:simpleType>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,87 @@
@@ -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 ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml.Schema; |
||||
using XmlEditor.Tests.Schema; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.FindSchemaObject |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that an xs:element/@ref is located in the schema.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ElementReferenceSelectedTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaAttribute schemaAttribute; |
||||
XmlSchemaElement referencedSchemaElement; |
||||
|
||||
public override void FixtureInit() |
||||
{ |
||||
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); |
||||
schemas.Add(SchemaCompletionData); |
||||
XmlSchemaCompletionData xsdSchemaCompletionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema()); |
||||
schemas.Add(xsdSchemaCompletionData); |
||||
XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xsdSchemaCompletionData, String.Empty); |
||||
|
||||
string xml = GetSchema(); |
||||
schemaAttribute = (XmlSchemaAttribute)XmlView.GetSchemaObjectSelected(xml, xml.IndexOf("ref=\"name"), provider, SchemaCompletionData); |
||||
|
||||
int index = xml.IndexOf("ref=\"name"); |
||||
index = xml.IndexOf('n', index); |
||||
referencedSchemaElement = (XmlSchemaElement)XmlView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeName() |
||||
{ |
||||
Assert.AreEqual("ref", schemaAttribute.QualifiedName.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReferencedElementName() |
||||
{ |
||||
Assert.AreEqual("name", referencedSchemaElement.QualifiedName.Name); |
||||
} |
||||
|
||||
protected override string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\">\r\n" + |
||||
"\r\n" + |
||||
"<!-- definition of simple elements -->\r\n" + |
||||
"<xs:element name=\"name\" type=\"xs:string\"/>\r\n" + |
||||
"<xs:element name=\"address\" type=\"xs:string\"/>\r\n" + |
||||
"\r\n" + |
||||
"<!-- definition of complex elements -->\r\n" + |
||||
"<xs:element name=\"shipto\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:element ref=\"name\"/>\r\n" + |
||||
" <xs:element ref=\"address\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:attribute name=\"address\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
"</xs:element>\r\n" + |
||||
"\r\n" + |
||||
"<xs:element name=\"shiporder\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:element ref=\"shipto\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:attribute name=\"id\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
"</xs:element>\r\n" + |
||||
"\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,85 @@
@@ -0,0 +1,85 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml.Schema; |
||||
using XmlEditor.Tests.Schema; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.FindSchemaObject |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that an xs:element/@ref='prefix:name' is located in the schema.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ElementReferenceWithPrefixSelectedTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaElement referencedSchemaElement; |
||||
|
||||
public override void FixtureInit() |
||||
{ |
||||
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); |
||||
schemas.Add(SchemaCompletionData); |
||||
XmlSchemaCompletionData xsdSchemaCompletionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema()); |
||||
schemas.Add(xsdSchemaCompletionData); |
||||
XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xsdSchemaCompletionData, String.Empty); |
||||
|
||||
string xml = GetSchema(); |
||||
|
||||
int index = xml.IndexOf("ref=\"xs:list"); |
||||
index = xml.IndexOf("xs", index); |
||||
referencedSchemaElement = (XmlSchemaElement)XmlView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReferencedElementName() |
||||
{ |
||||
Assert.AreEqual("list", referencedSchemaElement.QualifiedName.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReferencedElementNamespace() |
||||
{ |
||||
Assert.AreEqual("http://www.w3.org/2001/XMLSchema", referencedSchemaElement.QualifiedName.Namespace); |
||||
} |
||||
|
||||
protected override string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\">\r\n" + |
||||
"\r\n" + |
||||
"<!-- definition of simple elements -->\r\n" + |
||||
"<xs:element name=\"name\" type=\"xs:string\"/>\r\n" + |
||||
"<xs:element name=\"address\" type=\"xs:string\"/>\r\n" + |
||||
"\r\n" + |
||||
"<!-- definition of complex elements -->\r\n" + |
||||
"<xs:element name=\"shipto\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:element ref=\"name\"/>\r\n" + |
||||
" <xs:element ref=\"xs:list\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:attribute name=\"address\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
"</xs:element>\r\n" + |
||||
"\r\n" + |
||||
"<xs:element name=\"shiporder\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:element ref=\"shipto\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" <xs:attribute name=\"id\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
"</xs:element>\r\n" + |
||||
"\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml.Schema; |
||||
using XmlEditor.Tests.Schema; |
||||
|
||||
namespace XmlEditor.Tests.FindSchemaObject |
||||
{ |
||||
[TestFixture] |
||||
public class ElementSelectedTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaElement schemaElement; |
||||
|
||||
public override void FixtureInit() |
||||
{ |
||||
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); |
||||
schemas.Add(SchemaCompletionData); |
||||
XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, SchemaCompletionData, String.Empty); |
||||
string xml = "<note xmlns='http://www.w3schools.com'></note>"; |
||||
schemaElement = (XmlSchemaElement)XmlView.GetSchemaObjectSelected(xml, xml.IndexOf("note xmlns"), provider); |
||||
} |
||||
|
||||
[Test] |
||||
public void SchemaElementNamespace() |
||||
{ |
||||
Assert.AreEqual("http://www.w3schools.com", |
||||
schemaElement.QualifiedName.Namespace, |
||||
"Unexpected namespace."); |
||||
} |
||||
|
||||
[Test] |
||||
public void SchemaElementName() |
||||
{ |
||||
Assert.AreEqual("note", schemaElement.QualifiedName.Name); |
||||
} |
||||
|
||||
protected override string GetSchema() |
||||
{ |
||||
return "<?xml version=\"1.0\"?>\r\n" + |
||||
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\r\n" + |
||||
"targetNamespace=\"http://www.w3schools.com\"\r\n" + |
||||
"xmlns=\"http://www.w3schools.com\"\r\n" + |
||||
"elementFormDefault=\"qualified\">\r\n" + |
||||
"<xs:element name=\"note\">\r\n" + |
||||
"</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,63 @@
@@ -0,0 +1,63 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml.Schema; |
||||
using XmlEditor.Tests.Schema; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.FindSchemaObject |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that an xs:element/@type is located in the schema.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ElementTypeSelectedTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaComplexType schemaComplexType; |
||||
|
||||
public override void FixtureInit() |
||||
{ |
||||
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); |
||||
schemas.Add(SchemaCompletionData); |
||||
XmlSchemaCompletionData xsdSchemaCompletionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema()); |
||||
schemas.Add(xsdSchemaCompletionData); |
||||
XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xsdSchemaCompletionData, String.Empty); |
||||
|
||||
string xml = GetSchema(); |
||||
int index = xml.IndexOf("type=\"text-type\""); |
||||
index = xml.IndexOf("text-type", index); |
||||
schemaComplexType = (XmlSchemaComplexType)XmlView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData); |
||||
} |
||||
|
||||
[Test] |
||||
public void ComplexTypeName() |
||||
{ |
||||
Assert.AreEqual("text-type", schemaComplexType.QualifiedName.Name); |
||||
} |
||||
|
||||
protected override string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
"\t<xs:element name=\"note\">\r\n" + |
||||
"\t\t<xs:complexType> \r\n" + |
||||
"\t\t\t<xs:sequence>\r\n" + |
||||
"\t\t\t\t<xs:element name=\"text\" type=\"text-type\"/>\r\n" + |
||||
"\t\t\t</xs:sequence>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"\t<xs:complexType name=\"text-type\">\r\n" + |
||||
"\t\t<xs:attribute name=\"foo\"/>\r\n" + |
||||
"\t</xs:complexType>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -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 ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml.Schema; |
||||
using XmlEditor.Tests.Schema; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.FindSchemaObject |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that an xs:element/@type="prefix:name" is located in the schema.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ElementTypeWithPrefixSelectedTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaComplexType schemaComplexType; |
||||
|
||||
public override void FixtureInit() |
||||
{ |
||||
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); |
||||
schemas.Add(SchemaCompletionData); |
||||
XmlSchemaCompletionData xsdSchemaCompletionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema()); |
||||
schemas.Add(xsdSchemaCompletionData); |
||||
XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xsdSchemaCompletionData, String.Empty); |
||||
|
||||
string xml = GetSchema(); |
||||
int index = xml.IndexOf("type=\"xs:complexType\""); |
||||
index = xml.IndexOf("xs:complexType", index); |
||||
schemaComplexType = (XmlSchemaComplexType)XmlView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData); |
||||
} |
||||
|
||||
[Test] |
||||
public void ComplexTypeName() |
||||
{ |
||||
Assert.AreEqual("complexType", schemaComplexType.QualifiedName.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void ComplexTypeNamespace() |
||||
{ |
||||
Assert.AreEqual("http://www.w3.org/2001/XMLSchema", schemaComplexType.QualifiedName.Namespace); |
||||
} |
||||
|
||||
protected override string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
"\t<xs:element name=\"note\">\r\n" + |
||||
"\t\t<xs:complexType> \r\n" + |
||||
"\t\t\t<xs:sequence>\r\n" + |
||||
"\t\t\t\t<xs:element name=\"text\" type=\"xs:complexType\"/>\r\n" + |
||||
"\t\t\t</xs:sequence>\r\n" + |
||||
"\t\t</xs:complexType>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,98 @@
@@ -0,0 +1,98 @@
|
||||
// <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.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml.Schema; |
||||
using XmlEditor.Tests.Schema; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.FindSchemaObject |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that an xs:group/@ref is located in the schema.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class GroupReferenceSelectedTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaGroup schemaGroup; |
||||
|
||||
public override void FixtureInit() |
||||
{ |
||||
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); |
||||
schemas.Add(SchemaCompletionData); |
||||
XmlSchemaCompletionData xsdSchemaCompletionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema()); |
||||
schemas.Add(xsdSchemaCompletionData); |
||||
XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xsdSchemaCompletionData, String.Empty); |
||||
|
||||
string xml = GetSchema(); |
||||
int index = xml.IndexOf("ref=\"block\""); |
||||
index = xml.IndexOf("block", index); |
||||
schemaGroup = (XmlSchemaGroup)XmlView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData); |
||||
} |
||||
|
||||
[Test] |
||||
public void GroupName() |
||||
{ |
||||
Assert.AreEqual("block", schemaGroup.QualifiedName.Name); |
||||
} |
||||
|
||||
protected override string GetSchema() |
||||
{ |
||||
return "<xs:schema version=\"1.0\" xml:lang=\"en\"\r\n" + |
||||
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\r\n" + |
||||
" targetNamespace=\"http://foo/xhtml\"\r\n" + |
||||
" xmlns=\"http://foo/xhtml\"\r\n" + |
||||
" elementFormDefault=\"qualified\">\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"html\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:element ref=\"head\"/>\r\n" + |
||||
" <xs:element ref=\"body\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"head\" type=\"xs:string\"/>\r\n" + |
||||
" <xs:element name=\"body\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:sequence>\r\n" + |
||||
" <xs:group ref=\"block\"/>\r\n" + |
||||
" <xs:element name=\"form\"/>\r\n" + |
||||
" </xs:sequence>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
"\r\n" + |
||||
" <xs:group name=\"block\">\r\n" + |
||||
" <xs:choice>\r\n" + |
||||
" <xs:element ref=\"p\"/>\r\n" + |
||||
" <xs:group ref=\"heading\"/>\r\n" + |
||||
" </xs:choice>\r\n" + |
||||
" </xs:group>\r\n" + |
||||
"\r\n" + |
||||
" <xs:element name=\"p\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
" <xs:attribute name=\"id\"/>" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"\r\n" + |
||||
" <xs:group name=\"heading\">\r\n" + |
||||
" <xs:choice>\r\n" + |
||||
" <xs:element name=\"test\"/>\r\n" + |
||||
" <xs:element name=\"id\"/>\r\n" + |
||||
" </xs:choice>\r\n" + |
||||
" </xs:group>\r\n" + |
||||
"\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,170 @@
@@ -0,0 +1,170 @@
|
||||
// <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.Xml; |
||||
|
||||
namespace XmlEditor.Tests.Parser |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the XmlParser.GetActiveElementStartPathAtIndex which finds the element
|
||||
/// path where the index is at. The index may be in the middle or start of the element
|
||||
/// tag.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ActiveElementUnderCursorTests |
||||
{ |
||||
XmlElementPath elementPath; |
||||
XmlElementPath expectedElementPath; |
||||
string namespaceURI = "http://foo.com/foo.xsd"; |
||||
|
||||
[Test] |
||||
public void PathTest1() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "'><bar "; |
||||
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("bar ")); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); |
||||
Assert.IsTrue(elementPath.Equals(expectedElementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void PathTest2() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "'><bar>"; |
||||
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("bar>")); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); |
||||
Assert.IsTrue(elementPath.Equals(expectedElementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void PathTest3() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "'><bar>"; |
||||
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("ar>")); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); |
||||
Assert.IsTrue(elementPath.Equals(expectedElementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void PathTest4() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "'><bar>"; |
||||
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length - 1); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); |
||||
Assert.IsTrue(elementPath.Equals(expectedElementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void PathTest5() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "'><bar a='a'>"; |
||||
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("='a'")); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); |
||||
Assert.IsTrue(elementPath.Equals(expectedElementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void PathTest6() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "'><bar a='a'"; |
||||
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length - 1); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); |
||||
Assert.IsTrue(elementPath.Equals(expectedElementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void PathTest7() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "'><bar a='a'"; |
||||
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); |
||||
Assert.IsTrue(elementPath.Equals(expectedElementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void PathTest8() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "'><bar>"; |
||||
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); |
||||
Assert.IsTrue(elementPath.Equals(expectedElementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void PathTest9() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "'><bar "; |
||||
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); |
||||
Assert.IsTrue(elementPath.Equals(expectedElementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void PathTest10() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "'><bar Id=\r\n</foo>"; |
||||
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("Id=")); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI)); |
||||
Assert.IsTrue(elementPath.Equals(expectedElementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
[Test] |
||||
public void PathTest11() |
||||
{ |
||||
string text = "<foo xmlns='" + namespaceURI + "'>"; |
||||
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, 2); |
||||
|
||||
expectedElementPath = new XmlElementPath(); |
||||
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI)); |
||||
Assert.IsTrue(elementPath.Equals(expectedElementPath), |
||||
"Incorrect active element path."); |
||||
} |
||||
|
||||
} |
||||
} |
@ -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 ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
|
||||
namespace XmlEditor.Tests.Parser |
||||
{ |
||||
[TestFixture] |
||||
public class AttributeNameUnderCursorTests |
||||
{ |
||||
[Test] |
||||
public void SuccessTest1() |
||||
{ |
||||
string text = "<a foo"; |
||||
Assert.AreEqual("foo", XmlParser.GetAttributeNameAtIndex(text, text.Length)); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest2() |
||||
{ |
||||
string text = "<a foo"; |
||||
Assert.AreEqual("foo", XmlParser.GetAttributeNameAtIndex(text, text.IndexOf("foo"))); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest3() |
||||
{ |
||||
string text = "<a foo"; |
||||
Assert.AreEqual("foo", XmlParser.GetAttributeNameAtIndex(text, text.IndexOf("oo"))); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest4() |
||||
{ |
||||
string text = "<a foo"; |
||||
Assert.AreEqual("foo", XmlParser.GetAttributeNameAtIndex(text, text.Length - 2)); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest5() |
||||
{ |
||||
string text = "<a foo="; |
||||
Assert.AreEqual("foo", XmlParser.GetAttributeNameAtIndex(text, 3)); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest6() |
||||
{ |
||||
string text = "<a foo="; |
||||
Assert.AreEqual("foo", XmlParser.GetAttributeNameAtIndex(text, text.Length)); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest7() |
||||
{ |
||||
string text = "<a foo='"; |
||||
Assert.AreEqual("foo", XmlParser.GetAttributeNameAtIndex(text, text.Length)); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest8() |
||||
{ |
||||
string text = "<a type='a"; |
||||
Assert.AreEqual("type", XmlParser.GetAttributeNameAtIndex(text, text.Length)); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest9() |
||||
{ |
||||
string text = "<a type='a'"; |
||||
Assert.AreEqual("type", XmlParser.GetAttributeNameAtIndex(text, text.Length - 1)); |
||||
} |
||||
} |
||||
} |
@ -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 ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
|
||||
namespace XmlEditor.Tests.Parser |
||||
{ |
||||
[TestFixture] |
||||
public class AttributeValueUnderCursorTests |
||||
{ |
||||
[Test] |
||||
public void SuccessTest1() |
||||
{ |
||||
string text = "<a foo='abc'"; |
||||
Assert.AreEqual("abc", XmlParser.GetAttributeValueAtIndex(text, text.Length - 1)); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest2() |
||||
{ |
||||
string text = "<a foo=\"abc\""; |
||||
Assert.AreEqual("abc", XmlParser.GetAttributeValueAtIndex(text, text.Length - 1)); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest3() |
||||
{ |
||||
string text = "<a foo='abc'"; |
||||
Assert.AreEqual("abc", XmlParser.GetAttributeValueAtIndex(text, text.Length - 2)); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest4() |
||||
{ |
||||
string text = "<a foo='abc'"; |
||||
Assert.AreEqual("abc", XmlParser.GetAttributeValueAtIndex(text, text.IndexOf("abc"))); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest5() |
||||
{ |
||||
string text = "<a foo=''"; |
||||
Assert.AreEqual(String.Empty, XmlParser.GetAttributeValueAtIndex(text, text.Length - 1)); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest6() |
||||
{ |
||||
string text = "<a foo='a'"; |
||||
Assert.AreEqual("a", XmlParser.GetAttributeValueAtIndex(text, text.Length - 1)); |
||||
} |
||||
|
||||
[Test] |
||||
public void SuccessTest7() |
||||
{ |
||||
string text = "<a foo='a\"b\"c'"; |
||||
Assert.AreEqual("a\"b\"c", XmlParser.GetAttributeValueAtIndex(text, text.Length - 1)); |
||||
} |
||||
|
||||
[Test] |
||||
public void FailureTest1() |
||||
{ |
||||
string text = "<a foo='a"; |
||||
Assert.AreEqual(String.Empty, XmlParser.GetAttributeValueAtIndex(text, text.Length - 1)); |
||||
} |
||||
} |
||||
} |
@ -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 ICSharpCode.TextEditor.Gui.CompletionWindow; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Xml.Schema; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Element that has a single attribute.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class FindAttributeFromComplexTypeFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlSchemaAttribute attribute; |
||||
XmlSchemaAttribute missingAttribute; |
||||
|
||||
public override void FixtureInit() |
||||
{ |
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.Elements.Add(new QualifiedName("note", "http://www.w3schools.com")); |
||||
|
||||
XmlSchemaElement element = SchemaCompletionData.FindElement(path); |
||||
attribute = SchemaCompletionData.FindAttribute(element, "name"); |
||||
missingAttribute = SchemaCompletionData.FindAttribute(element, "missing"); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeFound() |
||||
{ |
||||
Assert.IsNotNull(attribute); |
||||
} |
||||
|
||||
[Test] |
||||
public void CannotFindUnknownAttribute() |
||||
{ |
||||
Assert.IsNull(missingAttribute); |
||||
} |
||||
|
||||
protected override string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\" xmlns=\"http://www.w3schools.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
" <xs:element name=\"note\">\r\n" + |
||||
" <xs:complexType>\r\n" + |
||||
"\t<xs:attribute name=\"name\" type=\"xs:string\"/>\r\n" + |
||||
" </xs:complexType>\r\n" + |
||||
" </xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using XmlEditor.Tests.Utils; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
[TestFixture] |
||||
public class GetSchemaFromFileNameTestFixture |
||||
{ |
||||
XmlSchemaCompletionDataCollection schemas; |
||||
string expectedNamespace; |
||||
XmlCompletionDataProvider provider; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
schemas = new XmlSchemaCompletionDataCollection(); |
||||
XmlSchemaCompletionData completionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema()); |
||||
expectedNamespace = completionData.NamespaceUri; |
||||
completionData.FileName = @"C:\Schemas\MySchema.xsd"; |
||||
schemas.Add(completionData); |
||||
|
||||
provider = new XmlCompletionDataProvider(schemas, completionData, String.Empty); |
||||
} |
||||
|
||||
[Test] |
||||
public void RelativeFileName() |
||||
{ |
||||
XmlSchemaCompletionData foundSchema = schemas.GetSchemaFromFileName(@"C:\Schemas\..\Schemas\MySchema.xsd"); |
||||
Assert.AreEqual(expectedNamespace, foundSchema.NamespaceUri); |
||||
} |
||||
|
||||
[Test] |
||||
public void RelativeFileNameFromProvider() |
||||
{ |
||||
XmlSchemaCompletionData foundSchema = provider.FindSchemaFromFileName(@"C:\Schemas\..\Schemas\MySchema.xsd"); |
||||
Assert.AreEqual(expectedNamespace, foundSchema.NamespaceUri); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void LowerCaseFileName() |
||||
{ |
||||
XmlSchemaCompletionData foundSchema = schemas.GetSchemaFromFileName(@"C:\schemas\myschema.xsd"); |
||||
Assert.AreEqual(expectedNamespace, foundSchema.NamespaceUri); |
||||
} |
||||
|
||||
[Test] |
||||
public void MissingFileName() |
||||
{ |
||||
Assert.IsNull(schemas.GetSchemaFromFileName(@"C:\Test\test.xsd")); |
||||
} |
||||
} |
||||
} |
@ -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 ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
using System; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that the standard W3C namespace for XSD files is recognised.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class XmlSchemaNamespaceTests |
||||
{ |
||||
[Test] |
||||
public void IsXmlSchemaNamespace() |
||||
{ |
||||
Assert.IsTrue(XmlSchemaManager.IsXmlSchemaNamespace("http://www.w3.org/2001/XMLSchema")); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsNotXmlSchemaNamespace() |
||||
{ |
||||
Assert.IsFalse(XmlSchemaManager.IsXmlSchemaNamespace("http://foo.com")); |
||||
} |
||||
|
||||
[Test] |
||||
public void EmptyString() |
||||
{ |
||||
Assert.IsFalse(XmlSchemaManager.IsXmlSchemaNamespace(String.Empty)); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue