public void nestedLoopTest() throws IOException {
//outer field contains less elements than inner field
StringReader reader = new StringReader("${loop}${loop}${outer}${inner}${/loop}${/loop}");
StringWriter writer = new StringWriter();
new DefaultParser(reader, writer).perform(
createOuterInnerDataFieldResolver(new int[]{0, 1}, new int[]{0, 1, 2}));
Assert.assertEquals("000102101112", writer.toString());
//outer field contains more elements than inner field
reader = new StringReader("${loop}${loop}${outer}${inner}${/loop}${/loop}");
writer = new StringWriter();
new DefaultParser(reader, writer).perform(
createOuterInnerDataFieldResolver(new int[]{0, 1, 2}, new int[]{0, 1}));
Assert.assertEquals("000110112021", writer.toString());
//inner and outer field have same length
reader = new StringReader("${loop}${loop}${outer}${inner}${/loop}${/loop}");
writer = new StringWriter();
new DefaultParser(reader, writer).perform(
createOuterInnerDataFieldResolver(new int[]{0, 1}, new int[]{2, 3}));
Assert.assertEquals("02031213", writer.toString());
//outer field is empty
reader = new StringReader("${loop}${loop}${outer}${inner}${/loop}${/loop}");
writer = new StringWriter();
new DefaultParser(reader, writer).perform(
createOuterInnerDataFieldResolver(new int[]{}, new int[]{0, 1}));
Assert.assertEquals("", writer.toString());
//inner field is empty
reader = new StringReader("${loop}${outer}${loop}${inner}${/loop}${/loop}");
writer = new StringWriter();
new DefaultParser(reader, writer).perform(
createOuterInnerDataFieldResolver(new int[]{0,1}, new int[]{}));
Assert.assertEquals("01", writer.toString());
//inner field is empty, and no access to outer
reader = new StringReader("${loop}*${loop}${inner}${/loop}${/loop}");
writer = new StringWriter();
new DefaultParser(reader, writer).perform(
createOuterInnerDataFieldResolver(new int[]{0,1}, new int[]{}));
Assert.assertEquals("**", writer.toString());
//both fields are empty
reader = new StringReader("${loop}${loop}${outer}${inner}${/loop}${/loop}");
writer = new StringWriter();
new DefaultParser(reader, writer).perform(
createOuterInnerDataFieldResolver(new int[]{}, new int[]{}));
Assert.assertEquals("", writer.toString());
}