Skip to content

Commit

Permalink
Question about nested loops
Browse files Browse the repository at this point in the history
  • Loading branch information
spullara committed Apr 18, 2018
1 parent 813e14b commit 1917fe3
Showing 1 changed file with 26 additions and 0 deletions.
Expand Up @@ -9,8 +9,10 @@
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import static org.junit.Assert.assertEquals;

Expand Down Expand Up @@ -58,4 +60,28 @@ public void testArrayOutput() throws IOException {
}).flush();
assertEquals("[\"one\", \"two\", \"three\"]", sw.toString());
}

@Test
public void testNested() throws IOException {
MustacheFactory mf = new DefaultMustacheFactory();
Mustache test = mf.compile(new StringReader("{{#outer}}" +
"least({{#value.inner}} event{{index}}_count{{^last}},{{/last}} {{/value.inner}}){{^last}},{{/last}}\n" +
"{{/outer}}"), "test");
StringWriter sw = new StringWriter();
List<String> innerList = Arrays.asList("event0_count", "event1_count", "event2_count");
List<Object> outerList = new ArrayList<>();
for (int i = 0; i < innerList.size(); i++) {
DecoratedCollection decoratedCollection = new DecoratedCollection(innerList.subList(0, i + 1));
outerList.add(new Object() {
Collection inner = decoratedCollection;
});
}
Object scope = new Object() {
Collection outer = new DecoratedCollection(outerList);
};
test.execute(sw, scope).flush();
assertEquals("least( event0_count ),\n" +
"least( event0_count, event1_count ),\n" +
"least( event0_count, event1_count, event2_count )\n", sw.toString());
}
}

0 comments on commit 1917fe3

Please sign in to comment.