예제 #1
0
        public void ParseModelKeyword_DoesNotAcceptNewlineIfInDesignTimeMode()
        {
            // Arrange + Act
            List <RazorError> errors = new List <RazorError>();
            var document             = "@ModelType foo\r\n";
            var spans = ParseDocument(document, errors, designTimeMode: true);

            // Assert
            var factory       = SpanFactory.CreateVbHtml();
            var expectedSpans = new Span[]
            {
                factory.EmptyHtml(),
                factory.CodeTransition(SyntaxConstants.TransitionString)
                .Accepts(AcceptedCharacters.None),
                factory.MetaCode("ModelType ")
                .Accepts(AcceptedCharacters.None),
                factory.Code("foo")
                .As(new SetModelTypeCodeGenerator("foo", "{0}(Of {1})"))
                .Accepts(AcceptedCharacters.Any),
                factory.Markup("\r\n")
            };

            Assert.Equal(expectedSpans, spans.ToArray());
            Assert.Equal(0, errors.Count);
        }
        public void ImplicitExpressionAcceptsIdentifierTypedAfterDotIfLastChangeWasProvisionalAcceptanceOfDot()
        {
            var factory = SpanFactory.CreateVbHtml();

            // Arrange
            TextChange        dotTyped  = new TextChange(8, 0, new StringTextBuffer("foo @foo bar"), 1, new StringTextBuffer("foo @foo. bar"));
            TextChange        charTyped = new TextChange(9, 0, new StringTextBuffer("foo @foo. bar"), 1, new StringTextBuffer("foo @foo.b bar"));
            TestParserManager manager   = CreateParserManager();

            manager.InitializeWithDocument(dotTyped.OldBuffer);

            // Apply the dot change
            Assert.Equal(PartialParseResult.Provisional | PartialParseResult.Accepted, manager.CheckForStructureChangesAndWait(dotTyped));

            // Act (apply the identifier start char change)
            PartialParseResult result = manager.CheckForStructureChangesAndWait(charTyped);

            // Assert
            Assert.Equal(PartialParseResult.Accepted, result);
            Assert.False(manager.Parser.LastResultProvisional, "LastResultProvisional flag should have been cleared but it was not");
            ParserTestBase.EvaluateParseTree(manager.Parser.CurrentParseTree,
                                             new MarkupBlock(
                                                 factory.Markup("foo "),
                                                 new ExpressionBlock(
                                                     factory.CodeTransition(),
                                                     factory.Code("foo.b")
                                                     .AsImplicitExpression(VBCodeParser.DefaultKeywords)
                                                     .Accepts(AcceptedCharacters.NonWhiteSpace)),
                                                 factory.Markup(" bar")));
        }
예제 #3
0
        public void ParseModelKeyword_ErrorOnMissingModelType()
        {
            // Arrange + Act
            List <RazorError> errors = new List <RazorError>();
            var document             = "@ModelType   ";
            var spans = ParseDocument(document, errors);

            // Assert
            var factory       = SpanFactory.CreateVbHtml();
            var expectedSpans = new Span[]
            {
                factory.EmptyHtml(),
                factory.CodeTransition(SyntaxConstants.TransitionString)
                .Accepts(AcceptedCharacters.None),
                factory.MetaCode("ModelType   ")
                .Accepts(AcceptedCharacters.None),
                factory.EmptyVB()
                .As(new SetModelTypeCodeGenerator(String.Empty, "{0}(Of {1})"))
                .Accepts(AcceptedCharacters.Any)
            };
            var expectedErrors = new[]
            {
                new RazorError("The 'ModelType' keyword must be followed by a type name on the same line.", new SourceLocation(10, 0, 10), 1)
            };

            Assert.Equal(expectedSpans, spans.ToArray());
            Assert.Equal(expectedErrors, errors.ToArray());
        }
        public void ImplicitExpressionAcceptsIdentifierExpansionAtEndOfNonWhitespaceCharacters()
        {
            var factory = SpanFactory.CreateVbHtml();
            StringTextBuffer changed = new StringTextBuffer("@Code" + Environment.NewLine
                                                            + "    @food" + Environment.NewLine
                                                            + "End Code");
            StringTextBuffer old = new StringTextBuffer("@Code" + Environment.NewLine
                                                        + "    @foo" + Environment.NewLine
                                                        + "End Code");

            RunPartialParseTest(new TextChange(15, 0, old, 1, changed),
                                new MarkupBlock(
                                    factory.EmptyHtml(),
                                    new StatementBlock(
                                        factory.CodeTransition(),
                                        factory.MetaCode("Code")
                                        .Accepts(AcceptedCharacters.None),
                                        factory.Code("\r\n    ").AsStatement(),
                                        new ExpressionBlock(
                                            factory.CodeTransition(),
                                            factory.Code("food")
                                            .AsImplicitExpression(VBCodeParser.DefaultKeywords, acceptTrailingDot: true)
                                            .Accepts(AcceptedCharacters.NonWhiteSpace)),
                                        factory.Code("\r\n").AsStatement(),
                                        factory.MetaCode("End Code").Accepts(AcceptedCharacters.None)),
                                    factory.EmptyHtml()));
        }
