Пример #1
0
        public void TestChangeCommand()
        {
            //setup
            BaseExecuteCommand command1 = new ExecuteAt(new SharpCraft.Selector())
            {
                ExecuteCommand = new ExecuteAlign(true, true, true)
            };
            BaseExecuteCommand command2 = new ExecuteAt(new SharpCraft.Selector())
            {
                ExecuteCommand = new ExecuteAlign(true, true, true)
            };

            //test
            Assert.IsNull(command1.ChangeCommand(new ExecuteAs(ID.Selector.a)));
            Assert.IsFalse(command1.DoneChanging, "Adding another execute command shouldnt stop the changer");

            Assert.IsNull(command1.ChangeCommand(new SayCommand("hello")));
            Assert.IsTrue(command1.DoneChanging, "Adding an end command should stop the changer");

            Assert.IsNotNull(command1.ChangeCommand(new SayCommand("hello")));
            Assert.IsTrue(command1.DoneChanging, "Execute command ending in a command should stop the changer");

            Assert.IsNull(command2.ChangeCommand(new StopExecuteCommand()));
            Assert.IsTrue(command2.DoneChanging, "Execute command is not done executing after adding stop command");
        }
Пример #2
0
        public void TestExecuteCommandStacking()
        {
            //setup
            ExecuteAt    command1 = new ExecuteAt(new SharpCraft.Selector());
            ExecuteAlign command2 = new ExecuteAlign(true, false, true);
            TestICommand command3 = new TestICommand();

            command1.ExecuteCommand = command2;
            command2.ExecuteCommand = command3;

            //test
            Assert.AreEqual("execute at @s align xz run hello world", command1.GetCommandString(), "Execute commands does not return correct GetCommandString");
        }
Пример #3
0
        public void TestHasEndCommand()
        {
            //setup
            BaseExecuteCommand command1 = new ExecuteAt(new SharpCraft.Selector())
            {
                ExecuteCommand = new ExecuteAlign(true, true, true)
                {
                    ExecuteCommand = new SayCommand("hello")
                }
            };
            BaseExecuteCommand command2 = new ExecuteAt(new SharpCraft.Selector())
            {
                ExecuteCommand = new ExecuteAlign(true, true, true)
                {
                    ExecuteCommand = new ExecuteAs(ID.Selector.a)
                }
            };

            //test
            Assert.IsTrue(command1.HasEndCommand(), "HasEndCommand doesn't see the end command");
            Assert.IsFalse(command2.HasEndCommand(), "HasEndCommand doesn't see that the last command is an execute command");
        }
Пример #4
0
        public void TestCustomGroupCommands()
        {
            //setup
            using Datapack pack = new Datapack("datapacks", "pack", "a pack", 0, new NoneFileCreator());
            PackNamespace space    = pack.Namespace("space");
            Function      function = space.Function("function", BaseFile.WriteSetting.OnDispose);

            BaseCommand command1 = new ExecuteAt(ID.Selector.s);
            BaseCommand command2 = new SayCommand("123");
            BaseCommand command3 = new SayMeCommand("123");
            BaseCommand command4 = new ExecuteAs(ID.Selector.s);

            //test
            //without execute at start
            function.Custom.GroupCommands((f) =>
            {
                f.AddCommand(command1.ShallowClone());
                f.AddCommand(command2);
                f.AddCommand(command3);
            });
            Assert.AreEqual("execute at @s run say 123", function.Commands[0].GetCommandString(), "Get first grouped command string returned wrong string");
            Assert.AreEqual("me 123", function.Commands[1].GetCommandString(), "Get second grouped command string returned wrong string");

            //with execute at start
            function.Commands.Clear();
            function.AddCommand(command1.ShallowClone());
            function.Custom.GroupCommands((f) =>
            {
                f.AddCommand(command2);
                f.AddCommand(command4.ShallowClone());
                f.AddCommand(command3);
            });
            Assert.AreEqual("execute at @s run say 123", function.Commands[0].GetCommandString(), "Get first executed grouped command string returned wrong string");
            Assert.AreEqual("execute at @s as @s run me 123", function.Commands[1].GetCommandString(), "Get second executed grouped command string returned wrong string");

            //using function
            function.Commands.Clear();
            function.AddCommand(command1.ShallowClone());
            function.Custom.GroupCommands((f) =>
            {
                f.AddCommand(command2);
                f.AddCommand(command1.ShallowClone());
                f.AddCommand(command3);
            }, true);
            Function addedFunction = (((function.Commands[0] as BaseExecuteCommand) !.ExecuteCommand as RunFunctionCommand) !.Function as Function) !;

            Assert.AreEqual("say 123", addedFunction.Commands[0].GetCommandString(), "Get first function grouped command string returned wrong string");
            Assert.AreEqual("execute at @s run me 123", addedFunction.Commands[1].GetCommandString(), "Get second function grouped command string returned wrong string");
            Assert.AreEqual(2, addedFunction.Commands.Count, "function grouped command doesn't contain the correct amount of commands");

            space.AddSetting(NamespaceSettings.GetSettings().FunctionGroupedCommands());
            function.Commands.Clear();
            function.AddCommand(command1.ShallowClone());
            function.Custom.GroupCommands((f) =>
            {
                f.AddCommand(command2);
                f.AddCommand(command1.ShallowClone());
                f.AddCommand(command3);
            });
            addedFunction = (((function.Commands[0] as BaseExecuteCommand) !.ExecuteCommand as RunFunctionCommand) !.Function as Function) !;
            Assert.AreEqual(2, addedFunction.Commands.Count, "automatic function grouped command doesn't get the correct commands");
        }
Пример #5
0
 public int CompareTo(IScheduledTask other)
 {
     return(ExecuteAt.CompareTo(other.ExecuteAt));
 }