Esempio n. 1
0
        public void TestLuaTableConfig()
        {
            Lua lua = new Lua();

            const string inputfile = "{ \"x\": 10, \"y\": \"hello\", \"z\": [ 10, \"yo\" ], \"w\": { \"a\": 20, \"b\": [ 500, 600 ] } }";
            string       filename  = System.IO.Path.GetTempFileName();

            System.IO.File.WriteAllText(filename, inputfile);

            var cfg = ConfigFile.Load <DynamicConfigFile>(filename);

            TestConfigFile(cfg); // This should always pass so long as the CoreTests pass

            LuaTable tbl = Utility.TableFromConfig(cfg, lua);

            Assert.AreEqual(10.0, tbl["x"], "Failed tbl.x");
            Assert.AreEqual("hello", tbl["y"], "Failed tbl.y");

            Assert.IsInstanceOfType(tbl["z"], typeof(LuaTable), "Failed tbl.z");
            LuaTable ztbl = tbl["z"] as LuaTable;

            if (ztbl != null)
            {
                Assert.IsNull(ztbl[0], "Failed tbl.z[0]");
                Assert.AreEqual(10.0, ztbl[1], "Failed tbl.z[1]");
                Assert.AreEqual("yo", ztbl[2], "Failed tbl.z[2]");
                Assert.IsNull(ztbl[3], "Failed tbl.z[3]");
            }

            Assert.IsInstanceOfType(tbl["w"], typeof(LuaTable), "Failed tbl.w");
            LuaTable wtbl = tbl["w"] as LuaTable;

            if (wtbl != null)
            {
                Assert.AreEqual(20.0, wtbl["a"], "Failed tbl.w.a");

                Assert.IsInstanceOfType(wtbl["b"], typeof(LuaTable), "Failed tbl.w.b");
                LuaTable wbtbl = wtbl["b"] as LuaTable;
                if (wbtbl != null)
                {
                    Assert.IsNull(wbtbl[0], "Failed tbl.w.b[0]");
                    Assert.AreEqual(500.0, wbtbl[1], "Failed tbl.w.b[1]");
                    Assert.AreEqual(600.0, wbtbl[2], "Failed tbl.w.b[2]");
                    Assert.IsNull(wbtbl[3], "Failed tbl.w.b[3]");
                }
            }

            cfg = new DynamicConfigFile();
            Utility.SetConfigFromTable(cfg, tbl);

            TestConfigFile(cfg);
        }
Esempio n. 2
0
        public void TestEmptyTableInConfig()
        {
            Lua lua = new Lua();

            lua.LoadString("TeleportData = { AdminTP = {}, Test = 3, ABC=4 }", "test").Call();

            LuaTable          tdata   = lua["TeleportData"] as LuaTable;
            DynamicConfigFile cfgfile = new DynamicConfigFile();

            Utility.SetConfigFromTable(cfgfile, tdata);

            Assert.AreEqual(3, cfgfile["Test"], "Failed TeleportData.Test");
            Assert.AreEqual(4, cfgfile["ABC"], "Failed TeleportData.ABC");

            //Assert.IsInstanceOfType(cfgfile["AdminTP"], typeof(List<string, object>), "Failed TeleportData.AdminTP");

            string tmp = Path.GetTempFileName();

            cfgfile.Save(tmp);

            string text = File.ReadAllText(tmp);

            File.Delete(tmp);
        }
Esempio n. 3
0
 public void TestGetNamespace()
 {
     Assert.AreEqual("System", Utility.GetNamespace(typeof(UInt16)));
     Assert.AreEqual("System.Collections.Generic", Utility.GetNamespace(typeof(System.Collections.Generic.List <string>)));
     Assert.AreEqual("", Utility.GetNamespace(typeof(TestStruct)));
 }