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

« back to all changes in this revision

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