public void TestWithNoArguments()
        {
            var cmdLine = setUpCommandLine();

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

            Assert.IsNull(parsing.Errors);
            Assert.IsEmpty(parsing.Instructions);
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }