public void cameraIsTriggeredGetTarget()
        {
            String script = @"
when ""mock camera"" is triggered
  print ""Target: "" + ""mock camera"" target
";

            using (var test = new ScriptTest(script)) {
                var mockCamera = new Mock <IMyCameraBlock>();
                mockCamera.Setup(b => b.CustomData).Returns("");
                mockCamera.Setup(b => b.CanScan(1000)).Returns(false);

                test.MockBlocksOfType("mock camera", mockCamera);
                test.RunOnce();

                Assert.AreEqual(0, test.Logger.Count);
                mockCamera.VerifySet(b => b.EnableRaycast = true);
                mockCamera.Verify(b => b.CanScan(1000));

                test.RunOnce();

                Assert.AreEqual(0, test.Logger.Count);
                mockCamera.Verify(b => b.CanScan(1000));

                mockCamera.Setup(b => b.CanScan(1000)).Returns(true);
                mockCamera.Setup(b => b.Raycast(1000, 0, 0)).Returns(MockDetectedEntity(new Vector3D(1, 2, 3)));
                mockCamera.Setup(b => b.CustomData).Returns("Target=1:2:3");
                test.RunOnce();

                mockCamera.VerifySet(b => b.CustomData = "Target=1:2:3");
                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Target: 1:2:3", test.Logger[0]);
            }
        }
예제 #2
0
        public void asyncThreadsAreAllExecuted()
        {
            String script = @"
:main
async call runAsync
async call runAsync
async call runAsync
print 'Main'

:runAsync
wait
print 'Async'
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();//Execute main, add async threads and execute wait in all 3

                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Main", test.Logger[0]);

                test.RunOnce();//Execute print in all async threads

                Assert.AreEqual(4, test.Logger.Count);
                Assert.AreEqual("Async", test.Logger[1]);
                Assert.AreEqual("Async", test.Logger[2]);
                Assert.AreEqual("Async", test.Logger[3]);
            }
        }
예제 #3
0
        public void asyncCommandsShareGlobalVariables()
        {
            String script = @"
:main
assign global ""a"" to 1
async call printGlobalVariable
async call printGlobalVariable

:printGlobalVariable
print 'Variable is: ' + {a}
assign global ""a"" to {a} + 2
goto printGlobalVariable
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();//Execute main, add async threads which set their variable and print
                Assert.AreEqual(2, test.Logger.Count);
                Assert.AreEqual("Variable is: 1", test.Logger[0]);
                Assert.AreEqual("Variable is: 3", test.Logger[1]);

                test.Logger.Clear();
                test.RunOnce();//Executing async threads again, expect global variable is incremented cumulatively
                Assert.AreEqual(2, test.Logger.Count);
                Assert.AreEqual("Variable is: 5", test.Logger[0]);
                Assert.AreEqual("Variable is: 7", test.Logger[1]);
            }
        }
예제 #4
0
        public void asyncCommandLocalVariablesTakePrecedenceOverGlobalVariables()
        {
            String script = @"
:main
assign global ""a"" to 1
async call printVariable
async call printVariable
call ""printGlobalVariable""

:printGlobalVariable
Print ""Global Variable is: "" + {a}
goto ""printGlobalVariable""

:printVariable
print 'Variable is: ' + {a}
assign ""a"" to {a} + 2
goto printVariable
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();//Execute main, add async threads which set their variable and print
                Assert.AreEqual(3, test.Logger.Count);
                Assert.AreEqual("Global Variable is: 1", test.Logger[0]);
                Assert.AreEqual("Variable is: 1", test.Logger[1]);
                Assert.AreEqual("Variable is: 1", test.Logger[2]);

                test.Logger.Clear();
                test.RunOnce();//Executing async threads again, expect variables are incremented independently
                Assert.AreEqual(3, test.Logger.Count);
                Assert.AreEqual("Global Variable is: 1", test.Logger[0]);
                Assert.AreEqual("Variable is: 3", test.Logger[1]);
                Assert.AreEqual("Variable is: 3", test.Logger[2]);
            }
        }