예제 #5
0
        public void ImplicitExpressionAcceptsDotIfTrailingDotsAreAllowed()
        {
            var factory = SpanFactory.CreateVbHtml();
            StringTextBuffer changed = new StringTextBuffer("@Code @foo. End Code");
            StringTextBuffer old     = new StringTextBuffer("@Code @foo End Code");

            RunPartialParseTest(
                new TextChange(10, 0, old, 1, changed),
                new MarkupBlock(
                    factory.EmptyHtml(),
                    new StatementBlock(
                        factory.CodeTransition(),
                        factory.MetaCode("Code").Accepts(AcceptedCharacters.None),
                        factory.Code(" ").AsStatement(),
                        new ExpressionBlock(
                            factory.CodeTransition(),
                            factory
                            .Code("foo.")
                            .AsImplicitExpression(
                                VBCodeParser.DefaultKeywords,
                                acceptTrailingDot: true
                                )
                            .Accepts(AcceptedCharacters.NonWhiteSpace)
                            ),
                        factory.Code(" ").AsStatement(),
                        factory.MetaCode("End Code").Accepts(AcceptedCharacters.None)
                        ),
                    factory.EmptyHtml()
                    )
                );
        }
        public void ImplicitExpressionAcceptsMultipleInsertionIfItOnlyCausesIdentifierExpansion()
        {
            var factory = SpanFactory.CreateVbHtml();
            StringTextBuffer changed = new StringTextBuffer("foo @barbiz baz");
            StringTextBuffer old     = new StringTextBuffer("foo @bar baz");

            RunPartialParseTest(new TextChange(8, 0, old, 3, changed),
                                new MarkupBlock(
                                    factory.Markup("foo "),
                                    new ExpressionBlock(
                                        factory.CodeTransition(),
                                        factory.Code("barbiz")
                                        .AsImplicitExpression(VBCodeParser.DefaultKeywords)
                                        .Accepts(AcceptedCharacters.NonWhiteSpace)),
                                    factory.Markup(" baz")));
        }
        public void ImplicitExpressionAcceptsDeleteOfIdentifierPartsIfSomeOfIdentifierRemains()
        {
            var factory = SpanFactory.CreateVbHtml();
            StringTextBuffer changed = new StringTextBuffer("foo @Us baz");
            StringTextBuffer old     = new StringTextBuffer("foo @User baz");

            RunPartialParseTest(new TextChange(7, 2, old, 0, changed),
                                new MarkupBlock(
                                    factory.Markup("foo "),
                                    new ExpressionBlock(
                                        factory.CodeTransition(),
                                        factory.Code("Us")
                                        .AsImplicitExpression(VBCodeParser.DefaultKeywords)
                                        .Accepts(AcceptedCharacters.NonWhiteSpace)),
                                    factory.Markup(" baz")));
        }
        public void ImplicitExpressionAcceptsAdditionalIdentifierCharactersIfEndOfSpanIsIdentifier()
        {
            var factory = SpanFactory.CreateVbHtml();
            StringTextBuffer changed = new StringTextBuffer("foo @foob baz");
            StringTextBuffer old     = new StringTextBuffer("foo @foo bar");

            RunPartialParseTest(new TextChange(8, 0, old, 1, changed),
                                new MarkupBlock(
                                    factory.Markup("foo "),
                                    new ExpressionBlock(
                                        factory.CodeTransition(),
                                        factory.Code("foob")
                                        .AsImplicitExpression(VBCodeParser.DefaultKeywords)
                                        .Accepts(AcceptedCharacters.NonWhiteSpace)),
                                    factory.Markup(" bar")));
        }
        public void ImplicitExpressionProvisionallyAcceptsMultipleInsertionIfItCausesIdentifierExpansionAndTrailingDot()
        {
            var factory = SpanFactory.CreateVbHtml();
            StringTextBuffer changed = new StringTextBuffer("foo @User. baz");
            StringTextBuffer old     = new StringTextBuffer("foo @U baz");

            RunPartialParseTest(new TextChange(6, 0, old, 4, changed),
                                new MarkupBlock(
                                    factory.Markup("foo "),
                                    new ExpressionBlock(
                                        factory.CodeTransition(),
                                        factory.Code("User.")
                                        .AsImplicitExpression(VBCodeParser.DefaultKeywords)
                                        .Accepts(AcceptedCharacters.NonWhiteSpace)),
                                    factory.Markup(" baz")),
                                additionalFlags: PartialParseResult.Provisional);
        }
        public void ImplicitExpressionProvisionallyAcceptsDotAfterIdentifierInMarkup()
        {
            var factory = SpanFactory.CreateVbHtml();
            StringTextBuffer changed = new StringTextBuffer("foo @foo. bar");
            StringTextBuffer old     = new StringTextBuffer("foo @foo bar");

            RunPartialParseTest(new TextChange(8, 0, old, 1, changed),
                                new MarkupBlock(
                                    factory.Markup("foo "),
                                    new ExpressionBlock(
                                        factory.CodeTransition(),
                                        factory.Code("foo.")
                                        .AsImplicitExpression(VBCodeParser.DefaultKeywords)
                                        .Accepts(AcceptedCharacters.NonWhiteSpace)),
                                    factory.Markup(" bar")),
                                additionalFlags: PartialParseResult.Provisional);
        }
        public void ImplicitExpressionProvisionallyAcceptsDeleteOfIdentifierPartsIfDotRemains()
        {
            var factory = SpanFactory.CreateVbHtml();
            StringTextBuffer changed = new StringTextBuffer("foo @User. baz");
            StringTextBuffer old     = new StringTextBuffer("foo @User.Name baz");

            RunPartialParseTest(new TextChange(10, 4, old, 0, changed),
                                new MarkupBlock(
                                    factory.Markup("foo "),
                                    new ExpressionBlock(
                                        factory.CodeTransition(),
                                        factory.Code("User.")
                                        .AsImplicitExpression(VBCodeParser.DefaultKeywords)
                                        .Accepts(AcceptedCharacters.NonWhiteSpace)),
                                    factory.Markup(" baz")),
                                additionalFlags: PartialParseResult.Provisional);
        }
