~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.XmlEditor/Tests/Parser/ActiveElementUnderCursorTests.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1

 
2
using MonoDevelop.XmlEditor;
 
3
using NUnit.Framework;
 
4
using System;
 
5
using System.Xml;
 
6
 
 
7
namespace MonoDevelop.XmlEditor.Tests.Parser
 
8
{
 
9
        /// <summary>
 
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
 
12
        /// tag.
 
13
        /// </summary>
 
14
        [TestFixture]
 
15
        public class ActiveElementUnderCursorTests
 
16
        {
 
17
                XmlElementPath elementPath;
 
18
                XmlElementPath expectedElementPath;
 
19
                string namespaceURI = "http://foo.com/foo.xsd";
 
20
                
 
21
                [Test]
 
22
                public void PathTest1()
 
23
                {
 
24
                        string text = "<foo xmlns='" + namespaceURI + "'><bar ";
 
25
                        elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("bar "));
 
26
                        
 
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.");
 
32
                }               
 
33
                
 
34
                [Test]
 
35
                public void PathTest2()
 
36
                {
 
37
                        string text = "<foo xmlns='" + namespaceURI + "'><bar>";
 
38
                        elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("bar>"));
 
39
                        
 
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.");
 
45
                }
 
46
                
 
47
                [Test]
 
48
                public void PathTest3()
 
49
                {
 
50
                        string text = "<foo xmlns='" + namespaceURI + "'><bar>";
 
51
                        elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("ar>"));
 
52
                        
 
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.");
 
58
                }
 
59
                
 
60
                [Test]
 
61
                public void PathTest4()
 
62
                {
 
63
                        string text = "<foo xmlns='" + namespaceURI + "'><bar>";
 
64
                        elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length - 1);
 
65
                        
 
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.");
 
71
                }
 
72
                
 
73
                [Test]
 
74
                public void PathTest5()
 
75
                {
 
76
                        string text = "<foo xmlns='" + namespaceURI + "'><bar a='a'>";
 
77
                        elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("='a'"));
 
78
                        
 
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.");
 
84
                }
 
85
                
 
86
                [Test]
 
87
                public void PathTest6()
 
88
                {
 
89
                        string text = "<foo xmlns='" + namespaceURI + "'><bar a='a'";
 
90
                        elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length - 1);
 
91
                        
 
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.");
 
97
                }
 
98
                
 
99
                [Test]
 
100
                public void PathTest7()
 
101
                {
 
102
                        string text = "<foo xmlns='" + namespaceURI + "'><bar a='a'";
 
103
                        elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length);
 
104
                        
 
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.");
 
110
                }
 
111
                
 
112
                [Test]
 
113
                public void PathTest8()
 
114
                {
 
115
                        string text = "<foo xmlns='" + namespaceURI + "'><bar>";
 
116
                        elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length);
 
117
                        
 
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.");
 
123
                }
 
124
                
 
125
                [Test]
 
126
                public void PathTest9()
 
127
                {
 
128
                        string text = "<foo xmlns='" + namespaceURI + "'><bar ";
 
129
                        elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.Length);
 
130
                        
 
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.");
 
136
                }
 
137
                
 
138
                [Test]
 
139
                public void PathTest10()
 
140
                {
 
141
                        string text = "<foo xmlns='" + namespaceURI + "'><bar Id=\r\n</foo>";
 
142
                        elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, text.IndexOf("Id="));
 
143
                        
 
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.");
 
149
                }
 
150
                
 
151
                [Test]
 
152
                public void PathTest11()
 
153
                {
 
154
                        string text = "<foo xmlns='" + namespaceURI + "'>";
 
155
                        elementPath = XmlParser.GetActiveElementStartPathAtIndex(text, 2);
 
156
                        
 
157
                        expectedElementPath = new XmlElementPath();
 
158
                        expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
 
159
                        Assert.IsTrue(elementPath.Equals(expectedElementPath), 
 
160
                                      "Incorrect active element path.");
 
161
                }
 
162
 
 
163
        }
 
164
}