Exemplo n.º 1
0
        public void InputTree_BuildTexo_TexoTree()
        {
            InputTreeBuilder builder = new InputTreeBuilder(new EmptyLogService());
            InputTree        tree    = builder.Build(new[] { CommandsBuilder.BuildTexo() }, null);

            Assert.NotNull(tree);
            Assert.NotNull(tree.Root);
            Assert.NotNull(tree.Root.Queries["texo"]);
            Assert.Equal(6, tree.Root.Queries["texo"].Queries.Count);
        }
Exemplo n.º 2
0
        public void InputTree_BuildCurrentDirectory_CurrentDirectoryTree()
        {
            InputTreeBuilder builder = new InputTreeBuilder(new EmptyLogService());
            InputTree        tree    = builder.Build(new[] { CommandsBuilder.BuildCurrentDirectory() }, null);

            Assert.NotNull(tree);
            Assert.NotNull(tree.Root);
            Assert.Equal(4, tree.Root.Queries.Count);
            Assert.Null(tree.Root.DefaultQuery);
            Assert.Single(tree.Root.Queries["cd"].Parameters);
        }
Exemplo n.º 3
0
        public void InputTree_BuildHelp_HelpTree()
        {
            InputTreeBuilder builder = new InputTreeBuilder(new EmptyLogService());
            InputTree        tree    = builder.Build(new[] { CommandsBuilder.BuildHelp() }, null);

            Assert.NotNull(tree);
            Assert.NotNull(tree.Root);
            Assert.NotNull(tree.Root.Queries["help"]);
            Assert.Empty(tree.Root.Queries["help"].Queries);
            Assert.Empty(tree.Root.Queries["help"].Options);
            Assert.Single(tree.Root.Queries["help"].Parameters);
        }
Exemplo n.º 4
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]);
        }
Exemplo n.º 5
0
        private InputTree BuildInputTree(TexoConfiguration fromConfiguration)
        {
            IInputTreeBuilder treeBuilder = new InputTreeBuilder(logger);

            return(treeBuilder.Build(fromConfiguration.Runtime.Commands, fromConfiguration.Runtime.DefaultCommand));
        }