Exemplo n.º 1
0
    public void WriteCSharpCode_SkipsLinePragma_WithoutSource()
    {
        // Arrange
        var codeWriter = new CodeWriter();
        var writer     = new RuntimeNodeWriter();
        var context    = TestCodeRenderingContext.CreateRuntime();

        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);
    }
Exemplo n.º 2
0
    public void WriteCSharpCode_WritesPadding_WithSource()
    {
        // Arrange
        var codeWriter = new CodeWriter();
        var writer     = new RuntimeNodeWriter();
        var context    = TestCodeRenderingContext.CreateRuntime();

        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);
    }
Exemplo n.º 3
0
    public void WriteCSharpCode_WhitespaceContent_DoesNothing()
    {
        // Arrange
        var codeWriter = new CodeWriter();
        var writer     = new RuntimeNodeWriter();
        var context    = TestCodeRenderingContext.CreateRuntime();

        var node = new CSharpCodeIntermediateNode();

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

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

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

        Assert.Empty(csharp);
    }