public void ConfigTest() { string file = "config { foo { a = \"test\"; b = \"bar\"; } }"; ScriptEngine engine = new ScriptEngine(); ConfigBuilder.Structure s = new ConfigBuilder.Structure(); s.AddElement(new ConfigBuilder.KeyValueTagBuilder("foo", false)); engine.RegisterBuilder(new ConfigBuilder("config", s, NewConfigBuilt)); engine.Build(file); if (_results == null) { Assert.Fail("Was not returned a configuration."); } Dictionary<string, List<Token>> foo = (Dictionary<string, List<Token>>)_results["foo"][0]; Chunk c = new Chunk(foo["b"], new Script(engine) {UseEngineGlobals = false}); object result = c.Evaluate(); Assert.AreEqual("bar", (string) result); }
public void FunctionConfigTest() { string file = "config { script \"foo\" { return \"foo\"; } script \"bar\" { return 1 + 1; } }"; ScriptEngine engine = new ScriptEngine(); ConfigBuilder.Structure s = new ConfigBuilder.Structure(); s.AddElement(new ConfigBuilder.ScriptTagBuilder()); engine.RegisterBuilder(new ConfigBuilder("config", s, NewConfigBuilt)); engine.Build(file); if (_results == null) { Assert.Fail("ScriptEngine failed to build config."); } ConfigBuilder.ScriptBlock block = (ConfigBuilder.ScriptBlock) _results["script"][0]; object result = block.Code.Evaluate(true); Assert.AreEqual(result, "foo"); block = (ConfigBuilder.ScriptBlock)_results["script"][1]; result = block.Code.Evaluate(true); if (!(result is Number)) { Assert.Fail("Code block did not return Slimterpreter.Number, returned " + result.GetType().Name + " instead."); } Assert.AreEqual(2, (int)(Number)result); System.Console.WriteLine(block); }