public static TableElement Load(string path) { var source = File.ReadAllText(path ?? throw new ArgumentNullException(nameof(path))).AsStream(); var rep = LuaTableParser.RecipeParser(source); return(rep.Case((str, _) => throw new ParseException(str.Current), (_, elem) => elem)); }
public void ReadAllItemTest() { var files = Directory.GetFiles("./ItemSample"); foreach (var path in files) { var source = File.ReadAllText(path).AsStream(); LuaTableParser.RecipeParser(source).IsSuccess().IsTrue(); } }
public void NestedTest() { var souce = "{1,2,named={10,20},{30,40}}".AsStream(); var actual = LuaTableParser.TableElementParser(souce); actual.Case(Fail, (_, elem) => { elem.GedChildren().Count().Is(4); elem.Traverse().Count().Is(8); var array = elem.Traverse().Where(x => x is ValueElement).Cast <ValueElement>() .Select(x => ((IntegerValue)x.Content).Value).ToArray(); var exp = new[] { 1, 2, 10, 20, 30, 40 }; foreach (var i in exp) { array.Contains(i).IsTrue(); } }); }
public void SimpleTest() { var source = "{1,2,3}"; var actual = LuaTableParser.TableElementParser(source.AsStream()); actual.Case(Fail, (_, elem) => { var array = elem.GedChildren() .Cast <ValueElement>() .Select(x => x.Content) .Cast <IntegerValue>() .Select(x => x.Value) .ToArray(); array.Length.Is(3); array.Contains(1).IsTrue(); array.Contains(2).IsTrue(); array.Contains(3).IsTrue(); }); }