示例#1
0
        public void ArgStringPipeTest()
        {
            ShellParser  shellParser = MakeParser("\"12345 | echo asdf\"");
            ArgContext   context     = shellParser.arg();
            ShellVisitor visitor     = new ShellVisitor();

            ParserResult result = visitor.Visit(context);

            result.IsArg.Should().BeTrue();
            result.ArgValue.Should().Be("12345 | echo asdf");
        }
示例#2
0
        public void ArgStringSingleQuoteTest()
        {
            ShellParser  shellParser = MakeParser("'string arg'");
            ArgContext   context     = shellParser.arg();
            ShellVisitor visitor     = new ShellVisitor();

            ParserResult result = visitor.Visit(context);

            result.IsArg.Should().BeTrue();
            result.ArgValue.Should().Be("string arg");
        }
示例#3
0
        public void ArgWordTest()
        {
            ShellParser  shellParser = MakeParser("wordarg");
            ArgContext   context     = shellParser.arg();
            ShellVisitor visitor     = new ShellVisitor();

            ParserResult result = visitor.Visit(context);

            result.IsArg.Should().BeTrue();
            result.ArgValue.Should().Be("wordarg");
        }
示例#4
0
        public void CmdTest()
        {
            ShellParser  shellParser = MakeParser("cmdword");
            CmdContext   context     = shellParser.cmd();
            ShellVisitor visitor     = new ShellVisitor();

            ParserResult result = visitor.Visit(context);

            result.IsCmd.Should().BeTrue();
            result.CmdValue.Should().Be("cmdword");
        }
示例#5
0
        public void SimpleCommandNoArgsTest()
        {
            ShellParser          shellParser = MakeParser("git");
            SimpleCommandContext context     = shellParser.simpleCommand();
            ShellVisitor         visitor     = new ShellVisitor();

            ParserResult  result        = visitor.Visit(context);
            SimpleCommand actualCommand = result.SimpleCommandValue;

            result.IsSimpleCommand.Should().BeTrue();
            actualCommand.Command.Should().Be("git");
            actualCommand.Arguments.Should().BeEmpty();
        }
示例#6
0
        public void PipeListOneCommandTest()
        {
            ShellParser     shellParser = MakeParser("git reset --hard");
            PipeListContext context     = shellParser.pipeList();
            ShellVisitor    visitor     = new ShellVisitor();

            ParserResult         result         = visitor.Visit(context);
            List <SimpleCommand> actualPipeList = result.PipeListValue;

            result.IsPipeList.Should().BeTrue();
            actualPipeList.Should().HaveCount(1);
            actualPipeList[0].ToString().Should().Be("git reset --hard");
        }
示例#7
0
        public void ShellCommandOnlyPipesTest()
        {
            ShellParser         shellParser = MakeParser("git reset --hard | echo");
            ShellCommandContext context     = shellParser.shellCommand();
            ShellVisitor        visitor     = new ShellVisitor();

            ParserResult result       = visitor.Visit(context);
            ShellCommand shellCommand = result.ShellCommandValue;

            result.IsShellCommand.Should().BeTrue();
            shellCommand.IsBackground.Should().BeFalse();
            shellCommand.CommandList.Should().HaveCount(2);
        }
示例#8
0
        public void ArgListMixedArgsTest()
        {
            ShellParser  shellParser = MakeParser("these are 'some args'");
            ArgsContext  context     = shellParser.args();
            ShellVisitor visitor     = new ShellVisitor();

            ParserResult result = visitor.Visit(context);

            result.IsArgList.Should().BeTrue();
            result.ArgListValue.Should().BeEquivalentTo(new List <string> {
                "these", "are", "some args"
            }, opts => opts.WithStrictOrdering());
        }
示例#9
0
        public void ArgListOneWordTest()
        {
            ShellParser  shellParser = MakeParser("wordarg");
            ArgsContext  context     = shellParser.args();
            ShellVisitor visitor     = new ShellVisitor();

            ParserResult result = visitor.Visit(context);

            result.IsArgList.Should().BeTrue();
            result.ArgListValue.Should().BeEquivalentTo(new List <string> {
                "wordarg"
            }, opts => opts.WithStrictOrdering());
        }
示例#10
0
        public void ShellCommandSingleCommandTest()
        {
            ShellParser         shellParser = MakeParser("git reset --hard");
            ShellCommandContext context     = shellParser.shellCommand();
            ShellVisitor        visitor     = new ShellVisitor();

            ParserResult result       = visitor.Visit(context);
            ShellCommand shellCommand = result.ShellCommandValue;

            result.IsShellCommand.Should().BeTrue();
            shellCommand.IsBackground.Should().BeFalse();
            shellCommand.CommandList.Should().HaveCount(1);
            shellCommand.CommandList[0].ToString().Should().Be("git reset --hard");
        }
示例#11
0
        public void SimpleCommandWithArgsTest()
        {
            ShellParser          shellParser = MakeParser("git reset --hard");
            SimpleCommandContext context     = shellParser.simpleCommand();
            ShellVisitor         visitor     = new ShellVisitor();

            ParserResult  result        = visitor.Visit(context);
            SimpleCommand actualCommand = result.SimpleCommandValue;

            result.IsSimpleCommand.Should().BeTrue();
            actualCommand.Command.Should().Be("git");
            actualCommand.Arguments.Should().BeEquivalentTo(new List <string> {
                "reset", "--hard"
            }, opt => opt.WithStrictOrdering());
        }