public void TestLson01() { var t = new LuaTable() { ["int"] = 1, [1] = 1, ["float"] = 1.0, ["byte"] = (byte)1, ["str"] = "test", ["do"] = true, ["t"] = new LuaTable() { 1, 2, 3, 4 }, [2] = 2, [3] = 3, [10] = 10 }; var s = t.ToLson(); Console.WriteLine(s); var t2 = LuaTable.FromLson(s); Assert.AreEqual(10, t2.Values.Count); }
public void TestLsonParser() { LuaTable t; t = LuaTable.FromLson("{test=\"1.0\"}"); Assert.AreEqual(typeof(string), t["test"].GetType()); t = LuaTable.FromLson("{test=1.0}"); Assert.AreEqual(1.0, t["test"]); t = LuaTable.FromLson("{test=1.}"); Assert.AreEqual(1.0, t["test"]); t = LuaTable.FromLson("{test=1}"); Assert.AreEqual(1, t["test"]); t = LuaTable.FromLson("{test=" + Int64.MaxValue + "0" + "}"); Assert.AreEqual(Int64.MaxValue * 10.0, t["test"]); try { t = LuaTable.FromLson("{test=_test}"); Assert.Fail("Value starting with underscore must not be parsed"); } catch (LuaParseException) { } try { t = LuaTable.FromLson("{test=" + Double.PositiveInfinity.ToString() + "}"); Assert.Fail("Illegal number parsed without Error."); } catch (LuaParseException) { } }
public void TestLsonDouble() { var t = new LuaTable() { ["test"] = 1.0 }; Assert.AreEqual(1.0, LuaTable.FromLson(t.ToLson())["test"]); }
private async Task <LuaTable> _LoadOptionsFileAsync() { _ActivityCount += 1; using (var fs = new FileStream(InstallConfiguration.PSO2DocumentsUserFile, FileMode.Open, FileAccess.Read)) using (var reader = new StreamReader(fs)) { var lua = await reader.ReadToEndAsync(); var lson = Regex.Replace(lua, @"^\s*Ini\s*=\s*", string.Empty); var table = await Task.Run(() => LuaTable.FromLson(lson)); _ActivityCount -= 1; return(table); } }
public void TestLsonDouble() { var t = new LuaTable() { ["test1"] = 1.0, ["test2"] = 1.32, ["test3"] = Double.NaN }; var data = t.ToLson(); Assert.IsTrue(data.IndexOf("test3 = nil") >= 0, "Tag nicht generiert."); var r = LuaTable.FromLson(data); Assert.AreEqual(1.0, r["test1"]); Assert.AreEqual(1.32, r["test2"]); Assert.AreEqual(null, r["test3"]); }
public void TestLsonTypes() { LuaTable t; var timestamp = DateTime.Now; var guid = Guid.NewGuid(); t = new LuaTable() { ["int64max"] = Int64.MaxValue, ["uint64"] = UInt64.MaxValue, ["string"] = "test", ["char"] = '+', ["DateTime"] = timestamp, ["Guid"] = guid }; var result = LuaTable.FromLson(t.ToLson()); Assert.AreEqual(Int64.MaxValue, result["int64max"]); Assert.AreEqual(UInt64.MaxValue, result["uint64"]); Assert.AreEqual("test", result["string"]); Assert.AreEqual("+", result["char"]); Assert.AreEqual(timestamp.ToString("o"), result["DateTime"]); Assert.AreEqual(guid.ToString("B"), result["Guid"]); }
public void TestFromLson01() { dynamic t = LuaTable.FromLson("{ a = true, b = false, c = 10, d = 1099511627776, e = 'test', f = 1.0, g = 1.23, h = 1e10 }"); TestResult(new LuaResult(t.a, t.b, t.c, t.d, t.e, t.f, t.g, t.h), true, false, 10, 1099511627776L, "test", 1.0, 1.23, 1e10); }
public void TestLsonNumberBoundaries() { var t = LuaTable.FromLson("{test=" + Lua.RtConvertValue(Double.MaxValue, typeof(string)) + "0" + "}"); Assert.AreEqual(Double.PositiveInfinity, t["test"]); }
public void TestLsonSpecialChars() { LuaTable t; t = new LuaTable() { ["string_unicode"] = "ⓛ", ["string_esc1"] = "\0", ["string2"] = "\"", ["stringⓛ3"] = "test", ["stri\nng4"] = "test", ["stri\\nng5"] = "test", ["stri\\\nng6"] = "test", ["stri{ng7"] = "test", ["{[\"stri{ng7\"]=\"test\"}8"] = "test", ["stri\x4e00ng9"] = "test" }; var result = LuaTable.FromLson(t.ToLson()); Assert.AreEqual("ⓛ", result["string_unicode"]); Assert.AreEqual("\0", result["string_esc1"]); Assert.AreEqual("\"", result["string2"]); Assert.AreEqual("test", result["stringⓛ3"]); Assert.AreEqual("test", result["stri\nng4"]); Assert.AreEqual("test", result["stri\\nng5"]); Assert.AreEqual("test", result["stri\\\nng6"]); Assert.AreEqual("test", result["stri{ng7"]); Assert.AreEqual("test", result["{[\"stri{ng7\"]=\"test\"}8"]); Assert.AreEqual("test", result["stri\x4e00ng9"]); t = new LuaTable() { ["test1"] = "_test" }; Assert.AreEqual("_test", LuaTable.FromLson(t.ToLson())["test1"]); t = new LuaTable() { ["_test2"] = "test" }; Assert.AreEqual("test", LuaTable.FromLson(t.ToLson())["_test2"]); var keywords = ( from fi in typeof(LuaToken).GetTypeInfo().DeclaredFields let a = fi.GetCustomAttribute <TokenNameAttribute>() where a != null && fi.IsStatic && fi.Name.StartsWith("Kw") orderby a.Name select a.Name ).ToArray(); foreach (var keyword in keywords) { t = new LuaTable() { [keyword] = "test" }; Assert.IsTrue(t.ToLson(false).IndexOf($"[\"{keyword}\"]") >= 0); } foreach (var keyword in keywords) { try { var tt = LuaTable.FromLson("{" + keyword + "=\"test\"}"); Assert.Fail("A keyword was parsed as a member name."); } catch (LuaParseException) { } } }