-Added JContainer.DescendantsAndSelf
-Added CurrentToken to JTokenReader
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
#if !(NET20 || NET35 || PORTABLE || ASPNETCORE50)
|
||||
using System.Numerics;
|
||||
#endif
|
||||
@@ -717,6 +718,35 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.AreEqual(3, (int)descendants[descendants.Count - 1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DescendantsAndSelf()
|
||||
{
|
||||
XElement e = new XElement("name");
|
||||
e.Add(new XElement("child"));
|
||||
|
||||
var x = e.DescendantsAndSelf().ToList();
|
||||
Assert.AreEqual(2, x.Count);
|
||||
Assert.AreEqual(e, x[0]);
|
||||
Assert.AreEqual(e.Element("child"), x[1]);
|
||||
|
||||
JArray a =
|
||||
new JArray(
|
||||
5,
|
||||
new JArray(1),
|
||||
new JArray(1, 2),
|
||||
new JArray(1, 2, 3)
|
||||
);
|
||||
|
||||
List<JToken> descendantsAndSelf = a.DescendantsAndSelf().ToList();
|
||||
Assert.AreEqual(11, descendantsAndSelf.Count());
|
||||
Assert.AreEqual(a, descendantsAndSelf[0]);
|
||||
Assert.AreEqual(5, (int)descendantsAndSelf[1]);
|
||||
Assert.IsTrue(JToken.DeepEquals(new JArray(1, 2, 3), descendantsAndSelf[descendantsAndSelf.Count - 4]));
|
||||
Assert.AreEqual(1, (int)descendantsAndSelf[descendantsAndSelf.Count - 3]);
|
||||
Assert.AreEqual(2, (int)descendantsAndSelf[descendantsAndSelf.Count - 2]);
|
||||
Assert.AreEqual(3, (int)descendantsAndSelf[descendantsAndSelf.Count - 1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateWriter()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user