1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
using MonoDevelop.XmlEditor;
using NUnit.Framework;
using System;
using System.Xml;
namespace MonoDevelop.XmlEditor.Tests.Parser
{
[TestFixture]
public class ActiveElementStartPathTestFixture
{
XmlElementPath elementPath;
XmlElementPath expectedElementPath;
string namespaceURI = "http://foo.com/foo.xsd";
[Test]
public void PathTest1()
{
string text = "<foo xmlns='" + namespaceURI + "' ";
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath),
"Incorrect active element path.");
}
[Test]
public void PathTest2()
{
string text = "<foo xmlns='" + namespaceURI + "' ><bar ";
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI));
Assert.IsTrue(expectedElementPath.Equals(elementPath),
"Incorrect active element path.");
}
[Test]
public void PathTest3()
{
string text = "<f:foo xmlns:f='" + namespaceURI + "' ><f:bar ";
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI, "f"));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI, "f"));
Assert.IsTrue(expectedElementPath.Equals(elementPath),
"Incorrect active element path.");
}
[Test]
public void PathTest4()
{
string text = "<x:foo xmlns:x='" + namespaceURI + "' ";
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI, "x"));
Assert.IsTrue(expectedElementPath.Equals(elementPath),
"Incorrect active element path.");
}
[Test]
public void PathTest5()
{
string text = "<foo xmlns='" + namespaceURI + "'>\r\n"+
"<y\r\n" +
"Id = 'foo' ";
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("y", namespaceURI));
Assert.IsTrue(expectedElementPath.Equals(elementPath),
"Incorrect active element path.");
}
[Test]
public void PathTest6()
{
string text = "<bar xmlns='http://bar'>\r\n" +
"<foo xmlns='" + namespaceURI + "' ";
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
Assert.IsTrue(expectedElementPath.Equals(elementPath),
"Incorrect active element path.");
}
/// <summary>
/// Tests that we get no path back if we are outside the start
/// tag.
/// </summary>
[Test]
public void OutOfStartTagPathTest1()
{
string text = "<foo xmlns='" + namespaceURI + "'> ";
elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
Assert.AreEqual(0, elementPath.Elements.Count, "Should have no path.");
}
}
}
|