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
21 changes: 21 additions & 0 deletions Fluid.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,27 @@ public Task EmptyShouldNotEqualNumbers(string source, string expected)
return CheckAsync(source, expected, t => t.SetValue("zero", 0).SetValue("one", 1));
}

[Theory]
[InlineData("p == null", "true")]
[InlineData("p != null", "false")]
[InlineData("null == p", "true")]
[InlineData("null == blank", "true")]
[InlineData("blank == null", "true")]
[InlineData("null == ''", "false")]
[InlineData("'' == null", "false")]
[InlineData("empty == null", "false")]
[InlineData("null == empty", "false")]
[InlineData("null == nil", "true")]
[InlineData("nil == null", "true")]
[InlineData("e == null", "false")]
[InlineData("null == e", "false")]
[InlineData("p != null and p != ''", "false")]
[InlineData("p != '' and p != null", "false")]
public Task NullShouldBehaveLikeNil(string source, string expected)
{
return CheckAsync(source, expected, t => t.SetValue("e", "").SetValue("f", "hello"));
}

[Theory]
[InlineData("blank == false", "true")]
[InlineData("empty == false", "false")]
Expand Down
3 changes: 3 additions & 0 deletions Fluid/FluidParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class FluidParser

protected static readonly LiteralExpression EmptyKeyword = new LiteralExpression(EmptyValue.Instance);
protected static readonly LiteralExpression BlankKeyword = new LiteralExpression(BlankValue.Instance);
protected static readonly LiteralExpression NilKeyword = new LiteralExpression(NilValue.Instance);
protected static readonly LiteralExpression TrueKeyword = new LiteralExpression(BooleanValue.True);
protected static readonly LiteralExpression FalseKeyword = new LiteralExpression(BooleanValue.False);

Expand Down Expand Up @@ -163,6 +164,8 @@ public FluidParser(FluidParserOptions parserOptions)
{
case "empty": return EmptyKeyword;
case "blank": return BlankKeyword;
case "nil": return NilKeyword; // Both nil and null are supported for convenience
case "null": return NilKeyword;
case "true": return TrueKeyword;
case "false": return FalseKeyword;
}
Expand Down