Author: atsushi
Date: 2005-12-13 10:18:30 -0500 (Tue, 13 Dec 2005)
New Revision: 54296

Modified:
   trunk/mcs/class/System.XML/System.Xml.XPath/ChangeLog
   trunk/mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs
   trunk/mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog
   
trunk/mcs/class/System.XML/Test/System.Xml.XPath/XPathEditableNavigatorTests.cs
Log:
2005-12-13  Atsushi Enomoto <[EMAIL PROTECTED]>

        * XPathNavigator.cs : Reimplemented MoveToFollowing() to avoid
          inefficient MoveToDescendant() and to match .NET 2.0 behavior.

        * XPathEditableNavigatorTests.cs : added tests for MoveToFollowing().



Modified: trunk/mcs/class/System.XML/System.Xml.XPath/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.XPath/ChangeLog       2005-12-13 
14:55:34 UTC (rev 54295)
+++ trunk/mcs/class/System.XML/System.Xml.XPath/ChangeLog       2005-12-13 
15:18:30 UTC (rev 54296)
@@ -1,5 +1,10 @@
 2005-12-13  Atsushi Enomoto <[EMAIL PROTECTED]>
 
+       * XPathNavigator.cs : Reimplemented MoveToFollowing() to avoid
+         inefficient MoveToDescendant() and to match .NET 2.0 behavior.
+
+2005-12-13  Atsushi Enomoto <[EMAIL PROTECTED]>
+
        * XPathNavigator.cs : ReplaceSelf() should allow document fragment.
          Moved implementation to XPathEditableDocument.
 

Modified: trunk/mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs       
2005-12-13 14:55:34 UTC (rev 54295)
+++ trunk/mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs       
2005-12-13 15:18:30 UTC (rev 54296)
@@ -721,16 +721,6 @@
                        return MoveTo (SelectChildren (localName, 
namespaceURI));
                }
 
-               bool MoveToDescendant (XPathNodeType type)
-               {
-                       return MoveTo (SelectDescendants (type, false));
-               }
-
-               bool MoveToDescendant (string localName, string namespaceURI)
-               {
-                       return MoveTo (SelectDescendants (localName, 
namespaceURI, false));
-               }
-
                public virtual bool MoveToNext (string localName, string 
namespaceURI)
                {
                        XPathNavigator nav = Clone ();
@@ -756,76 +746,89 @@
                        return false;
                }
 
-               [MonoTODO]
                public virtual bool MoveToFollowing (string localName,
                        string namespaceURI)
                {
                        return MoveToFollowing (localName, namespaceURI, null);
                }
 
