Skip to content

Commit

Permalink
Merge pull request #35 from oformaniuk/issues/34
Browse files Browse the repository at this point in the history
Fix index increment for Enumerable data
  • Loading branch information
oformaniuk committed Jul 6, 2020
2 parents 44a0e36 + 515b74a commit 8244de5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions source/Handlebars.Test/IteratorTests.cs
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using Xunit;

namespace HandlebarsDotNet.Test
Expand Down Expand Up @@ -276,6 +277,19 @@ public void NullSequence()
var result = template(data);
Assert.Equal("Hello, (no one listed)", result);
}

[Fact]
public void EnumerableIterator()
{
var source = "{{#each people}}{{.}}{{@index}}{{/each}}";
var template = Handlebars.Compile(source);
var data = new
{
people = Enumerable.Range(0, 3).Select(x => x.ToString())
};
var result = template(data);
Assert.Equal("001122", result);
}
}
}

Expand Up @@ -249,6 +249,8 @@ internal static class Iterator
innerContext.RegisterValueProvider(iterator);
template(context, context.TextWriter, innerContext);
}

iterator.Index++;
}

if (iterator.Index == 0 && !enumerated)
Expand Down

0 comments on commit 8244de5

Please sign in to comment.