예제 #1
0
        public void TestScalar()
        {
            var s = @"{
            ""astring"": ""this is a string."",
            ""anint"": 52461,
            ""afloat"": 0.95294,
            ""abool"": false,
            ""anull"": null
        }";

            FConfig d = new FConfig();

            d.LoadString(s);

            Assert.That(d.Get("astring") is string, Is.True);
            Assert.That((string)d.Get("astring"), Is.EqualTo("this is a string."));
            Assert.That(d.GetString("astring"), Is.EqualTo("this is a string."));

            Assert.That(d.Get("anint") is int, Is.True);
            Assert.That((int)d.Get("anint"), Is.EqualTo(52461));
            Assert.That(d.GetInt("anint"), Is.EqualTo(52461));

            Assert.That(d.Get("afloat") is float, Is.True);
            Assert.That((float)d.Get("afloat"), Is.EqualTo(0.95294f));
            Assert.That(d.GetFloat("afloat"), Is.EqualTo(0.95294f));

            Assert.That(d.Get("abool") is bool, Is.True);
            Assert.That((bool)d.Get("abool"), Is.False);
            Assert.That(d.GetBool("abool"), Is.False);

            Assert.That(d.Get("anull"), Is.Null);
        }
예제 #2
0
        public void TestList()
        {
            var     s = @"{
            ""da"": [
                ""a string"",
                ""another one"",
                ""the third in a series""
            ],
            ""db"": [
                { ""a"": 1, ""b"": 2, ""c"": 3 },
                { ""a"": 8, ""b"": 7, ""c"": 6 },
                { ""a"": 4, ""b"": 3, ""c"": 2 },
                { ""a"": 5, ""b"": 6, ""c"": 7 },
            ],
            ""dc"": [
                [ 46, 24, 86, 62 ],
                134.974,
                { ""p"": ""bug"", ""q"": ""lizard"" }
            ]
        }";
            FConfig d = new FConfig();

            d.LoadString(s);

            Assert.That(d.GetString("da/0"), Is.EqualTo("a string"));
            Assert.That(d.GetString("da/1"), Is.EqualTo("another one"));
            Assert.That(d.GetString("da/2"), Is.EqualTo("the third in a series"));

            Assert.That(d.GetInt("db/0/a"), Is.EqualTo(1));
            Assert.That(d.GetInt("db/1/b"), Is.EqualTo(7));
            Assert.That(d.GetInt("db/2/c"), Is.EqualTo(2));
            Assert.That(d.GetInt("db/3/b"), Is.EqualTo(6));

            Assert.That(d.GetInt("dc/0/1"), Is.EqualTo(24));
            Assert.That(d.GetInt("dc/0/3"), Is.EqualTo(62));
            Assert.That(d.GetFloat("dc/1"), Is.EqualTo(134.974f));
            Assert.That(d.GetString("dc/2/p"), Is.EqualTo("bug"));
        }