예제 #5
0
        public void asyncCommandVariablesAreThreadLocal()
        {
            String script = @"
:main
async call printLocalVariable 1
async call printLocalVariable 2

:printLocalVariable ""a""
print 'Variable is: ' + {a}
assign ""a"" to {a} + 2
goto printLocalVariable {a}
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();//Execute main, add async threads which set their variable and print
                Assert.AreEqual(2, test.Logger.Count);
                Assert.AreEqual("Variable is: 1", test.Logger[0]);
                Assert.AreEqual("Variable is: 2", test.Logger[1]);

                test.Logger.Clear();
                test.RunOnce();//Executing async threads again, expect variables are incremented independently
                Assert.AreEqual(2, test.Logger.Count);
                Assert.AreEqual("Variable is: 3", test.Logger[0]);
                Assert.AreEqual("Variable is: 4", test.Logger[1]);
            }
        }
예제 #6
0
        public void GetShipProximityStoppedTarget()
        {
            using (ScriptTest test = new ScriptTest(script)) {
                var mockCamera = new Mock <IMyCameraBlock>();
                test.MockBlocksOfType("My Camera", mockCamera);
                mockCamera.Setup(b => b.CanScan(1000)).Returns(false);
                mockCamera.Setup(b => b.CustomData).Returns("Range=10000");

                test.RunOnce();

                mockCamera.VerifySet(b => b.CustomData = "Range=10000");

                Assert.AreEqual(0, test.Logger.Count);

                mockCamera.Setup(b => b.Position).Returns(Vector3I.Zero);
                mockCamera.Setup(b => b.CanScan(10000)).Returns(true);
                mockCamera.Setup(b => b.Raycast(10000, 0, 0)).Returns(MockDetectedEntity(new Vector3D(1100, 1100, 0), new Vector3D(0, 0, 0)));
                mockCamera.Setup(b => b.CustomData).Returns(@"
Range=10000
Target=1100:1100:0
Velocity=0:0:0
");

                test.RunOnce();

                Assert.AreEqual(2, test.Logger.Count);
                Assert.AreEqual("Distance To Target: 1.56km", test.Logger[0]);
                Assert.AreEqual("Closest Approach: 1.56km", test.Logger[1]);
            }
        }
        public void NoScannedTargetDeletesPreviouslyStoredTarget()
        {
            String script = @"
print ""Target: "" + avg ""mock camera"" target
";

            using (var test = new ScriptTest(script)) {
                var mockCamera = new Mock <IMyCameraBlock>();
                mockCamera.Setup(b => b.CanScan(1000)).Returns(false);
                mockCamera.Setup(b => b.CustomData).Returns("Target=1:2:3");

                test.MockBlocksOfType("mock camera", mockCamera);
                test.RunOnce();
                mockCamera.VerifySet(b => b.EnableRaycast = true);
                mockCamera.Verify(b => b.CanScan(1000));

                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Target: 1:2:3", test.Logger[0]);

                test.Logger.Clear();
                mockCamera.Setup(b => b.CanScan(1000)).Returns(true);
                mockCamera.Setup(b => b.Raycast(1000, 0, 0)).Returns(MockNoDetectedEntity());
                mockCamera.Setup(b => b.CustomData).Returns("");
                test.RunOnce();

                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Target: 0:0:0", test.Logger[0]);
                mockCamera.VerifySet(b => b.CustomData = "");
            }
        }
예제 #8
0
        public void TriggerTheSensorAndGetTarget()
        {
            String script = @"
when ""mock sensor"" is triggered
  print ""Target: "" + ""mock sensor"" target
";

            using (var test = new ScriptTest(script)) {
                var mockSensor = new Mock <IMySensorBlock>();
                mockSensor.Setup(b => b.CustomData).Returns("");
                mockSensor.Setup(b => b.IsActive).Returns(false);

                test.MockBlocksOfType("mock sensor", mockSensor);
                test.RunOnce();

                Assert.AreEqual(0, test.Logger.Count);

                test.RunOnce();

                Assert.AreEqual(0, test.Logger.Count);

                mockSensor.Setup(b => b.IsActive).Returns(true);
                mockSensor.Setup(b => b.LastDetectedEntity).Returns(MockDetectedEntity(new Vector3D(1, 2, 3)));
                test.RunOnce();

                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Target: 1:2:3", test.Logger[0]);
            }
        }
        public void updatedScriptAutoParsesAndRestarts()
        {
            String script = @"
            :main
            #This is a comment
            print 'Hello World'
            replay
            ";

            String newScript = @"
            :main
            #This is a comment
            print 'Hello New World'
            ";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();
                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Hello World", test.Logger[0]);
                test.setScript(newScript);
                test.Logger.Clear();
                test.RunOnce();
                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Hello New World", test.Logger[0]);
            }
        }
