Skip to content

Commit

Permalink
Fixing NilValue comparison
Browse files Browse the repository at this point in the history
Fixes #149
  • Loading branch information
sebastienros committed Sep 25, 2019
1 parent 05979cc commit 1b5a4e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Fluid.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,24 @@ public void ShouldParseCurlyBraceInOutputStatements()
{
Parse("{{ 'on {0}' }}");
}

[Fact]
public void ShouldBeAbleToCompareNilValues()
{
// [1, 2, 3] | map will return [nil, nil, nil] then | uniq will try to call NilValue.GetHashCode()

var model = new
{
Doubles = new List<double> { 1.1, 2.2, 3.3 }
};

var template = "{{Doubles |map |uniq}}";

if (FluidTemplate.TryParse(template, out var result))
{
TemplateContext.GlobalMemberAccessStrategy.Register(model.GetType());
result.Render(new TemplateContext { Model = model });
}
}
}
}
2 changes: 1 addition & 1 deletion Fluid/Values/NilValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override bool Equals(object other)

public override int GetHashCode()
{
return Instance.GetHashCode();
return GetType().GetHashCode(); ;
}
}
}

0 comments on commit 1b5a4e0

Please sign in to comment.