예제 #1
0
        public void WriteKeyedTest()
        {
            using (var sw = new StringWriter())
                using (var tw = new LuaTableTextWriter(sw))
                {
                    tw.WriteStartTable();
                    tw.WriteKey("Test");
                    tw.WriteLiteral("value");
                    tw.WriteKey(123);
                    tw.WriteLiteral(456);
                    tw.WriteKey(TimeSpan.FromHours(3.2));
                    tw.WriteNil();
                    tw.WriteKey("while");
                    tw.WriteNil();
                    tw.WriteKey("function");
                    tw.WriteNil();

                    // Though it's meaningless…
                    tw.WriteStartKey();
                    tw.WriteStartTable();
                    tw.WriteLiteral(1);
                    tw.WriteLiteral(2);
                    tw.WriteEndTable();
                    tw.WriteEndKey();
                    tw.WriteLiteral(123);

                    tw.WriteEndTable();
                    tw.Flush();
                    Assert.Equal("{Test=\"value\",[123]=456,[\"03:12:00\"]=nil,[\"while\"]=nil,[\"function\"]=nil,[{1,2}]=123}", sw.ToString());
                }
        }
예제 #2
0
        public void WriteOutsideTableTest()
        {
            using (var sw = new StringWriter())
                using (var tw = new LuaTableTextWriter(sw))
                {
                    tw.WriteLiteral(123);

                    tw.WriteStartKey();
                    tw.WriteLiteral(2);
                    tw.WriteEndKey();

                    tw.WriteLiteral(456);

                    tw.WriteKey("key");
                    tw.WriteLiteral("value");

                    tw.WriteLiteral("last");

                    tw.Flush();
                    Assert.Equal("123,[2]=456,key=\"value\",\"last\"", sw.ToString());
                }
        }