Exemplo n.º 1
0
        public Input Evaluate(string input)
        {
            ParsedInput parsedInput = parser.Parse(input);

            IInputTreeEvaluationStrategy evaluation = new InputTreeEvaluationStrategy(tree, environment);

            return(evaluation.Evaluate(parsedInput));
        }
Exemplo n.º 2
0
        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]);
        }