public void InputParsing_SimpleCommand_TwoTokens() { const string input = "cd ../folder"; InputParseService parser = new InputParseService(); ParsedInput parsed = parser.Parse(input); Assert.Equal(input, parsed.RawInput); Assert.Equal(2, parsed.Tokens.Count); Assert.Equal("cd", parsed.Tokens[0]); Assert.Equal("../folder", parsed.Tokens[1]); }
public void InputParsing_CommandWithTwoComplexParameters_ThreeTokens() { const string input = "_command42 \"complex param '## $ ! | text' \" 'second complex param with \"inner text\"'"; InputParseService parser = new InputParseService(); ParsedInput parsed = parser.Parse(input); Assert.Equal(input, parsed.RawInput); Assert.Equal(3, parsed.Tokens.Count); Assert.Equal("_command42", parsed.Tokens[0]); Assert.Equal("\"complex param '## $ ! | text' \"", parsed.Tokens[1]); Assert.Equal("'second complex param with \"inner text\"'", parsed.Tokens[2]); }
public void InputParsing_CommandWithParametrisedOption_FourTokens() { const string input = "manager --ignore-folders ../folder ../second/sub"; InputParseService parser = new InputParseService(); ParsedInput parsed = parser.Parse(input); Assert.Equal(input, parsed.RawInput); Assert.Equal(4, parsed.Tokens.Count); Assert.Equal("manager", parsed.Tokens[0]); Assert.Equal("--ignore-folders", parsed.Tokens[1]); Assert.Equal("../folder", parsed.Tokens[2]); Assert.Equal("../second/sub", parsed.Tokens[3]); }
public void TreeEvaluation_ConfigurationCommand_EvaluateInput() { const string input = "cd ../folder '../second folder/sub'"; var cdBuilder = Query.CreateBuilder(); var cdParamBuilder = Parameter.CreateBuilder(); cdParamBuilder.Key = "path"; cdParamBuilder.ArgumentTemplate = "[^\\<\\>\\:\\\"\\|\\?\\*[:cntrl:]]+"; cdParamBuilder.IsOptional = true; cdParamBuilder.IsRepeatable = true; cdParamBuilder.Documentation.Title = "Directory path"; cdParamBuilder.Documentation.Description = "Specify full or relative path."; cdBuilder.Key = "current-directory"; cdBuilder.Representations.AddRange(new[] { "current-directory", "cd", "chdir", "cdir" }); cdBuilder.Parameters.Add(cdParamBuilder.ToImmutable()); cdBuilder.Documentation.Title = "Current directory"; cdBuilder.Documentation.Description = "Gets or sets current working directory."; InputTreeBuilder builder = new InputTreeBuilder(new EmptyLogService()); InputTree tree = builder.Build(new[] { cdBuilder.ToImmutable() }, null); IEnvironmentService environment = new EnvironmentService(null); IInputParseService parser = new InputParseService(); InputTreeEvaluationStrategy evaluation = new InputTreeEvaluationStrategy(tree, environment); ParsedInput parsed = parser.Parse(input); Input evaluated = evaluation.Evaluate(parsed); Assert.Equal(parsed, evaluated.ParsedInput); Assert.Equal(3, evaluated.Tokens.Count); Assert.True(evaluated.Context.IsValid); Assert.Equal("current-directory", evaluated.Context.Key); Assert.Empty(evaluated.Context.Options); Assert.Single(evaluated.Context.Parameters); Assert.Equal("../folder", evaluated.Context.Parameters["path"].GetValues()[0]); Assert.Equal("../second folder/sub", evaluated.Context.Parameters["path"].GetValues()[1]); }