Example #1
0
    public void WriteCSharpCode_SkipsLinePragma_WithoutSource()
    {
        // Arrange
        var writer  = new DesignTimeNodeWriter();
        var context = TestCodeRenderingContext.CreateDesignTime();

        var node = new CSharpCodeIntermediateNode();

        IntermediateNodeBuilder.Create(node)
        .Add(new IntermediateToken()
        {
            Kind    = TokenKind.CSharp,
            Content = "if (true) { }"
        });

        // Act
        writer.WriteCSharpCode(context, node);

        // Assert
        var csharp = context.CodeWriter.GenerateCode();

        Assert.Equal(
            @"if (true) { }
",
            csharp,
            ignoreLineEndingDifferences: true);
    }
Example #2
0
    public void WriteCSharpCode_WritesPadding_WithSource()
    {
        // Arrange
        var writer  = new DesignTimeNodeWriter();
        var context = TestCodeRenderingContext.CreateDesignTime();

        var node = new CSharpCodeIntermediateNode()
        {
            Source = new SourceSpan("test.cshtml", 0, 0, 0, 17),
        };

        IntermediateNodeBuilder.Create(node)
        .Add(new IntermediateToken()
        {
            Kind    = TokenKind.CSharp,
            Content = "    if (true) { }",
        });

        // Act
        writer.WriteCSharpCode(context, node);

        // Assert
        var csharp = context.CodeWriter.GenerateCode();

        Assert.Equal(
            @"
#nullable restore
#line 1 ""test.cshtml""
    if (true) { }

#line default
#line hidden
#nullable disable
",
            csharp,
            ignoreLineEndingDifferences: true);
    }