public void TestProcedureParametersSingleInput() { var proc = FileBuilder.ParseProcedure("void Func(int a){}"); Assert.AreEqual(typeof(void), proc.ReturnType.Type); Assert.AreEqual(1, proc.Parameters.Length); }
public void TestProcedureParametersNone() { var proc = FileBuilder.ParseProcedure("void Func(){}"); Assert.AreEqual(typeof(void), proc.ReturnType.Type); Assert.AreEqual(0, proc.Parameters.Length); }
public void TestProcedureParametersOnlyReturn() { var proc = FileBuilder.ParseProcedure("int Func(){}"); Assert.AreEqual(typeof(long), proc.ReturnType.Type); Assert.AreEqual(0, proc.Parameters.Length); }
public void TestSimpleVoidProcedureExecution() { var proc = FileBuilder.ParseProcedure("void Func(){}"); Assert.AreEqual(0, proc.Parameters.Length); var ret = proc.Call(); Assert.IsNull(ret); }
public void TestProcedureParametersInterfaceReference() { var proc = FileBuilder.ParseProcedure( typeof(TestProcedureParsing), "void Func( " + typeof(ISomeInterface).Namespace + "." + nameof(ISomeInterface) + " reference){ }"); Assert.AreEqual(typeof(void), proc.ReturnType.Type); Assert.AreEqual(1, proc.Parameters.Length); Assert.AreEqual(typeof(ISomeInterface), proc.Parameters[0].Value.Type); }
public void ExecuteDelay2() { var proc = FileBuilder.ParseProcedure( "void Func(){ delay(200ms); }"); Assert.AreEqual(typeof(void), proc.ReturnType.Type); Assert.AreEqual(0, proc.Parameters.Length); object result = proc.Call(); Assert.IsNull(result); }
public void TestProcedureWhileStatementWithExpression() { var proc = FileBuilder.ParseProcedure( "int Func(){ var output = 0; while ( output < 100) output += 12; return output; }"); Assert.AreEqual(typeof(long), proc.ReturnType.Type); Assert.AreEqual(0, proc.Parameters.Length); object result = proc.Call(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(long)); Assert.AreEqual(108L, (long)result); }
public void TestProcedureWhileStatementWithBlockAndConditionalBreak() { var proc = FileBuilder.ParseProcedure( "int Func(){ var output = 5; var n = 0; while (n < 1000) { output += 13; n++; if (n >= 4) break; } return output; }"); Assert.AreEqual(typeof(long), proc.ReturnType.Type); Assert.AreEqual(0, proc.Parameters.Length); object result = proc.Call(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(long)); Assert.AreEqual(57L, (long)result); }
public void TestSimpleUsing_ExistingVarAlreadyCreated() { var proc = FileBuilder.ParseProcedure( typeof(DummyClass), "int Func()", "{", " var obj = " + typeof(DummyClass).FullName + ".Create();", " using (obj) { obj.PropInt = 27; }", " return obj.PropInt; ", "}"); object result = proc.Call(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(long)); Assert.AreEqual(1107L, (long)result); }
public void CreateReportInProcedure() { var proc = FileBuilder.ParseProcedure( "DataReport Func(){ var data = StartReport(\"daID\", \"daTitle\"); return data; }"); Assert.AreEqual(typeof(DataReport), proc.ReturnType.Type); Assert.AreEqual(0, proc.Parameters.Length); object result = proc.Call(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(DataReport)); var report = result as DataReport; Assert.AreEqual("daID", report.ID); Assert.AreEqual(0, report.ListData().Count()); }
[Ignore] // Interactive interface not implemented public void TestProcedureWhileStatementWithSpecifiedIterationVariable() { var proc = FileBuilder.ParseProcedure( "int Func(){ var n = 9; var m = 0; var c = 0;" + "while (true) : index: c" + "{ n++; if (n >= 16) break; m = c; }" + "return c + m; }"); Assert.AreEqual(typeof(long), proc.ReturnType.Type); Assert.AreEqual(0, proc.Parameters.Length); object result = proc.Call(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(long)); Assert.AreEqual(5, (long)result); }
public void TestSimpleUsing_CreateVar() { var proc = FileBuilder.ParseProcedure( typeof(DummyClass), "int Func()", "{", " " + typeof(DummyClass).FullName + " cpy = null;", " using (var obj = " + typeof(DummyClass).FullName + ".Create()) { obj.PropInt = 19; cpy = obj; }", " return cpy.PropInt; ", "}"); object result = proc.Call(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(long)); Assert.AreEqual(1099L, (long)result); }
public void LogConstantString() { var procedure = FileBuilder.ParseProcedure( "procedure void Anders() {", " log (\"Ello!\");", "}"); var taskContext = ExecutionHelper.ExeContext(); taskContext.CallProcedure(procedure); var log = new LogInspector(taskContext.Logger); log.ExpectNext("0 - Pre - TestRun - Starting"); log.ExpectNext("1 - Pre - Anders - <arguments>"); log.ExpectNext("2 - Normal - 2 - log: Ello!"); log.ExpectNext("2 - Post"); log.ExpectEnd(); }
[Ignore] // Interactive interface not implemented public void TestProcedureWhileStatementWithInteractiveBreak() { var proc = FileBuilder.ParseProcedure( "int Func(){ var n = 0;" + "[Break: \"Stop\"]" + "while (true) : Break: \"Stop\"" + "{ n++; if (n >= 100) break; }" + "return n; }"); Assert.AreEqual(typeof(long), proc.ReturnType.Type); Assert.AreEqual(0, proc.Parameters.Length); object result = proc.Call(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(long)); Assert.AreEqual(5, (long)result); }
public void TestProcedureSimpleIfElseStatement() { var proc = FileBuilder.ParseProcedure( "int Func(bool input){ var result = 0; if (input) result = 175; else result = 126; return result; }"); Assert.AreEqual(typeof(long), proc.ReturnType.Type); Assert.AreEqual(1, proc.Parameters.Length); object result = proc.Call(false); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(long)); Assert.AreEqual(126L, (long)result); result = proc.Call(true); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(long)); Assert.AreEqual(175L, (long)result); }
public void TestProcedureWhileStatementWithTimeout() { var proc = FileBuilder.ParseProcedure( "int Func(){ var n = 0; " + "while (true) :" + " Timeout: 20ms" + "{ n++; if (n > 5000000) break; }" + // ENSURE THIS TAKES MORE THAN 20ms !! "return n; }"); Assert.AreEqual(typeof(long), proc.ReturnType.Type); Assert.AreEqual(0, proc.Parameters.Length); object result = proc.Call(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(long)); Assert.IsTrue((long)result < 5000000); Assert.IsTrue((long)result > 1000); // Just to check that the loop iterated several times }
public void CreateReportWithinUsing() { var proc = FileBuilder.ParseProcedure( "DataReport Func(){ DataReport result = null; using ( var r = StartReport(\"daID\", \"Test#9\")) { expect (5 > 4); result = r; } return result; }"); Assert.AreEqual(typeof(DataReport), proc.ReturnType.Type); Assert.AreEqual(0, proc.Parameters.Length); object result = proc.Call(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(DataReport)); var report = result as DataReport; Assert.AreEqual("daID", report.ID); Assert.AreEqual(1, report.ListData().Count()); var entry = report.ListData().ElementAt(0); Assert.AreEqual(StepBro.Core.Data.Report.ReportDataType.ExpectResult, entry.Type); }
public void LogStringEnumerable() { var procedure = FileBuilder.ParseProcedure(typeof(DummyClass), "procedure void Anders() {", " log (DummyClass.MethodListSomeNames());", "}"); var taskContext = ExecutionHelper.ExeContext(); taskContext.CallProcedure(procedure); var log = new LogInspector(taskContext.Logger); log.ExpectNext("0 - Pre - TestRun - Starting"); log.ExpectNext("1 - Pre - Anders - <arguments>"); log.ExpectNext("2 - Normal - 2 - Anders"); log.ExpectNext("2 - Normal - 2 - Berditto"); log.ExpectNext("2 - Normal - 2 - Chrushtor"); log.ExpectNext("2 - Normal - 2 - Dowfick"); log.ExpectNext("2 - Post"); log.ExpectEnd(); }
public void LogSimpleNonStringTypes() { var procedure = FileBuilder.ParseProcedure( "procedure void Anders() {", " log (true);", " log (36);", " log (pass);", "}"); var taskContext = ExecutionHelper.ExeContext(); taskContext.CallProcedure(procedure); var log = new LogInspector(taskContext.Logger); log.ExpectNext("0 - Pre - TestRun - Starting"); log.ExpectNext("1 - Pre - Anders - <arguments>"); log.ExpectNext("2 - Normal - 2 - log: True"); log.ExpectNext("2 - Normal - 3 - log: 36"); log.ExpectNext("2 - Normal - 4 - log: Pass"); log.ExpectNext("2 - Post"); log.ExpectEnd(); }
public void TestProcedureSimpleIfElseStatementWithBlock() { var proc = FileBuilder.ParseProcedure( "int Func(bool input)", "{ var result = 0;", " if (input) { result = 626; }", " else { result = 262; }", " return result; ", "}"); Assert.AreEqual(typeof(long), proc.ReturnType.Type); Assert.AreEqual(1, proc.Parameters.Length); object result = proc.Call(false); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(long)); Assert.AreEqual(262L, (long)result); result = proc.Call(true); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(long)); Assert.AreEqual(626L, (long)result); }
public static FileBuilder Parse <T>( string returnValueExpression = "0", string statements = "", bool varGeneration = true, bool varDummyClass = false) { string typeName = ""; if (typeof(T) == typeof(long)) { typeName = "int"; } else if (typeof(T) == typeof(double)) { typeName = "decimal"; } else if (typeof(T) == typeof(bool)) { typeName = "bool"; } else if (typeof(T) == typeof(string)) { typeName = "string"; } else if (typeof(T) == typeof(TimeSpan)) { typeName = "timespan"; } else if (typeof(T) == typeof(DateTime)) { typeName = "datetime"; } else if (typeof(T) == typeof(Verdict)) { typeName = "verdict"; } else if (typeof(T) == typeof(DummyDataClass)) { typeName = "DummyDataClass"; } else if (typeof(T) == typeof(DataReport)) { typeName = "DataReport"; } else { throw new NotImplementedException(); } StringBuilder source = new StringBuilder(); source.AppendLine(typeName + " ExpressionProcedure(){"); if (varGeneration || varDummyClass) { AddLocalVariables(source, varDummyClass); } source.AppendLine(statements); source.AppendLine(typeName + " result = " + returnValueExpression + ";"); source.AppendLine("return result;"); source.AppendLine("}"); IAddonManager addons = AddonManager.Create(); addons.AddAssembly(typeof(Enumerable).Assembly, false); addons.AddAssembly(typeof(ExpressionParser).Assembly, false); return(FileBuilder.ParseProcedure( addons, new string[] { typeof(DataReport).Namespace, typeof(DummyClass).FullName, typeof(DummyClass).Namespace }, null, source.ToString())); }