2
using MonoDevelop.XmlEditor;
7
namespace MonoDevelop.XmlEditor.Tests.Parser
10
/// Tests the XmlParser.GetActiveElementStartPathAtIndex which finds the element
11
/// path where the index is at. The index may be in the middle or start of the element
15
public class ActiveElementUnderCursorTests
17
XmlElementPath elementPath;
18
XmlElementPath expectedElementPath;
19
string namespaceURI = "http://foo.com/foo.xsd";
22
public void PathTest1()
24
string text = "<foo xmlns='" + namespaceURI + "'><bar ";
25
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("bar "));
27
expectedElementPath = new XmlElementPath();
28
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
29
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI));
30
Assert.IsTrue(elementPath.Equals(expectedElementPath),
31
"Incorrect active element path.");
35
public void PathTest2()
37
string text = "<foo xmlns='" + namespaceURI + "'><bar>";
38
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("bar>"));
40
expectedElementPath = new XmlElementPath();
41
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
42
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI));
43
Assert.IsTrue(elementPath.Equals(expectedElementPath),
44
"Incorrect active element path.");
48
public void PathTest3()
50
string text = "<foo xmlns='" + namespaceURI + "'><bar>";
51
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("ar>"));
53
expectedElementPath = new XmlElementPath();
54
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
55
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI));
56
Assert.IsTrue(elementPath.Equals(expectedElementPath),
57
"Incorrect active element path.");
61
public void PathTest4()
63
string text = "<foo xmlns='" + namespaceURI + "'><bar>";
64
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length - 1);
66
expectedElementPath = new XmlElementPath();
67
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
68
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI));
69
Assert.IsTrue(elementPath.Equals(expectedElementPath),
70
"Incorrect active element path.");
74
public void PathTest5()
76
string text = "<foo xmlns='" + namespaceURI + "'><bar a='a'>";
77
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("='a'"));
79
expectedElementPath = new XmlElementPath();
80
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
81
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI));
82
Assert.IsTrue(elementPath.Equals(expectedElementPath),
83
"Incorrect active element path.");
87
public void PathTest6()
89
string text = "<foo xmlns='" + namespaceURI + "'><bar a='a'";
90
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length - 1);
92
expectedElementPath = new XmlElementPath();
93
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
94
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI));
95
Assert.IsTrue(elementPath.Equals(expectedElementPath),
96
"Incorrect active element path.");
100
public void PathTest7()
102
string text = "<foo xmlns='" + namespaceURI + "'><bar a='a'";
103
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length);
105
expectedElementPath = new XmlElementPath();
106
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
107
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI));
108
Assert.IsTrue(elementPath.Equals(expectedElementPath),
109
"Incorrect active element path.");
113
public void PathTest8()
115
string text = "<foo xmlns='" + namespaceURI + "'><bar>";
116
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length);
118
expectedElementPath = new XmlElementPath();
119
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
120
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI));
121
Assert.IsTrue(elementPath.Equals(expectedElementPath),
122
"Incorrect active element path.");
126
public void PathTest9()
128
string text = "<foo xmlns='" + namespaceURI + "'><bar ";
129
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length);
131
expectedElementPath = new XmlElementPath();
132
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
133
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI));
134
Assert.IsTrue(elementPath.Equals(expectedElementPath),
135
"Incorrect active element path.");
139
public void PathTest10()
141
string text = "<foo xmlns='" + namespaceURI + "'><bar Id=\r\n</foo>";
142
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("Id="));
144
expectedElementPath = new XmlElementPath();
145
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
146
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI));
147
Assert.IsTrue(elementPath.Equals(expectedElementPath),
148
"Incorrect active element path.");
152
public void PathTest11()
154
string text = "<foo xmlns='" + namespaceURI + "'>";
155
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, 2);
157
expectedElementPath = new XmlElementPath();
158
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
159
Assert.IsTrue(elementPath.Equals(expectedElementPath),
160
"Incorrect active element path.");