Ejemplo n.º 1
0
        public void PathTest()
        {
            var json = @"
{
    ""a"": [
        {
            ""aa"": 1
        }       
    ]
}
";
            var root = JsonParser.Parse(json);

            {
                var it = root.Traverse().GetEnumerator();
                it.MoveNext(); Assert.AreEqual("/", it.Current.Pointer().ToString());
                it.MoveNext(); Assert.AreEqual("/a", it.Current.Pointer().ToString());
                it.MoveNext(); Assert.AreEqual("/a/0", it.Current.Pointer().ToString());
                it.MoveNext(); Assert.AreEqual("/a/0/aa", it.Current.Pointer().ToString());
                Assert.False(it.MoveNext());
            }

            {
                var it = root.Traverse().GetEnumerator();

                var f = new JsonFormatter();
                f.Serialize("JsonPath");

                root.SetValue(Utf8String.From("/a"), f.GetStoreBytes());
                it.MoveNext(); Assert.AreEqual("/", it.Current.Pointer().ToString());
                it.MoveNext(); Assert.AreEqual("/a", it.Current.Pointer().ToString());
                Assert.False(it.MoveNext());
            }
        }
        static void SerializeValue <T>(T value, string json)
        {
            var b = new BytesStore();
            var f = new JsonFormatter(b);

            f.Serialize(value);
            Assert.AreEqual(json, new Utf8String(b.Bytes).ToString());
        }