Exemple #1
0
        public void TestAccumulatePath()
        {
            var memory = new SimpleObjectMemory(new
            {
                f = "foo",
                b = "bar",
                z = new
                {
                    z = "zar"
                },
                n = 2
            });

            // normal case, note, we doesn't append a " yet
            var exp = Expression.Parse("a[f].b[n].z");

            var(path, left, err) = ExpressionFunctions.TryAccumulatePath(exp, memory);
            Assert.AreEqual(path, "a['foo'].b[2].z");

            // normal case
            exp = Expression.Parse("a[z.z][z.z].y");
            (path, left, err) = ExpressionFunctions.TryAccumulatePath(exp, memory);
            Assert.AreEqual(path, "a['zar']['zar'].y");

            // normal case
            exp = Expression.Parse("a.b[z.z]");
            (path, left, err) = ExpressionFunctions.TryAccumulatePath(exp, memory);
            Assert.AreEqual(path, "a.b['zar']");

            // stop evaluate at middle
            exp = Expression.Parse("json(x).b");
            (path, left, err) = ExpressionFunctions.TryAccumulatePath(exp, memory);
            Assert.AreEqual(path, "b");
        }