예제 #1
0
        public void TestWithNoArguments()
        {
            var cmdLine = setUpCommandLine();

            var parsing = Cli.ParseInstructions(cmdLine, new string[] { });

            Assert.IsNull(parsing.Errors);
            Assert.IsEmpty(parsing.Instructions);
        }
예제 #2
0
        public void TestParsingNoArgumentsGivesEmptyInstructions()
        {
            var cmdLine = setUpCommandLine();

            var args    = new string[] { };
            var parsing = Cli.ParseInstructions(cmdLine, args);

            Assert.IsEmpty(parsing.Instructions);
            Assert.AreEqual(0, parsing.AcceptedArgs);
            Assert.IsNull(parsing.Errors);
        }
예제 #3
0
        public void TestWithNoArguments()
        {
            var cmdLine = Cli.DeclareCommandLine(
                "test-program",
                "Tests something.",
                new List <Cli.Command>()
                );

            var parsing = Cli.ParseInstructions(cmdLine, new string[] { });

            Assert.IsNull(parsing.Errors);
            Assert.IsEmpty(parsing.Instructions);
        }
예제 #4
0
        public void TestParsingChainOfCommands()
        {
            var cmdLine = setUpCommandLine();

            var parsing = Cli.ParseInstructions(cmdLine, new[] { "load", "one", "load", "two" });

            Assert.IsNull(parsing.Errors);
            Assert.AreEqual(2, parsing.Instructions.Count);

            Assert.IsInstanceOf <Instruction.Load>(parsing.Instructions[0]);
            Assert.IsInstanceOf <Instruction.Load>(parsing.Instructions[1]);

            var first = (Instruction.Load)parsing.Instructions[0];

            Assert.AreEqual("one", first.Path);

            var second = (Instruction.Load)parsing.Instructions[1];

            Assert.AreEqual("two", second.Path);
        }
예제 #5
0
        public void TestParsingFailedDueToTooFewArguments()
        {
            var cmdLine = setUpCommandLine();

            var args    = new[] { "load" };
            var parsing = Cli.ParseInstructions(cmdLine, args);

            Assert.IsNull(parsing.Instructions);
            Assert.AreEqual(0, parsing.AcceptedArgs);

            var errorMsg = Cli.FormatParsingErrors(args, parsing.AcceptedArgs, parsing.Errors);

            var nl = System.Environment.NewLine;

            Assert.AreEqual(
                $"The command-line arguments could not be parsed.{nl}" +
                $"Arguments (vertically ordered):{nl}" +
                $"load <<< PROBLEM <<<{nl}" +
                nl +
                "Too few arguments specified for the command load. It requires at least one argument.",
                errorMsg);
        }
예제 #6
0
        public void TestParsingFailedDueToAnUnknownCommand()
        {
            var cmdLine = setUpCommandLine();

            var args    = new[] { "load", "one", "unknown-command", "foobar" };
            var parsing = Cli.ParseInstructions(cmdLine, args);

            Assert.IsNull(parsing.Instructions);

            var errorMsg = Cli.FormatParsingErrors(args, parsing.AcceptedArgs, parsing.Errors);

            var nl = System.Environment.NewLine;

            Assert.AreEqual(
                $"The command-line arguments could not be parsed.{nl}" +
                $"Arguments (vertically ordered):{nl}" +
                $"load{nl}" +
                $"one{nl}" +
                $"unknown-command <<< PROBLEM <<<{nl}" +
                $"foobar{nl}" +
                $"{nl}" +
                "Command unknown: unknown-command",
                errorMsg);
        }