static private Run ( string source ) : |
||
source | string | |
return |
public void PowerTests() { var result = ScriptProcessorFactory.Run("2**3"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 8); }
public void IncrementTests() { var result = ScriptProcessorFactory.Run("var a = 13; a++; a;"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 14); }
public void DecrementTests() { var result = ScriptProcessorFactory.Run("var b = 13; b--; b;"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 12); }
public void DivisionTests() { var result = ScriptProcessorFactory.Run("15/5"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 3); }
public void MultiplicationTests() { var result = ScriptProcessorFactory.Run("5*3*-4"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, -60); }
public void LogicalOrTests() { var result = ScriptProcessorFactory.Run("true || false"); Assert.IsTrue(result is SBool); Assert.AreEqual(((SBool)result).Value, true); }
public void ModuloTests() { var result = ScriptProcessorFactory.Run("5%2"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 1); }
public void CustomFunctionTests() { var result = ScriptProcessorFactory.Run("class testClass { var member = 0; function customFunction() { this.member = 3; } } var test = new testClass(); test.customFunction(); test.member;"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 3); }
public void InterpolationTests() { var result = ScriptProcessorFactory.Run("var insert = \"{{World}}\"; var outer = $\"{{Hello}}, {insert}!\"; outer;"); Assert.IsTrue(result is SString); Assert.AreEqual("{Hello}, {{World}}!", ((SString)result).Value); }
public void BreakTests() { var result = ScriptProcessorFactory.Run("var a = 0; for (var i = 0; i < 10; i++) { if (i > 5) { break; } a++; } a;"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 6); }
public void AdditionTests() { var result = ScriptProcessorFactory.Run("1+4+6"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 11); }
public void ForLoopTests() { var result = ScriptProcessorFactory.Run("var a = 0; for (var i = 0; i < 10; i++) { a++; } a;"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 10); }
public void ContinueTests() { var result = ScriptProcessorFactory.Run("var a = 0; for (var i = 0; i < 10; i++) { if (i % 2 == 0) { a++; } } a;"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 5); }
public void AbstractTests() { var result = ScriptProcessorFactory.Run("class abstract baseClass { } var test = new baseClass();"); // cannot instanciate abstract class: Assert.IsTrue(result is SError); }
public void IfElseTests() { var result = ScriptProcessorFactory.Run("var a = 0; if (a > 0) { a = 5; } else { a = 10; } a;"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 10); }
public void PropertyTests() { var result = ScriptProcessorFactory.Run("class testClass { var member = 0; function property get Member() { return member; } function property set Member(value) { member = value; } } var test = new testClass(); test.Member = 3; test.Member;"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 3); }
public void IndexerTests() { var result = ScriptProcessorFactory.Run("class testClass { var member = 0; function indexer get indexerGet(accessor) { return this.member * accessor; } function indexer set indexerSet(accessor, value) { this.member = value / accessor; } } var test = new testClass(); test[3] = 9; test[3];"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 9); }
public void StaticVarTests() { var result = ScriptProcessorFactory.Run("class testClass { var static member = 0; } testClass.member = 3; testClass.member;"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 3); }
public void StaticFunctionTests() { var result = ScriptProcessorFactory.Run("class testClass { var static member = 0; function static testFunction() { member = 3; } } testClass.testFunction(); testClass.member;"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 3); }
public void ReadonlyVarTests() { var result = ScriptProcessorFactory.Run("class testClass { var readonly member = 0; } var test = new testClass(); test.member = 3; test.member;"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 0); }
public void SubtractionTests() { var result = ScriptProcessorFactory.Run("12-4-6"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 2); }
public void VariableDeclarationTests() { var result = ScriptProcessorFactory.Run("class testClass { var member = 3 } var test = new testClass(); test.member;"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 3); }
public void ExtendsTests() { var result = ScriptProcessorFactory.Run("class abstract baseClass { var member = 3; function baseFunction() { this.member += 2; } } class extendingClass extends baseClass { function extendsFunction() { baseFunction(); } } var test = new extendingClass(); test.extendsFunction(); test.member;"); Assert.IsTrue(result is SNumber); Assert.AreEqual(((SNumber)result).Value, 5); }
public void InstanciationTests() { var result = ScriptProcessorFactory.Run("class testClass { } var test = new testClass(); test;"); Assert.IsTrue(result is SProtoObject); var protoObj = (SProtoObject)result; Assert.AreEqual(protoObj.Prototype.Name, "testClass"); }