public void ZeroReturnsFalse() { var parsed = MoLangParser.Parse("return 0 ?? 'test'"); var result = _runtime.Execute(parsed); Assert.AreEqual(result.AsString(), "test"); }
public void BiggerOrEqualTest() { var parsed = MoLangParser.Parse(@" t.a = 1; loop(10, { t.a = t.a + 1; t.a >= 5 ? break : continue; }); return t.a; "); Assert.IsNotNull(parsed); var result = _runtime.Execute(parsed); Assert.AreEqual(5, result.AsDouble()); }
public void PropertyWrite() { var expression = MoLangParser.Parse("query.life_time = 5"); MoLangRuntime runtime = new MoLangRuntime(); var testStruct = new TestClass(Environment.TickCount); runtime.Environment.Structs.TryAdd( "query", new InteropStruct(testStruct)); runtime.Execute(expression); Assert.AreEqual(5d, testStruct.Lifetime); }
public void PropertyRead() { var expression = MoLangParser.Parse("query.life_time"); var expected = Environment.TickCount * 3.5d; MoLangRuntime runtime = new MoLangRuntime(); runtime.Environment.Structs.TryAdd( "query", new InteropStruct(new TestClass(expected))); var result = runtime.Execute(expression); Assert.AreEqual(expected, result.AsDouble()); }
public void MathFunctions() { MoLangParser parser = new MoLangParser(new TokenIterator("math.floor(10.1 + 20.1)")); parser.ExpressionTraverser.Visitors.Add(new MathOptimizationVisitor()); var expr = parser.Parse(); Assert.IsInstanceOfType(expr, typeof(NumberExpression)); MoLangRuntime runtime = new MoLangRuntime(); var result = runtime.Execute(expr); Assert.AreEqual(30, result.AsDouble()); }
public void Constants() { MoLangParser parser = new MoLangParser(new TokenIterator("7 + 2 * (6 + 3) / 3 - 7")); parser.ExpressionTraverser.Visitors.Add(new MathOptimizationVisitor()); var expr = parser.Parse(); Assert.IsInstanceOfType(expr, typeof(NumberExpression)); MoLangRuntime runtime = new MoLangRuntime(); var result = runtime.Execute(expr); Assert.AreEqual(6, result.AsDouble()); }