Exemple #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);
        }
Exemple #2
0
        public void TestPreparsed()
        {
            var d = new Dictionary<string,object>();
            d["a"] = 1;
            d["b"] = 2;
            d["c"] = 3;
            FConfig c = new FConfig(d);

            Assert.That(c.GetInt("a"), Is.EqualTo(1));
            Assert.That(c.GetInt("b"), Is.EqualTo(2));
            Assert.That(c.GetInt("c"), Is.EqualTo(3));

            // Giving an empty path to Get() should return the root.
            Assert.That(c.Get(""), Is.EqualTo(d));
        }