-               [MonoTODO]
                public virtual bool MoveToFollowing (string localName,
                        string namespaceURI, XPathNavigator end)
                {
+                       if (localName == null)
+                               throw new ArgumentNullException ("localName");
+                       if (namespaceURI == null)
+                               throw new ArgumentNullException 
("namespaceURI");
+                       localName = NameTable.Get (localName);
+                       if (localName == null)
+                               return false;
+                       namespaceURI = NameTable.Get (namespaceURI);
+                       if (namespaceURI == null)
+                               return false;
+
                        XPathNavigator nav = Clone ();
-                       bool skip = false;
+                       switch (nav.NodeType) {
+                       case XPathNodeType.Attribute:
+                       case XPathNodeType.Namespace:
+                               nav.MoveToParent ();
+                               break;
+                       }
                        do {
-                               if (!skip && nav.MoveToDescendant (localName,
-                                       namespaceURI)) {
-                                       if (end != null) {
-                                               switch (nav.ComparePosition 
(end)) {
-                                               case XmlNodeOrder.After:
-                                               case XmlNodeOrder.Unknown:
-                                                       return false;
+                               if (!nav.MoveToFirstChild ()) {
+                                       do {
+                                               if (!nav.MoveToNext ()) {
+                                                       if (!nav.MoveToParent 
())
+                                                               return false;
                                                }
-                                       }
+                                               else
+                                                       break;
+                                       } while (true);
+                               }
+                               if (end != null && end.IsSamePosition (nav))
+                                       return false;
+                               if (object.ReferenceEquals (localName, 
nav.LocalName) &&
+                                       object.ReferenceEquals (namespaceURI, 
nav.NamespaceURI)) {
                                        MoveTo (nav);
                                        return true;
                                }
-                               else
-                                       skip = false;
-                               if (!nav.MoveToNext ()) {
-                                       if (!nav.MoveToParent ())
-                                               break;
-                                       skip = true;
-                               }
                        } while (true);
-                       return false;
                }
 
-               [MonoTODO]
                public virtual bool MoveToFollowing (XPathNodeType type)
                {
                        return MoveToFollowing (type, null);
                }
 
-               [MonoTODO]
                public virtual bool MoveToFollowing (XPathNodeType type,
                        XPathNavigator end)
                {
+                       if (type == XPathNodeType.Root)
+                               return false; // will never match
                        XPathNavigator nav = Clone ();
-                       bool skip = false;
+                       switch (nav.NodeType) {
+                       case XPathNodeType.Attribute:
+                       case XPathNodeType.Namespace:
+                               nav.MoveToParent ();
+                               break;
+                       }
                        do {
-                               if (!skip && nav.MoveToDescendant (type)) {
-                                       if (end != null) {
-                                               switch (nav.ComparePosition 
(end)) {
-                                               case XmlNodeOrder.After:
-                                               case XmlNodeOrder.Unknown:
-                                                       return false;
+                               if (!nav.MoveToFirstChild ()) {
+                                       do {
+                                               if (!nav.MoveToNext ()) {
+                                                       if (!nav.MoveToParent 
())
+                                                               return false;
                                                }
-                                       }
+                                               else
+                                                       break;
+                                       } while (true);
+                               }
+                               if (end != null && end.IsSamePosition (nav))
+                                       return false;
+                               if (nav.NodeType == type) {
                                        MoveTo (nav);
                                        return true;
                                }
-                               else
-                                       skip = false;
-                               if (!nav.MoveToNext ()) {
-                                       if (!nav.MoveToParent ())
-                                               break;
-                                       skip = true;
-                               }
                        } while (true);
-                       return false;
                }
 
                [MonoTODO]

Modified: trunk/mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog  2005-12-13 
14:55:34 UTC (rev 54295)
+++ trunk/mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog  2005-12-13 
15:18:30 UTC (rev 54296)
@@ -1,5 +1,9 @@
 2005-12-13  Atsushi Enomoto <[EMAIL PROTECTED]>
 
+       * XPathEditableNavigatorTests.cs : added tests for MoveToFollowing().
+
+2005-12-13  Atsushi Enomoto <[EMAIL PROTECTED]>
+
        * XPathEditableNavigatorTests.cs : added tests that passes empty
          string to editor methods. Added tests for ReplaceSelf().
 

Modified: 
trunk/mcs/class/System.XML/Test/System.Xml.XPath/XPathEditableNavigatorTests.cs
===================================================================
--- 
trunk/mcs/class/System.XML/Test/System.Xml.XPath/XPathEditableNavigatorTests.cs 
    2005-12-13 14:55:34 UTC (rev 54295)
+++ 
trunk/mcs/class/System.XML/Test/System.Xml.XPath/XPathEditableNavigatorTests.cs 
    2005-12-13 15:18:30 UTC (rev 54296)
@@ -702,6 +702,43 @@
                                true,           // HasChildren
                                false);         // IsEmptyElement
                }
+
+               [Test]
+               public void MoveToFollowing ()
+               {
+                       XPathNavigator end;
+
+                       XPathNavigator nav = GetInstance ("<root><bar><foo 
attr='v1'><baz><foo attr='v2'/></baz></foo></bar><dummy/><foo 
attr='v3'></foo></root>");
+                       Assert.IsTrue (nav.MoveToFollowing ("foo", 
String.Empty), "#1");
+                       Assert.AreEqual ("v1", nav.GetAttribute ("attr", 
String.Empty), "#2");
+                       Assert.IsTrue (nav.MoveToFollowing ("foo", 
String.Empty), "#3");
+                       Assert.AreEqual ("v2", nav.GetAttribute ("attr", 
String.Empty), "#4");
+                       Assert.IsTrue (nav.MoveToFollowing ("foo", 
String.Empty), "#5");
+                       Assert.AreEqual ("v3", nav.GetAttribute ("attr", 
String.Empty), "#6");
+
+                       // round 2
+                       end = nav.Clone ();
+
+                       nav.MoveToRoot ();
+                       Assert.IsTrue (nav.MoveToFollowing ("foo", 
String.Empty, end), "#7");
+                       Assert.AreEqual ("v1", nav.GetAttribute ("attr", 
String.Empty), "#8");
+                       Assert.IsTrue (nav.MoveToFollowing ("foo", 
String.Empty, end), "#9");
+                       Assert.AreEqual ("v2", nav.GetAttribute ("attr", 
String.Empty), "#10");
+                       // end is exclusive
+                       Assert.IsFalse (nav.MoveToFollowing ("foo", 
String.Empty, end), "#11");
+                       // in this case it never moves to somewhere else.
+                       Assert.AreEqual ("v2", nav.GetAttribute ("attr", 
String.Empty), "#12");
+               }
+
+               [Test]
+               public void MoveToFollowingFromAttribute ()
+               {
+                       XPathNavigator nav = GetInstance ("<root 
a='b'><foo/></root>");
+                       nav.MoveToFirstChild ();
+                       nav.MoveToFirstAttribute ();
+                       // should first move to owner element and go on.
+                       Assert.IsTrue (nav.MoveToFollowing ("foo", 
String.Empty));
+               }
        }
 }
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to