Exemple #1
0
        public void CommandLineParser_should_parse()
        {
            //prepare
            var commandLine = new [] {
                "--location", "somewhere",
                "storageAccount", "--containers", "cont1 cont2 cont3", "--resourceGroup", "default",
                "resourceGroup", "--location", "eastus"
            };

            // execute
            var tree = CommandLineLexer.LexCommandLine(commandLine);

            // assess
            Assert.Equal("somewhere", tree.Location);
            Assert.Equal(2, tree.Resources.Count());
            Assert.Single(tree.Resources,
                          resource => resource.ResourceType == "storageAccount" &&
                          resource.StringProperties["resourceGroup"] == "default" &&
                          resource.ListProperties["containers"].Count() == 3 &&
                          resource.ListProperties["containers"].Contains("cont2"));

            Assert.Single(tree.Resources,
                          resource => resource.ResourceType == "resourceGroup" &&
                          resource.StringProperties["location"] == "eastus");
        }
        public void Setup()
        {
            var syntaxFactory = new SyntaxFactory();
            var lexer         = new CommandLineLexer(syntaxFactory);
            var semanticModel = new EmptySemanticModel();

            _parser = new CommandLineParser(lexer, semanticModel, syntaxFactory);
        }
        public void LexEndOfInputToken(string input)
        {
            // Arrange
            var syntaxFactory = new SyntaxFactory();
            var lexer         = new CommandLineLexer(syntaxFactory);

            // Act
            var token = lexer.Lex(input).Last();

            // Assert
            Assert.Equal(SyntaxKind.EndOfInputToken, token.Kind);
        }
        public void LexNegativeNumberToken(string input, string value)
        {
            // Arrange
            var syntaxFactory = new SyntaxFactory();
            var lexer         = new CommandLineLexer(syntaxFactory);

            // Act
            var token = lexer.Lex(input).First();

            // Assert
            Assert.Equal(value, token.StringValue);
            Assert.Equal(SyntaxKind.LiteralToken, token.Kind);
        }
        public void LexSpecialToken(string input, string value, SyntaxKind kind)
        {
            // Arrange
            var syntaxFactory = new SyntaxFactory();
            var lexer         = new CommandLineLexer(syntaxFactory);

            // Act
            var token = lexer.Lex(input).First();

            // Assert
            Assert.Equal(value, token.StringValue);
            Assert.Equal(kind, token.Kind);
        }
        public void LexTokensPair(string input,
                                  string firstValue, SyntaxKind firstKind,
                                  string secondValue, SyntaxKind secondKind)
        {
            // Arrange
            var syntaxFactory = new SyntaxFactory();
            var lexer         = new CommandLineLexer(syntaxFactory);

            // Act
            var tokens = lexer.Lex(input).ToArray();
            var first  = tokens[0];
            var second = tokens[1];

            // Assert
            Assert.Equal(firstValue, first.StringValue);
            Assert.Equal(firstKind, first.Kind);
            Assert.Equal(secondValue, second.StringValue);
            Assert.Equal(secondKind, second.Kind);
        }
        public void LexTokenTrivia(string input, int leading, int trailing)
        {
            // Arrange
            var syntaxFactory = new SyntaxFactory();
            var lexer         = new CommandLineLexer(syntaxFactory);

            // Act
            var token = lexer.Lex(input).First();

            // Assert
            if (leading > 0)
            {
                Assert.True(token.HasLeadingTrivia);
                Assert.Equal(leading, token.LeadingTrivia.Span.Length);
            }
            if (trailing > 0)
            {
                Assert.True(token.HasTrailingTrivia);
                Assert.Equal(trailing, token.TrailingTrivia.Span.Length);
            }
        }