Beispiel #1
0
        public void extracting_properties_from_a_JSON()
        {
            string s = @"
{ 
    ""p1"": ""n"", 
    ""p2"": 
    { 
        ""p3"": 
        [ 
            {
                ""p4Before"": [""zero"", ""one"", { ""pSub"": [] }, ""three"" ]
                ""p4"": 
                { 
                    ""p5"" : 0.989, 
                    ""p6"": [],
                    ""p7"": {}
                }
            }
        ] 
    } 
}";
            JSONProperties p = new JSONProperties( new StringMatcher( s ) );
            p.Visit();
            CollectionAssert.AreEqual( new[] { "p1", "p2", "p3", "p4Before", "pSub", "p4", "p5", "p6", "p7" }, p.Properties );
            CollectionAssert.AreEqual( new[] {
                " => 0=p1",
                " => 1=p2",
                "1=p2 => 0=p3",
                "1=p2|0=p3|0= => 0=p4Before",
                "1=p2|0=p3|0=|0=p4Before|2= => 0=pSub",
                "1=p2|0=p3|0= => 1=p4",
                "1=p2|0=p3|0=|1=p4 => 0=p5",
                "1=p2|0=p3|0=|1=p4 => 1=p6",
                "1=p2|0=p3|0=|1=p4 => 2=p7" }, p.Paths );
        }
Beispiel #2
0
        public void json_visit_all_properties()
        {
            string         s = @"
{ 
    ""p1"": ""n"", 
    ""p2"": 
    { 
        ""p3"": 
        [ 
            {
                ""p4Before"": [""zero"", ""one"", { ""pSub"": [] }, ""three"" ]
                ""p4"": 
                { 
                    ""p5"" : 0.989, 
                    ""p6"": [],
                    ""p7"": {}
                }
            }
        ] 
    } 
}";
            JSONProperties p = new JSONProperties(new StringMatcher(s));

            p.Visit();
            CollectionAssert.AreEqual(new[] { "p1", "p2", "p3", "p4Before", "pSub", "p4", "p5", "p6", "p7" }, p.Properties);
            CollectionAssert.AreEqual(new[] {
                " => 0=p1",
                " => 1=p2",
                "1=p2 => 0=p3",
                "1=p2|0=p3|0= => 0=p4Before",
                "1=p2|0=p3|0=|0=p4Before|2= => 0=pSub",
                "1=p2|0=p3|0= => 1=p4",
                "1=p2|0=p3|0=|1=p4 => 0=p5",
                "1=p2|0=p3|0=|1=p4 => 1=p6",
                "1=p2|0=p3|0=|1=p4 => 2=p7"
            }, p.Paths);
        }
Beispiel #3
0
        public void extracting_properties_from_a_JSON()
        {
            string         s = @"
{ 
    ""p1"": ""n"", 
    ""p2"": 
    { 
        ""p3"": 
        [ 
            {
                ""p4Before"": [""zero"", ""one"", { ""pSub"": [] }, ""three"" ]
                ""p4"": 
                { 
                    ""p5"" : 0.989, 
                    ""p6"": [],
                    ""p7"": {}
                }
            }
        ] 
    } 
}";
            JSONProperties p = new JSONProperties(new StringMatcher(s));

            p.Visit();
            p.Properties.ShouldBeEquivalentTo(new[] { "p1", "p2", "p3", "p4Before", "pSub", "p4", "p5", "p6", "p7" });
            p.Paths.ShouldBeEquivalentTo(new[] {
                " => 0=p1",
                " => 1=p2",
                "1=p2 => 0=p3",
                "1=p2|0=p3|0= => 0=p4Before",
                "1=p2|0=p3|0=|0=p4Before|2= => 0=pSub",
                "1=p2|0=p3|0= => 1=p4",
                "1=p2|0=p3|0=|1=p4 => 0=p5",
                "1=p2|0=p3|0=|1=p4 => 1=p6",
                "1=p2|0=p3|0=|1=p4 => 2=p7"
            });
        }