예제 #12
0
        public void ParseModelKeyword_HandlesSingleInstance()
        {
            // Arrange + Act
            var document = "@ModelType    Foo";
            var spans    = ParseDocument(document);

            // Assert
            var factory       = SpanFactory.CreateVbHtml();
            var expectedSpans = new Span[]
            {
                factory.EmptyHtml(),
                factory
                .CodeTransition(SyntaxConstants.TransitionString)
                .Accepts(AcceptedCharacters.None),
                factory.MetaCode("ModelType    ").Accepts(AcceptedCharacters.None),
                factory.Code("Foo").As(new SetModelTypeCodeGenerator("Foo", "{0}(Of {1})"))
            };

            Assert.Equal(expectedSpans, spans.ToArray());
        }
예제 #13
0
        public void ParseModelKeyword_ErrorOnInheritsFollowedByModel()
        {
            // Arrange + Act
            List <RazorError> errors = new List <RazorError>();
            var document             = "@Inherits Bar" + Environment.NewLine + "@ModelType Foo";
            var spans = ParseDocument(document, errors);

            // Assert
            var factory       = SpanFactory.CreateVbHtml();
            var expectedSpans = new Span[]
            {
                factory.EmptyHtml(),
                factory
                .CodeTransition(SyntaxConstants.TransitionString)
                .Accepts(AcceptedCharacters.None),
                factory.MetaCode("Inherits ").Accepts(AcceptedCharacters.None),
                factory.Code("Bar\r\n").AsBaseType("Bar"),
                factory
                .CodeTransition(SyntaxConstants.TransitionString)
                .Accepts(AcceptedCharacters.None),
                factory.MetaCode("ModelType ").Accepts(AcceptedCharacters.None),
                factory.Code("Foo").As(new SetModelTypeCodeGenerator("Foo", "{0}(Of {1})"))
            };

            var expectedErrors = new[]
            {
                new RazorError(
                    "The 'inherits' keyword is not allowed when a 'ModelType' keyword is used.",
                    new SourceLocation(9, 0, 9),
                    1
                    )
            };

            expectedSpans
            .Zip(spans, (exp, span) => new { expected = exp, span = span })
            .ToList()
            .ForEach(i => Assert.Equal(i.expected, i.span));
            Assert.Equal(expectedSpans, spans.ToArray());
            Assert.Equal(expectedErrors, errors.ToArray());
        }
예제 #14
0
        public void ParseModelKeyword_ErrorOnMultipleModelStatements()
        {
            // Arrange + Act
            List <RazorError> errors = new List <RazorError>();
            var document             = "@ModelType Foo" + Environment.NewLine + "@ModelType Bar";
            var spans = ParseDocument(document, errors);

            // Assert
            var factory       = SpanFactory.CreateVbHtml();
            var expectedSpans = new Span[]
            {
                factory.EmptyHtml(),
                factory
                .CodeTransition(SyntaxConstants.TransitionString)
                .Accepts(AcceptedCharacters.None),
                factory.MetaCode("ModelType ").Accepts(AcceptedCharacters.None),
                factory.Code("Foo\r\n").As(new SetModelTypeCodeGenerator("Foo", "{0}(Of {1})")),
                factory
                .CodeTransition(SyntaxConstants.TransitionString)
                .Accepts(AcceptedCharacters.None),
                factory.MetaCode("ModelType ").Accepts(AcceptedCharacters.None),
                factory.Code("Bar").As(new SetModelTypeCodeGenerator("Bar", "{0}(Of {1})"))
            };

            var expectedErrors = new[]
            {
                new RazorError(
                    "Only one 'ModelType' statement is allowed in a file.",
                    new SourceLocation(26, 1, 10),
                    1
                    )
            };

            expectedSpans
            .Zip(spans, (exp, span) => new { expected = exp, span = span })
            .ToList()
            .ForEach(i => Assert.Equal(i.expected, i.span));
            Assert.Equal(expectedSpans, spans.ToArray());
            Assert.Equal(expectedErrors, errors.ToArray());
        }