Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions source/Handlebars.Test/Issues/Issue458Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Xunit;

namespace HandlebarsDotNet.Test
{
public class Issue458Tests
{
[Fact]
public void Issue458_BasicCompileAndRender_NoByRefDelegate()
{
// Validates the scenario that fails on Mono when byref delegates are used
var h = Handlebars.Create();
var render = h.Compile("{{input}}");
var result = render(new { input = 42 });
Assert.Equal("42", result);
}

[Fact]
public void Issue458_BlockHelper_NoByRefDelegate()
{
// Block helpers also exercise TemplateDelegate compilation
var h = Handlebars.Create();
h.RegisterHelper("loud", (writer, options, context, arguments) =>
{
options.Template(writer, context);
});
var render = h.Compile("{{#loud}}hello{{/loud}}");
var result = render(new { });
Assert.Equal("hello", result);
}

[Fact]
public void Issue458_NestedTemplates_NoByRefDelegate()
{
// Nested template compilation exercises the expression tree lambda paths
var h = Handlebars.Create();
var render = h.Compile("{{#each items}}{{this}},{{/each}}");
var result = render(new { items = new[] { "a", "b", "c" } });

Check warning on line 37 in source/Handlebars.Test/Issues/Issue458Tests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly and is not mutating the passed array

See more on https://sonarcloud.io/project/issues?id=Handlebars-Net_Handlebars.Net&issues=AZ7lE7kqtbSxmKwNOFZa&open=AZ7lE7kqtbSxmKwNOFZa&pullRequest=632
Assert.Equal("a,b,c,", result);
}
}
}
Loading