svn path=/trunk/mcs/; revision=104772
[mono.git] / mcs / class / System.XML / Test / System.Xml.XPath / XPathNavigatorTests.cs
index 70527943fbea6e3214a87b7f5b9fdaa008ae5c61..0d3a0fa83ce47c3fae69baecb1d5d8cad02d5b1f 100644 (file)
@@ -4,9 +4,11 @@
 // Authors:
 //   Jason Diamond <jason@injektilo.org>
 //   Martin Willemoes Hansen <mwh@sysrq.dk>
+//   Atsushi Enomoto <atsushi@ximian.com>
 //
 // (C) 2002 Jason Diamond
 // (C) 2003 Martin Willemoes Hansen
+// (C) 2004-2006 Novell, Inc.
 //
 
 using System;
@@ -407,6 +409,24 @@ namespace MonoTests.System.Xml
                        }
                }
 
+               [Test]
+               public void TextMatchesWhitespace ()
+               {
+                       string xml = "<root><ws>   </ws><sws xml:space='preserve'> </sws></root>";
+                       XmlDocument doc = new XmlDocument ();
+                       doc.PreserveWhitespace = true;
+                       doc.LoadXml (xml);
+                       XPathNavigator nav = doc.CreateNavigator ();
+                       nav.MoveToFirstChild (); // root
+                       nav.MoveToFirstChild (); // ws
+                       nav.MoveToFirstChild (); // '   '
+                       AssertEquals ("#1", true, nav.Matches ("text()"));
+                       nav.MoveToParent ();
+                       nav.MoveToNext (); // sws
+                       nav.MoveToFirstChild (); // ' '
+                       AssertEquals ("#2", true, nav.Matches ("text()"));
+               }
+
 #if NET_2_0
                [Test]
                public void ValueAsBoolean ()
@@ -592,6 +612,82 @@ namespace MonoTests.System.Xml
                        iter.MoveNext ();
                        AssertEquals ("val&quot;1&#10;&gt;", iter.Current.InnerXml);
                }
+
+               [Test]
+               public void WriterAttributePrefix ()
+               {
+                       XmlDocument doc = new XmlDocument ();
+                       XmlWriter w = doc.CreateNavigator ().AppendChild ();
+                       w.WriteStartElement ("foo");
+                       w.WriteAttributeString ("xmlns", "x", "http://www.w3.org/2000/xmlns/", "urn:foo");
+                       AssertEquals ("#0", "x", w.LookupPrefix ("urn:foo"));
+                       w.WriteStartElement (null, "bar", "urn:foo");
+                       w.WriteAttributeString (null, "ext", "urn:foo", "bah");
+                       w.WriteEndElement ();
+                       w.WriteEndElement ();
+                       w.Close ();
+                       AssertEquals ("#1", "x", doc.FirstChild.FirstChild.Prefix);
+                       AssertEquals ("#2", "x", doc.FirstChild.FirstChild.Attributes [0].Prefix);
+               }
+
+               [Test]
+               public void ValueAs ()
+               {
+                       string xml = "<root>1</root>";
+                       XPathNavigator nav = new XPathDocument (XmlReader.Create (new StringReader (xml))).CreateNavigator ();
+                       nav.MoveToFirstChild ();
+                       nav.MoveToFirstChild ();
+                       AssertEquals ("1", nav.ValueAs (typeof (string), null));
+                       AssertEquals (1, nav.ValueAs (typeof (int), null));
+               }
+
+               [Test]
+               public void MoveToFollowingNodeTypeAll ()
+               {
+                       XmlDocument doc = new XmlDocument ();
+                       doc.LoadXml ("<root><child/><child2/></root>");
+                       XPathNavigator nav = doc.CreateNavigator ();
+                       Assert ("#1", nav.MoveToFollowing (XPathNodeType.All));
+                       Assert ("#2", nav.MoveToFollowing (XPathNodeType.All));
+                       AssertEquals ("#3", "child", nav.LocalName);
+                       Assert ("#4", nav.MoveToNext (XPathNodeType.All));
+                       AssertEquals ("#5", "child2", nav.LocalName);
+               }
+
+               [Test] // bug #324606.
+               public void XPathDocumentFromSubtreeNodes ()
+               {
+                       string xml = "<root><child1><nest1><nest2>hello!</nest2></nest1></child1><child2/><child3/></root>";
+                       XmlReader r = new XmlTextReader (new StringReader (xml));
+                       while (r.Read ()) {
+                               if (r.Name == "child1")
+                                       break;
+                       }
+                       XPathDocument d = new XPathDocument (r);
+                       XPathNavigator n = d.CreateNavigator ();
+                       string result = @"<child1>
+  <nest1>
+    <nest2>hello!</nest2>
+  </nest1>
+</child1>
+<child2 />
+<child3 />";
+                       AssertEquals (result, n.OuterXml.Replace ("\r\n", "\n"));
+               }
+
+               [Test] // bug #376191
+               public void InnerXmlOnRoot ()
+               {
+                       XmlDocument document = new XmlDocument ();
+                       document.LoadXml (@"<test>
+                       <node>z</node>
+                       <node>a</node>
+                       <node>b</node>
+                       <node>q</node>
+                       </test>");
+                       XPathNavigator navigator = document.CreateNavigator();
+                       AssertEquals (navigator.OuterXml, navigator.InnerXml);
+               }
 #endif
        }
 }