Author: atsushi
Date: 2008-02-11 11:31:45 -0500 (Mon, 11 Feb 2008)
New Revision: 95447
Modified:
trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog
trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/Extensions.cs
trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XNodeDocumentOrderComparer.cs
trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ExtensionsTest.cs
trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XNodeDocumentOrderComparerTest.cs
Log:
2008-02-11 Atsushi Enomoto <[EMAIL PROTECTED]>
* XNodeDocumentOrderComparer.cs : ancestor/descendant comparison was
broken for some cases.
* Extensions.cs : implemented InDocumentOrder<T>().
* XNodeDocumentOrderComparerTest.cs : added another test for
descendant/ancestor comparison.
* ExtensionsTest.cs : test InDocumentOrder<T>().
Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog 2008-02-11
16:28:45 UTC (rev 95446)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog 2008-02-11
16:31:45 UTC (rev 95447)
@@ -1,5 +1,11 @@
2008-02-11 Atsushi Enomoto <[EMAIL PROTECTED]>
+ * XNodeDocumentOrderComparer.cs : ancestor/descendant comparison was
+ broken for some cases.
+ * Extensions.cs : implemented InDocumentOrder<T>().
+
+2008-02-11 Atsushi Enomoto <[EMAIL PROTECTED]>
+
* XName.cs : implemented GetObjectData(). It is however incompatible
with .NET (yet?).
* XNodeNavigator.cs : SchemaInfo is null.
Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/Extensions.cs
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/Extensions.cs
2008-02-11 16:28:45 UTC (rev 95446)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/Extensions.cs
2008-02-11 16:31:45 UTC (rev 95447)
@@ -141,11 +141,15 @@
yield return n;
}
- [MonoTODO]
public static IEnumerable<T> InDocumentOrder<T> (
this IEnumerable<T> source) where T : XNode
{
- throw new NotImplementedException ();
+ List<XNode> list = new List<XNode> ();
+ foreach (XNode n in source)
+ list.Add (n);
+ list.Sort (XNode.DocumentOrderComparer);
+ foreach (T n in list)
+ yield return n;
}
public static IEnumerable<XNode> Nodes<T> (
Modified:
trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XNodeDocumentOrderComparer.cs
===================================================================
---
trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XNodeDocumentOrderComparer.cs
2008-02-11 16:28:45 UTC (rev 95446)
+++
trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XNodeDocumentOrderComparer.cs
2008-02-11 16:31:45 UTC (rev 95447)
@@ -116,19 +116,19 @@
switch (ret) {
case CompareResult.Same:
// n1 and n2 are sibling each other.
- return CompareSibling (n1, n2);
+ return CompareSibling (n1, n2,
CompareResult.Same);
case CompareResult.Child:
- return CompareSibling (n1, n2.Owner);
+ return CompareSibling (n1, n2.Owner,
CompareResult.Child);
case CompareResult.Parent:
- return CompareSibling (n1.Owner, n2);
+ return CompareSibling (n1.Owner, n2,
CompareResult.Parent);
case CompareResult.Descendant:
for (XNode i2 = n2; ; i2 = i2.Owner)
if (i2.Owner == n1.Owner)
- return CompareSibling (n1, i2);
+ return CompareSibling (n1, i2,
CompareResult.Descendant);
case CompareResult.Ancestor:
for (XNode i1 = n1; ; i1 = i1.Owner)
if (i1.Owner == n2.Owner)
- return CompareSibling (i1, n2);
+ return CompareSibling (i1, n2,
CompareResult.Ancestor);
default:
return ret;
}
@@ -136,8 +136,11 @@
// results are returned as following/preceding, as it is also
// used for comparing parents.
- CompareResult CompareSibling (XNode n1, XNode n2)
+ CompareResult CompareSibling (XNode n1, XNode n2, CompareResult
forSameValue)
{
+ if (n1 == n2)
+ return forSameValue;
+
for (XNode n = n1.NextNode; n != null; n = n.NextNode)
if (n == n2)
return CompareResult.Following;
Modified: trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
===================================================================
--- trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
2008-02-11 16:28:45 UTC (rev 95446)
+++ trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
2008-02-11 16:31:45 UTC (rev 95447)
@@ -1,5 +1,11 @@
2008-02-11 Atsushi Enomoto <[EMAIL PROTECTED]>
+ * XNodeDocumentOrderComparerTest.cs : added another test for
+ descendant/ancestor comparison.
+ * ExtensionsTest.cs : test InDocumentOrder<T>().
+
+2008-02-11 Atsushi Enomoto <[EMAIL PROTECTED]>
+
* XNamespaceTest.cs : test Get() and GetName().
2008-02-11 Atsushi Enomoto <[EMAIL PROTECTED]>
Modified: trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ExtensionsTest.cs
===================================================================
--- trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ExtensionsTest.cs
2008-02-11 16:28:45 UTC (rev 95446)
+++ trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ExtensionsTest.cs
2008-02-11 16:31:45 UTC (rev 95447)
@@ -46,5 +46,16 @@
Assert.IsNull (doc.Root.FirstNode, "#1");
}
*/
+
+ [Test]
+ public void InDocumentOrder ()
+ {
+ XElement el = XDocument.Parse
("<root><foo><f1/><f2/></foo><bar/></root>").Root;
+ XElement c = el.FirstNode as XElement;
+ int n = 0;
+ string [] names = {"foo", "f1", "f2", "bar"};
+ foreach (XElement e2 in new XNode [] {el.LastNode,
c.LastNode, c.FirstNode, c}.InDocumentOrder ())
+ Assert.AreEqual (names [n], e2.Name.LocalName,
"#" + n++);
+ }
}
}
Modified:
trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XNodeDocumentOrderComparerTest.cs
===================================================================
---
trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XNodeDocumentOrderComparerTest.cs
2008-02-11 16:28:45 UTC (rev 95446)
+++
trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XNodeDocumentOrderComparerTest.cs
2008-02-11 16:31:45 UTC (rev 95447)
@@ -54,6 +54,11 @@
XDocument doc = XDocument.Parse ("<foo><bar/></foo>");
Assert.IsTrue (c.Compare (doc, doc.FirstNode) < 0,
"#2-1");
Assert.IsTrue (c.Compare (doc.FirstNode, doc) > 0,
"#2-2");
+
+ el = XDocument.Parse
("<root><foo><f1/><f2/></foo><bar/></root>").Root;
+ XElement e2 = el.FirstNode as XElement;
+ Assert.IsTrue (c.Compare (e2, e2.FirstNode) < 0,
"#3-1");
+ Assert.IsTrue (c.Compare (e2, e2.LastNode) < 0, "#3-2");
}
[Test]
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches