5
// Michael Hutchinson <mhutchinson@novell.com>
7
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
using System.Collections.Generic;
31
using MonoDevelop.Ide.Gui.Content;
34
using NUnit.Framework;
37
namespace MonoDevelop.Xml.StateEngine
41
public class ParsingTests
44
public virtual XmlFreeState CreateRootState ()
46
return new XmlFreeState ();
50
public void AttributeName ()
52
TestParser parser = new TestParser (CreateRootState ());
61
parser.AssertStateIs<XmlDoubleQuotedAttributeValueState> ();
62
parser.AssertPath ("//doc/tag.a/tag.b/@id");
65
parser.AssertEmpty ();
66
parser.AssertErrorCount (0);
70
public void Attributes ()
72
TestParser parser = new TestParser (CreateRootState ());
75
<tag.a name=""foo"" arg=5 wibble = 6 bar.baz = 'y.ff7]' $ />
79
parser.AssertStateIs<XmlTagState> ();
80
parser.AssertAttributes ("name", "foo", "arg", "5", "wibble", "6", "bar.baz", "y.ff7]");
83
parser.AssertEmpty ();
84
parser.AssertErrorCount (0);
87
[Test, Ignore ("Not working")]
88
public void AttributeRecovery ()
90
TestParser parser = new TestParser (CreateRootState ());
94
<tag.b arg='fff' sdd = sdsds= 'foo' ff $ />
100
parser.AssertStateIs<XmlTagState> ();
101
parser.AssertAttributes ("arg", "fff", "sdd", "", "sdsds", "foo", "ff", "");
102
parser.AssertErrorCount (1);
105
parser.AssertEmpty ();
106
parser.AssertErrorCount (1);
110
public void IncompleteTags ()
112
TestParser parser = new TestParser (CreateRootState ());
119
<tag.e att5='' att6=' att7 = >
129
parser.AssertStateIs<XmlSingleQuotedAttributeValueState> ();
130
parser.AssertNodeDepth (9);
131
parser.AssertPath ("//doc/tag.a/tag.b/tag.c/tag.d/tag.e/tag.f/@id");
134
parser.AssertEmpty ();
135
parser.AssertErrorCount (3, x => x.ErrorType == ErrorType.Error);
136
parser.AssertErrorCount (2, x => x.ErrorType == ErrorType.Warning);
140
public void Unclosed ()
142
TestParser parser = new TestParser (CreateRootState ());
151
parser.AssertStateIs<XmlFreeState> ();
152
parser.AssertNodeDepth (5);
153
parser.AssertPath ("//doc/tag.a/tag.b/tag.b");
156
parser.AssertStateIs<XmlFreeState> ();
157
parser.AssertNodeDepth (2);
158
parser.AssertPath ("//doc");
161
parser.AssertEmpty ();
162
parser.AssertErrorCount (2);
168
TestParser parser = new TestParser (CreateRootState ());
173
<!-- <foo> <bar arg=""> $ -->
177
parser.AssertStateIs<XmlDocTypeState> ();
178
parser.AssertNodeDepth (3);
179
parser.AssertPath ("//doc/<!DOCTYPE>");
182
parser.AssertStateIs<XmlCDataState> ();
183
parser.AssertNodeDepth (3);
184
parser.AssertPath ("//doc/<![CDATA[ ]]>");
187
parser.AssertStateIs<XmlCommentState> ();
188
parser.AssertNodeDepth (3);
189
parser.AssertPath ("//doc/<!-- -->");
192
parser.AssertEmpty ();
193
parser.AssertErrorCount (0);
197
public void DocTypeCapture ()
199
TestParser parser = new TestParser (CreateRootState (), true);
201
<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN""
202
""DTD/xhtml1-strict.dtd""
208
parser.AssertEmpty ();
209
XDocument doc = (XDocument)parser.Nodes.Peek ();
210
Assert.IsTrue (doc.FirstChild is XDocType);
211
XDocType dt = (XDocType) doc.FirstChild;
212
Assert.AreEqual ("html", dt.RootElement.FullName);
213
Assert.AreEqual ("-//W3C//DTD XHTML 1.0 Strict//EN", dt.PublicFpi);
214
Assert.AreEqual ("DTD/xhtml1-strict.dtd", dt.Uri);
215
Assert.AreEqual (dt.InternalDeclarationRegion.Start.Line, 4);
216
Assert.AreEqual (dt.InternalDeclarationRegion.End.Line, 7);
217
parser.AssertNoErrors ();