Exemplo n.º 1
0
        public void SectionDirectiveAutoCompleteAtStartOfFile()
        {
            // Arrange
            var chunkGenerator = new DirectiveChunkGenerator(SectionDirective.Directive);

            chunkGenerator.Diagnostics.Add(
                RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
                    new SourceSpan(new SourceLocation(16, 0, 16), contentLength: 1), "section", "}", "{"));

            // Act & Assert
            ParseBlockTest(
                "@section Header {" + Environment.NewLine + "<p>Foo</p>",
                new[] { SectionDirective.Directive },
                new DirectiveBlock(chunkGenerator,
                                   Factory.CodeTransition(),
                                   Factory.MetaCode("section").Accepts(AcceptedCharactersInternal.None),
                                   Factory.Span(SpanKindInternal.Code, " ", CSharpSymbolType.WhiteSpace).Accepts(AcceptedCharactersInternal.WhiteSpace),
                                   Factory.Span(SpanKindInternal.Code, "Header", CSharpSymbolType.Identifier).AsDirectiveToken(SectionDirective.Directive.Tokens.First()),
                                   Factory.Span(SpanKindInternal.Markup, " ", CSharpSymbolType.WhiteSpace).Accepts(AcceptedCharactersInternal.AllWhiteSpace),
                                   Factory.MetaCode("{").AutoCompleteWith("}", atEndOfSpan: true).Accepts(AcceptedCharactersInternal.None),
                                   new MarkupBlock(
                                       Factory.Markup(Environment.NewLine),
                                       new MarkupTagBlock(
                                           Factory.Markup("<p>")),
                                       Factory.Markup("Foo"),
                                       new MarkupTagBlock(
                                           Factory.Markup("</p>")))));
        }
Exemplo n.º 2
0
        public void SectionDirectiveAutoCompleteAtEOF()
        {
            // Arrange
            var chunkGenerator = new DirectiveChunkGenerator(SectionDirective.Directive);

            chunkGenerator.Diagnostics.Add(
                RazorDiagnostic.Create(
                    new RazorError(
                        LegacyResources.FormatParseError_Expected_EndOfBlock_Before_EOF("section", "}", "{"),
                        new SourceLocation(16, 0, 16),
                        length: 1)));

            // Act & Assert
            ParseBlockTest(
                "@section Header {",
                new[] { SectionDirective.Directive },
                new DirectiveBlock(chunkGenerator,
                                   Factory.CodeTransition(),
                                   Factory.MetaCode("section").Accepts(AcceptedCharactersInternal.None),
                                   Factory.Span(SpanKindInternal.Code, " ", CSharpSymbolType.WhiteSpace).Accepts(AcceptedCharactersInternal.WhiteSpace),
                                   Factory.Span(SpanKindInternal.Code, "Header", CSharpSymbolType.Identifier)
                                   .AsDirectiveToken(SectionDirective.Directive.Tokens.First()),
                                   Factory.Span(SpanKindInternal.Markup, " ", CSharpSymbolType.WhiteSpace).Accepts(AcceptedCharactersInternal.AllWhiteSpace),
                                   Factory.MetaCode("{").AutoCompleteWith("}", atEndOfSpan: true).Accepts(AcceptedCharactersInternal.None),
                                   new MarkupBlock(
                                       Factory.EmptyHtml())));
        }
Exemplo n.º 3
0
        public void InheritsBlockOutputsErrorIfInheritsNotFollowedByTypeButAcceptsEntireLineAsCode()
        {
            // Arrange
            var chunkGenerator = new DirectiveChunkGenerator(InheritsDirective.Directive);

            chunkGenerator.Diagnostics.Add(
                RazorDiagnostic.Create(
                    new RazorError(
                        LegacyResources.FormatDirectiveExpectsTypeName(InheritsDirective.Directive.Directive),
                        25, 0, 25, Environment.NewLine.Length)));

            // Act & Assert
            ParseDocumentTest(
                "@inherits                " + Environment.NewLine + "foo",
                new[] { InheritsDirective.Directive },
                new MarkupBlock(
                    Factory.EmptyHtml(),
                    new DirectiveBlock(chunkGenerator,
                                       Factory.CodeTransition(),
                                       Factory.MetaCode("inherits").Accepts(AcceptedCharactersInternal.None),
                                       Factory.Span(SpanKindInternal.Code, "                ", CSharpSymbolType.WhiteSpace).Accepts(AcceptedCharactersInternal.WhiteSpace),
                                       Factory.Span(SpanKindInternal.Code, string.Empty, CSharpSymbolType.Unknown)
                                       .AsDirectiveToken(DirectiveTokenDescriptor.CreateToken(DirectiveTokenKind.Type))),
                    Factory.Markup(Environment.NewLine + "foo")));
        }
