Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions Fluid.Tests/Extensibility/ExtensibilityTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Fluid.Ast;
using Parlot.Fluent;
using System;
using Xunit;

namespace Fluid.Tests.Extensibility
Expand All @@ -24,6 +25,21 @@ public void ShouldRenderEmptyTags()
Assert.Equal("Hello World", result);
}

[Fact]
public void ShouldReportAndErrorOnEmptyTags()
{
var parser = new CustomParser();

parser.RegisterEmptyTag("hello", (w, e, c) =>
{
w.Write("Hello World");

return Statement.Normal();
});

Assert.Throws<ParseException>(() => parser.Parse("{% hello foo %}"));
}

[Fact]
public void ShouldRenderIdentifierTags()
{
Expand Down
4 changes: 2 additions & 2 deletions Fluid/FluidParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public void RegisterParserBlock<T>(string tagName, Parser<T> parser, Func<T, IRe
{
RegisteredTags[tagName] = parser.AndSkip(TagEnd).And(AnyTagsList).AndSkip(CreateTag("end" + tagName).ElseError($"'{{% end{tagName} %}}' was expected"))
.Then<Statement>(x => new ParserBlockStatement<T>(x.Item1, x.Item2, render))
.ElseError($"Invalid 'tagName' tag")
.ElseError($"Invalid {tagName} tag")
;
}

Expand All @@ -513,7 +513,7 @@ public void RegisterParserTag<T>(string tagName, Parser<T> parser, Func<T, TextW

public void RegisterEmptyTag(string tagName, Func<TextWriter, TextEncoder, TemplateContext, ValueTask<Completion>> render)
{
RegisteredTags[tagName] = TagEnd.Then<Statement>(x => new EmptyTagStatement(render));
RegisteredTags[tagName] = TagEnd.Then<Statement>(x => new EmptyTagStatement(render)).ElseError($"Unexpected arguments in {tagName} tag");
}

public void RegisterEmptyBlock(string tagName, Func<IReadOnlyList<Statement>, TextWriter, TextEncoder, TemplateContext, ValueTask<Completion>> render)
Expand Down