-Fixed incorrect JTokenReader.Path in certain situations

This commit is contained in:
James Newton-King
2015-02-15 13:54:08 +13:00
parent 432a6e8945
commit 20f66cdac9
13 changed files with 145 additions and 34 deletions
@@ -614,5 +614,117 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(null, reader.ValueType);
Assert.AreEqual(null, reader.Value);
}
[Test]
public void InitialPath_PropertyBase_PropertyToken()
{
JObject o = new JObject
{
{ "prop1", true }
};
JTokenReader reader = new JTokenReader(o, "baseprop");
Assert.AreEqual("baseprop", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual("baseprop", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual("baseprop.prop1", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual("baseprop.prop1", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual("baseprop", reader.Path);
Assert.IsFalse(reader.Read());
Assert.AreEqual("baseprop", reader.Path);
}
[Test]
public void InitialPath_ArrayBase_PropertyToken()
{
JObject o = new JObject
{
{ "prop1", true }
};
JTokenReader reader = new JTokenReader(o, "[0]");
Assert.AreEqual("[0]", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual("[0]", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual("[0].prop1", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual("[0].prop1", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual("[0]", reader.Path);
Assert.IsFalse(reader.Read());
Assert.AreEqual("[0]", reader.Path);
}
[Test]
public void InitialPath_PropertyBase_ArrayToken()
{
JArray a = new JArray
{
1, 2
};
JTokenReader reader = new JTokenReader(a, "baseprop");
Assert.AreEqual("baseprop", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual("baseprop", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual("baseprop[0]", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual("baseprop[1]", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual("baseprop", reader.Path);
Assert.IsFalse(reader.Read());
Assert.AreEqual("baseprop", reader.Path);
}
[Test]
public void InitialPath_ArrayBase_ArrayToken()
{
JArray a = new JArray
{
1, 2
};
JTokenReader reader = new JTokenReader(a, "[0]");
Assert.AreEqual("[0]", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual("[0]", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual("[0][0]", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual("[0][1]", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual("[0]", reader.Path);
Assert.IsFalse(reader.Read());
Assert.AreEqual("[0]", reader.Path);
}
}
}