Exemplo n.º 4
0
        public void ParseSectionBlockReportsErrorAndAcceptsWhitespaceToEndOfLineIfSectionNotFollowedByOpenBrace()
        {
            // Arrange
            var chunkGenerator = new DirectiveChunkGenerator(SectionDirective.Directive);

            chunkGenerator.Diagnostics.Add(
                RazorDiagnosticFactory.CreateParsing_UnexpectedEOFAfterDirective(
                    new SourceSpan(new SourceLocation(18 + Environment.NewLine.Length, 1, 0), contentLength: 1),
                    SectionDirective.Directive.Directive,
                    "{"));

            // Act & Assert
            ParseDocumentTest(
                "@section foo      " + Environment.NewLine,
                new[] { SectionDirective.Directive });
        }
Exemplo n.º 5
0
        public void FunctionsDirectiveAutoCompleteAtEOF()
        {
            // Arrange
            var chunkGenerator = new DirectiveChunkGenerator(FunctionsDirective.Directive);

            chunkGenerator.Diagnostics.Add(
                RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
                    new SourceSpan(new SourceLocation(10, 0, 10), contentLength: 1), FunctionsDirective.Directive.Directive, "}", "{"));

            // Act & Assert
            ParseBlockTest(
                "@functions{",
                new[] { FunctionsDirective.Directive },
                new DirectiveBlock(chunkGenerator,
                                   Factory.CodeTransition(),
                                   Factory.MetaCode("functions").Accepts(AcceptedCharactersInternal.None),
                                   Factory.MetaCode("{").AutoCompleteWith("}", atEndOfSpan: true).Accepts(AcceptedCharactersInternal.None)));
        }
Exemplo n.º 6
0
        public void ParseBlockDoesNoErrorRecoveryForFunctionsBlock()
        {
            // Arrange
            var chunkGenerator = new DirectiveChunkGenerator(FunctionsDirective.Directive);

            chunkGenerator.Diagnostics.Add(
                RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
                    new SourceSpan(new SourceLocation(10, 0, 10), contentLength: 1), "functions", "}", "{"));

            // Act & Assert
            ParseBlockTest(
                "functions { { { { { } zoop",
                new[] { FunctionsDirective.Directive },
                new DirectiveBlock(chunkGenerator,
                                   Factory.MetaCode("functions").Accepts(AcceptedCharactersInternal.None),
                                   Factory.Span(SpanKindInternal.Markup, " ", CSharpSymbolType.WhiteSpace).Accepts(AcceptedCharactersInternal.AllWhiteSpace),
                                   Factory.MetaCode("{").AutoCompleteWith("}", atEndOfSpan: true).Accepts(AcceptedCharactersInternal.None),
                                   Factory.Code(" { { { { } zoop").AsStatement()));
        }
Exemplo n.º 7
0
        public void FunctionsDirectiveAutoCompleteAtEOF()
        {
            // Arrange
            var chunkGenerator = new DirectiveChunkGenerator(FunctionsDirective.Directive);

            chunkGenerator.Diagnostics.Add(
                RazorDiagnostic.Create(
                    new RazorError(
                        LegacyResources.FormatParseError_Expected_EndOfBlock_Before_EOF(FunctionsDirective.Directive.Directive, "}", "{"),
                        new SourceLocation(10, 0, 10),
                        length: 1)));

            // Act & Assert
            ParseBlockTest(
                "@functions{",
                new[] { FunctionsDirective.Directive },
                new DirectiveBlock(chunkGenerator,
                                   Factory.CodeTransition(),
                                   Factory.MetaCode("functions").Accepts(AcceptedCharactersInternal.None),
                                   Factory.MetaCode("{").AutoCompleteWith("}", atEndOfSpan: true).Accepts(AcceptedCharactersInternal.None)));
        }
