public void ShouldAssignVariable() { var value = _engine.Execute("a = 1").GetValue("a"); Assert.NotNull(value); Assert.Equal(1, value.AsType <NumberInstance>().Value); }
private void Execute(string code) { try { engine.Execute(code); } catch (SkryptException e) { Debug.LogError(e); } }
public StructTests(ITestOutputHelper output) { _output = output; _engine = new SkryptEngine(); _engine .SetValue("assert", new Action <bool>(Assert.True)) .SetValue("equal", new Action <object, object>(Assert.Equal)) ; _engine.Execute(@" struct BasicStruct { public A = 0 public B = """" public fn init (a,b) { self.A = a self.B = b } public fn toString () { return ""{"" + self.A + "","" + self.B + ""}"" } } "); }
static void Main(string[] args) { if (args.Any()) { _file = Path.Combine(Directory.GetCurrentDirectory(), args[0]); } if (!string.IsNullOrEmpty(_file)) { RunFile(_file); } while (true) { Console.ForegroundColor = ConsoleColor.White; Console.Write(">"); string line = Console.ReadLine(); if (line == "exit") { return; } if (line.StartsWith("run ")) { _file = Path.Combine( Directory.GetCurrentDirectory(), line.Substring(4) ); if (!string.IsNullOrEmpty(_file)) { RunFile(_file); } continue; } try { _engine.Execute(line); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine(_engine.CompletionValue?.ToString() ?? "null"); } catch (SkryptException e) { Console.ForegroundColor = ConsoleColor.Red; _engine.ErrorHandler.ReportError(e); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(e); } } }
public EngineBenchmarks() { _engine = new SkryptEngine(); // Pre-set value to make sure it exists in the GetValue benchmark _engine.SetValue("A", 1); _engine.Execute(@" fn fibonacci(num) { if (num <= 1) return 1 return fibonacci(num - 1) + fibonacci(num - 2) } "); }
private void RunTest(string source) { _engine.Execute(source, new Compiling.ParserOptions { Tolerant = false }); }
public SkryptEngine ExecuteNumericalExpression() { return(_engine.Execute(@"result = ((A - 2) * 4) / 2")); }
public void ShouldParseNull() { var nullValue = _engine.Execute("null").CompletionValue; Assert.Null(nullValue); }