예제 #10
0
        public void threadNamesAreProperlySet()
        {
            String script = @"
:main
async call runAsync
print 'Main'

:runAsync
wait
print 'Async'

:handleMessage
Print ""Message""
";

            using (var test = new ScriptTest(script)) {
                test.program.logLevel = LogLevel.INFO;
                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("[Main] main"));
                Assert.IsTrue(test.Logger.Contains("[Async] runAsync"));

                test.program.Main("call handleMessage");

                Assert.IsTrue(test.Logger.Contains("[Request] call handleMessage"));
            }
        }
예제 #11
0
        public void blockingCommandsAreHonored()
        {
            String script = @"
:main
print 'Hello World'
wait
print 'I Got Printed'
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();

                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Hello World", test.Logger[0]);

                test.RunOnce();

                Assert.AreEqual(2, test.Logger.Count);
                Assert.AreEqual("I Got Printed", test.Logger[1]);
            }
        }
        public void emptyScriptPrintsWelcomeMessage()
        {
            String script = "";

            using (var test = new ScriptTest(script)) {
                test.program.logLevel = Program.LogLevel.INFO;
                test.RunOnce();
                Assert.AreEqual(2, test.Logger.Count);
                Assert.AreEqual("Welcome to EasyCommands!", test.Logger[0]);
                Assert.AreEqual("Add Commands to Custom Data", test.Logger[1]);
            }
        }
예제 #13
0
        public void asyncCommandGotoStaysInSameThread()
        {
            String script = @"
:main
async call runAsync
async call runAsync
print 'Main'
wait
print 'Still Main'

:runAsync
wait
print 'Async'
goto ""stillInThread""

:stillInThread
print 'Still Async'
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();//Execute main, add async threads which wait 1 turn

                Assert.AreEqual(1, test.Logger.Count);
                Assert.AreEqual("Main", test.Logger[0]);

                test.RunOnce();//Execute print in both async threads. execute goto in both async threads

                Assert.AreEqual(4, test.Logger.Count);
                Assert.AreEqual("Still Main", test.Logger[1]);
                Assert.AreEqual("Async", test.Logger[2]);
                Assert.AreEqual("Async", test.Logger[3]);

                test.RunUntilDone(); //Execute stillInThread in both async threads, which should complete and terminate.

                Assert.AreEqual(6, test.Logger.Count);
                Assert.AreEqual("Still Async", test.Logger[4]);
                Assert.AreEqual("Still Async", test.Logger[5]);
            }
        }
예제 #14
0
        public void PrintSimpleListSize()
        {
            String script = @"
:main
assign myList to [1, 2, 3]
Print ""myList Size: "" + count of myList[]
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("myList Size: 3"));
            }
        }
        public void PrintCorrectLineNumberWhenUnableToParseAndImpliedMain()
        {
            String script = @"
print 'Hello World'
'Hello World'
";

            using (var test = new ScriptTest(script)) {
                test.program.logLevel = Program.LogLevel.INFO;
                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("Unable to parse command from command parameters at line number: 2"));
            }
        }
예제 #16
0
        public void PrintSimpleListValueAtIndex()
        {
            String script = @"
:main
assign myList to [1, 2, 3]
Print ""myList[2] = "" + myList[2]
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("myList[2] = 3"));
            }
        }
예제 #17
0
        public void CheckAllValuesAgainstValue()
        {
            String script = @"
:main
assign myList to [1, 2, 3]
if all myList[] > 0
  Print ""All values are greater than 0""
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("All values are greater than 0"));
            }
        }
예제 #18
0
        public void GetNonExistentValueByKeyReturnsEmptyList()
        {
            String script = @"
:main
assign myList to []
assign myList[""key""] to ""value""
Print ""myList[missingKey] = "" + myList[""missingKey""]
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("myList[missingKey] = []"));
            }
        }
예제 #19
0
        public void GetShipProximityNoTarget()
        {
            using (ScriptTest test = new ScriptTest(script)) {
                var mockCamera = new Mock <IMyCameraBlock>();
                test.MockBlocksOfType("My Camera", mockCamera);
                mockCamera.Setup(b => b.CanScan(1000)).Returns(false);
                mockCamera.Setup(b => b.CustomData).Returns("Range=10000");

                test.RunOnce();

                mockCamera.VerifySet(b => b.CustomData = "Range=10000");

                Assert.AreEqual(0, test.Logger.Count);

                mockCamera.Setup(b => b.Position).Returns(Vector3I.Zero);
                mockCamera.Setup(b => b.CanScan(10000)).Returns(true);
                mockCamera.Setup(b => b.Raycast(10000, 0, 0)).Returns(MockNoDetectedEntity());
                mockCamera.Setup(b => b.CustomData).Returns("Range=10000");

                test.RunOnce();

                Assert.AreEqual(0, test.Logger.Count);
            }
        }