Exemplo n.º 8
0
        public void ParseInheritsStatementMarksInheritsSpanAsCanGrowIfMissingTrailingSpace()
        {
            // Arrange
            var chunkGenerator = new DirectiveChunkGenerator(InheritsDirective.Directive);

            chunkGenerator.Diagnostics.Add(
                RazorDiagnosticFactory.CreateParsing_UnexpectedEOFAfterDirective(
                    new SourceSpan(new SourceLocation(9, 0, 9), 1), InheritsDirective.Directive.Directive, "type"));

            // Act & Assert
            ParseDocumentTest(
                "@inherits",
                new[] { InheritsDirective.Directive },
                new MarkupBlock(
                    Factory.EmptyHtml(),
                    new DirectiveBlock(chunkGenerator,
                                       Factory.CodeTransition(),
                                       Factory.MetaCode("inherits").Accepts(AcceptedCharactersInternal.None),
                                       Factory.Span(SpanKindInternal.Code, string.Empty, CSharpSymbolType.Unknown)
                                       .AsDirectiveToken(DirectiveTokenDescriptor.CreateToken(DirectiveTokenKind.Type))),
                    Factory.EmptyHtml()));
        }
Exemplo n.º 9
0
        public void ParseBlockReportsErrorIfClassBlockUnterminatedAtEOF()
        {
            // Arrange
            var chunkGenerator = new DirectiveChunkGenerator(FunctionsDirective.Directive);

            chunkGenerator.Diagnostics.Add(
                RazorDiagnostic.Create(
                    new RazorError(
                        LegacyResources.FormatParseError_Expected_EndOfBlock_Before_EOF("functions", '}', '{'),
                        new SourceLocation(10, 0, 10),
                        length: 1)));

            // Act & Assert
            ParseBlockTest(
                "functions { var foo = bar; if(foo != null) { bar(); } ",
                new[] { FunctionsDirective.Directive },
                new DirectiveBlock(chunkGenerator,
                                   Factory.MetaCode("functions").Accepts(AcceptedCharactersInternal.None),
                                   Factory.Span(SpanKindInternal.Markup, " ", CSharpSymbolType.WhiteSpace).Accepts(AcceptedCharactersInternal.AllWhiteSpace),
                                   Factory.MetaCode("{").AutoCompleteWith("}", atEndOfSpan: true).Accepts(AcceptedCharactersInternal.None),
                                   Factory.Code(" var foo = bar; if(foo != null) { bar(); } ").AsStatement()));
        }
Exemplo n.º 10
0
        public void ParseInheritsStatementMarksInheritsSpanAsCanGrowIfMissingTrailingSpace()
        {
            // Arrange
            var chunkGenerator = new DirectiveChunkGenerator(InheritsDirective.Directive);

            chunkGenerator.Diagnostics.Add(
                RazorDiagnostic.Create(
                    new RazorError(
                        LegacyResources.FormatUnexpectedEOFAfterDirective(InheritsDirective.Directive.Directive, "type"),
                        new SourceLocation(9, 0, 9), 1)));

            // Act & Assert
            ParseDocumentTest(
                "@inherits",
                new[] { InheritsDirective.Directive },
                new MarkupBlock(
                    Factory.EmptyHtml(),
                    new DirectiveBlock(chunkGenerator,
                                       Factory.CodeTransition(),
                                       Factory.MetaCode("inherits").Accepts(AcceptedCharactersInternal.None)),
                    Factory.EmptyHtml()));
        }
 public override void VisitDirectiveBlock(DirectiveChunkGenerator chunkGenerator, Block block)
 {
     WriteBlock(block);
 }