public void WriteDesignTimeDirective_WithTypeToken_WritesLambda() { // Arrange var extension = new DesignTimeDirectiveTargetExtension(); var context = TestCodeRenderingContext.CreateDesignTime(); var node = new DesignTimeDirectiveIntermediateNode(); var token = new DirectiveTokenIntermediateNode() { Source = new SourceSpan("test.cshtml", 0, 0, 0, 5), Content = "System.String", DirectiveToken = DirectiveTokenDescriptor.CreateToken(DirectiveTokenKind.Type), }; node.Children.Add(token); // Act extension.WriteDesignTimeDirective(context, node); // Assert var csharp = context.CodeWriter.GenerateCode(); Assert.Equal( @"#pragma warning disable 219 private void __RazorDirectiveTokenHelpers__() { ((System.Action)(() => { #nullable restore #line 1 ""test.cshtml"" System.String __typeHelper = default!; #line default #line hidden #nullable disable } ))(); } #pragma warning restore 219 ", csharp, ignoreLineEndingDifferences: true); }
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())); }
public void InheritsBlockOutputsErrorIfInheritsNotFollowedByTypeButAcceptsEntireLineAsCode() { // Arrange var chunkGenerator = new DirectiveChunkGenerator(InheritsDirective.Directive); chunkGenerator.Diagnostics.Add( RazorDiagnosticFactory.CreateParsing_DirectiveExpectsTypeName( new SourceSpan(new SourceLocation(25, 0, 25), Environment.NewLine.Length), InheritsDirective.Directive.Directive)); // 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"))); }