예제 #20
0
        public void AssignGlobalVariableWithSet()
        {
            var script = @"
set global b to a + 1
Print ""b is: "" + b
";

            using (var test = new ScriptTest(script)) {
                test.program.logLevel = Program.LogLevel.INFO;

                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("b is: a1"));
            }
        }
예제 #21
0
        public void TestImplicitStringValue()
        {
            var script = @"
assign b to a + 1
Print ""b is: "" + b
";

            using (var test = new ScriptTest(script)) {
                test.program.logLevel = Program.LogLevel.INFO;

                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("b is: a1"));
            }
        }
예제 #22
0
        public void finishedCommandsGetProcessedInSameTick()
        {
            String script = @"
:main
print 'Hello World'
print 'I Got Printed'
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();

                Assert.AreEqual(2, test.Logger.Count);
                Assert.AreEqual("Hello World", test.Logger[0]);
                Assert.AreEqual("I Got Printed", test.Logger[1]);
            }
        }
예제 #23
0
        public void GetItemInListByKeyedValue()
        {
            String script = @"
:main
assign myList to []
assign myKey to ""key""
assign myList[myKey] to ""value""
Print ""myList["" + myKey + ""] = "" + myList[myKey]
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("myList[key] = value"));
            }
        }
예제 #24
0
        public void CheckIfListContainsValue()
        {
            String script = @"
:main
assign myList to [""one"", ""two"", ""three""]
assign i to ""one""
if any myList[] is i
  Print ""myList contains "" + i
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("myList contains one"));
            }
        }
예제 #25
0
        public void AssignVariableToListSetsImmutableValue()
        {
            String script = @"
:main
assign i to 0
assign myList to [i,1,2,3]
assign i to 1
Print ""List: "" + myList
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("List: [0,1,2,3]"));
            }
        }
예제 #26
0
        public void InsertAtBeginnngSimpleList()
        {
            String script = @"
:main
assign myList to [1,2,3,4]
Print ""Before: "" + myList
assign myList to [5] + myList
Print ""After: "" + myList
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("Before: [1,2,3,4]"));
                Assert.IsTrue(test.Logger.Contains("After: [5,1,2,3,4]"));
            }
        }
예제 #27
0
        public void RemoveFromListByIndexes()
        {
            String script = @"
:main
assign myList to [1,2,3,4,5,6]
Print ""Before: "" + myList
assign myList to myList - [0,2,4]
Print ""After: "" + myList
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("Before: [1,2,3,4,5,6]"));
                Assert.IsTrue(test.Logger.Contains("After: [2,4,6]"));
            }
        }
예제 #28
0
        public void InsertIntoMiddleOfList()
        {
            String script = @"
:main
assign myList to [1,2,3,4,5]
Print ""Before: "" + myList
assign myList to myList[0 .. 2] + [6] + myList[3..4]
Print ""After: "" + myList
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("Before: [1,2,3,4,5]"));
                Assert.IsTrue(test.Logger.Contains("After: [1,2,3,6,4,5]"));
            }
        }
예제 #29
0
        public void AssignVariableToSubList()
        {
            String script = @"
:main
assign myList to [1,2,3,4]
Print ""List: "" + myList
assign mySubList to myList[2,3]
Print ""SubList: "" + mySubList
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("List: [1,2,3,4]"));
                Assert.IsTrue(test.Logger.Contains("SubList: [3,4]"));
            }
        }
예제 #30
0
        public void AssignMultiDimensionalListValueAtIndex()
        {
            String script = @"
:main
assign myList to [[0,1],[2,3]]
Print ""Before: ""  + myList
assign myList[1][1] to 4
Print ""After: "" + myList
";

            using (var test = new ScriptTest(script)) {
                test.RunOnce();

                Assert.IsTrue(test.Logger.Contains("Before: [[0,1],[2,3]]"));
                Assert.IsTrue(test.Logger.Contains("After: [[0,1],[2,4]]"));
            }
        }