tokens) {
- this(insertion.name, insertion, tokens.toArray(new LNode[tokens.size()]));
+ this(insertion.name, insertion, tokens.toArray(new LNode[0]));
}
public InsertionNode(Insertion insertion, LNode... tokens) {
diff --git a/src/main/java/liqp/tags/IncludeRelative.java b/src/main/java/liqp/tags/IncludeRelative.java
index e025ee5e..9eb603e5 100644
--- a/src/main/java/liqp/tags/IncludeRelative.java
+++ b/src/main/java/liqp/tags/IncludeRelative.java
@@ -2,13 +2,10 @@
import liqp.TemplateContext;
import liqp.antlr.CharStreamWithLocation;
-import liqp.nodes.LNode;
import java.io.IOException;
import java.nio.file.Path;
-import java.util.Map;
-
-import static liqp.TemplateParser.pwd;
+import java.nio.file.Paths;
/**
*
@@ -44,7 +41,7 @@ public IncludeRelative() {
protected CharStreamWithLocation detectSource(TemplateContext context, String includeResource) throws IOException {
Path rootPath = context.getRootFolder();
if (rootPath == null) {
- rootPath = pwd();
+ rootPath = Paths.get(".").toAbsolutePath();
}
Path includePath = rootPath.resolve(includeResource);
return new CharStreamWithLocation(includePath);
diff --git a/src/test/java/liqp/InsertionTest.java b/src/test/java/liqp/InsertionTest.java
index 4fa66ae6..9bd4dc91 100644
--- a/src/test/java/liqp/InsertionTest.java
+++ b/src/test/java/liqp/InsertionTest.java
@@ -16,7 +16,7 @@ public class InsertionTest {
public void testNestedCustomTagsAndBlocks() {
TemplateParser templateParser = new TemplateParser.Builder()
- .withInsertion(new Block("block") {
+ .withBlock(new Block("block") {
@Override
public Object render(TemplateContext context, LNode... nodes) {
String data = (nodes.length >= 2 ? nodes[1].render(context) : nodes[0].render(
@@ -25,7 +25,7 @@ public Object render(TemplateContext context, LNode... nodes) {
return "blk[" + data + "]";
}
})
- .withInsertion(new Tag("simple") {
+ .withTag(new Tag("simple") {
@Override
public Object render(TemplateContext context, LNode... nodes) {
return "(sim)";
@@ -41,7 +41,7 @@ public Object render(TemplateContext context, LNode... nodes) {
public void testNestedCustomTagsAndBlocksAsOneCollection() {
String templateString = "{% block %}a{% simple %}b{% block %}c{% endblock %}d{% endblock %}";
- TemplateParser parser = new TemplateParser.Builder().withInsertion(
+ TemplateParser parser = new TemplateParser.Builder().withBlock(
new Block("block") {
@Override
public Object render(TemplateContext context, LNode... nodes) {
@@ -50,7 +50,7 @@ public Object render(TemplateContext context, LNode... nodes) {
return "blk[" + data + "]";
}
- }).withInsertion(new Tag("simple") {
+ }).withTag(new Tag("simple") {
@Override
public Object render(TemplateContext context, LNode... nodes) {
return "(sim)";
@@ -64,7 +64,7 @@ public Object render(TemplateContext context, LNode... nodes) {
@Test
public void testCustomTag() throws RecognitionException {
- TemplateParser parser = new TemplateParser.Builder().withInsertion(new Tag("twice") {
+ TemplateParser parser = new TemplateParser.Builder().withTag(new Tag("twice") {
@Override
public Object render(TemplateContext context, LNode... nodes) {
Double number = super.asNumber(nodes[0].render(context)).doubleValue();
@@ -80,7 +80,7 @@ public Object render(TemplateContext context, LNode... nodes) {
@Test
public void testCustomTagBlock() throws RecognitionException {
- TemplateParser templateParser = new TemplateParser.Builder().withInsertion(new Block("twice") {
+ TemplateParser templateParser = new TemplateParser.Builder().withBlock(new Block("twice") {
@Override
public Object render(TemplateContext context, LNode... nodes) {
LNode blockNode = nodes[nodes.length - 1];
@@ -186,7 +186,7 @@ public void no_transformTest() throws RecognitionException {
@Test
public void testCustomTagRegistration() {
TemplateParser parser = new TemplateParser.Builder()
- .withInsertion(new Tag("custom_tag") {
+ .withTag(new Tag("custom_tag") {
@Override
public Object render(TemplateContext context, LNode... nodes) {
return "xxx";
diff --git a/src/test/java/liqp/ReadmeSamplesTest.java b/src/test/java/liqp/ReadmeSamplesTest.java
index 8f1caa41..16e48947 100644
--- a/src/test/java/liqp/ReadmeSamplesTest.java
+++ b/src/test/java/liqp/ReadmeSamplesTest.java
@@ -1,23 +1,73 @@
package liqp;
+import liqp.blocks.Block;
+import liqp.filters.Filter;
+import liqp.nodes.LNode;
import liqp.parser.Inspectable;
import liqp.parser.LiquidSupport;
+import org.antlr.v4.runtime.tree.ParseTree;
import org.junit.Test;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
public class ReadmeSamplesTest {
+
+
@Test
+ public void testRenderTree() {
+ String input =
+ "
\n" +
+ " {% for product in products %} \n" +
+ " - \n" +
+ "
{{ product.name }}
\n" +
+ " Only {{ product.price | price }} \n" +
+ " \n" +
+ " {{ product.description | prettyprint | paragraph }} \n" +
+ " \n" +
+ " {% endfor %} \n" +
+ "
\n";
+ Template template = TemplateParser.DEFAULT.parse(input);
+
+ ParseTree root = template.getParseTree();
+ }
+
+ @Test
+ public void testReadMeIntro() {
+ TemplateParser parser = new TemplateParser.Builder().build();
+ Template template = parser.parse("hi {{name}}");
+ String rendered = template.render("name", "tobi");
+ System.out.println(rendered);
+ }
+
+ @Test
+ public void testReadMeMap() {
+ Template template = new TemplateParser.Builder().build().parse("hi {{name}}");
+ Map map = new HashMap<>();
+ map.put("name", "tobi");
+ String rendered = template.render(map);
+ System.out.println(rendered);
+ }
+
+ @Test
+ public void testReadMeJson() {
+ Template template = new TemplateParser.Builder().build().parse("hi {{name}}");
+ String rendered = template.render("{\"name\" : \"tobi\"}");
+ System.out.println(rendered);
+ }
+
+ @Test
+ @SuppressWarnings({"unused", "FieldMayBeFinal"})
public void testInspectable() {
class MyParams implements Inspectable {
- @SuppressWarnings("unused")
public String name = "tobi";
};
Template template = TemplateParser.DEFAULT.parse("hi {{name}}");
String rendered = template.render(new MyParams());
+ System.out.println(rendered);
assertEquals("hi tobi", rendered);
}
@@ -31,6 +81,7 @@ public Map toLiquid() {
};
Template template = TemplateParser.DEFAULT.parse("hi {{name}}");
String rendered = template.render(new MyLazy());
+ System.out.println(rendered);
assertEquals("hi tobi", rendered);
}
@@ -48,5 +99,113 @@ public void testEagerMode() {
assertEquals("hi tobi", res);
// System.out.println(res);
}
+
+ @Test
+ public void testFilterRegistration() {
+ // first create template parser with new filter
+ TemplateParser parser = new TemplateParser.Builder().withFilter(new Filter("b") {
+ @Override
+ public Object apply(TemplateContext context, Object value, Object... params) {
+ // create a string from the value
+ String text = super.asString(value, context);
+
+ // replace and return *...* with ...
+ return text.replaceAll("\\*(\\w(.*?\\w)?)\\*", "$1");
+ }
+ }).build();
+
+
+ // use your filter
+ Template template = parser.parse("{{ wiki | b }}");
+ String rendered = template.render("{\"wiki\" : \"Some *bold* text *in here*.\"}");
+ System.out.println(rendered);
+ /*
+ Some bold text in here.
+ */
+ }
+
+ @Test
+ public void testFilerWithOptionalParams() {
+ TemplateParser parser = new TemplateParser.Builder().withFilter(new Filter("repeat"){
+ @Override
+ public Object apply(TemplateContext context, Object value, Object... params) {
+ // get the text of the value
+ String text = super.asString(value, context);
+
+ // check if an optional parameter is provided
+ int times = params.length == 0 ? 1 : super.asNumber(params[0]).intValue();
+
+ StringBuilder builder = new StringBuilder();
+
+ while(times-- > 0) {
+ builder.append(text);
+ }
+
+ return builder.toString();
+ }
+ }).build();
+
+ // use your filter
+ Template template = parser.parse("{{ 'a' | repeat }}\n{{ 'b' | repeat:5 }}");
+ String rendered = template.render();
+ System.out.println(rendered);
+ /*
+ a
+ bbbbb
+ */
+ }
+
+ @Test
+ public void testFilterCanBeAnything() {
+ TemplateParser parser = new TemplateParser.Builder().withFilter(new Filter("sum"){
+ @Override
+ public Object apply(TemplateContext context, Object value, Object... params) {
+
+ Object[] numbers = super.asArray(value, context);
+
+ double sum = 0;
+
+ for(Object obj : numbers) {
+ sum += super.asNumber(obj).doubleValue();
+ }
+
+ return sum;
+ }
+ }).build();
+
+ Template template = parser.parse("{{ numbers | sum }}");
+ String rendered = template.render("{\"numbers\" : [1, 2, 3, 4, 5]}");
+ System.out.println(rendered);
+ /*
+ 15.0
+ */
+ }
+
+ @Test
+ public void testBlockSample() {
+ TemplateParser parser = new TemplateParser.Builder().withBlock(new Block("loop"){
+ @Override
+ public Object render(TemplateContext context, LNode... nodes) {
+ int n = super.asNumber(nodes[0].render(context)).intValue();
+ LNode block = nodes[1];
+ StringBuilder builder = new StringBuilder();
+ while(n-- > 0) {
+ builder.append(super.asString(block.render(context), context));
+ }
+ return builder.toString();
+ }
+ }).build();
+
+ Template template = parser.parse("{% loop 5 %}looping!\n{% endloop %}");
+ String rendered = template.render();
+ System.out.println(rendered);
+ /*
+ looping!
+ looping!
+ looping!
+ looping!
+ looping!
+ */
+ }
}
diff --git a/src/test/java/liqp/RenderSettingsTest.java b/src/test/java/liqp/RenderSettingsTest.java
index 179cc953..b9934ab8 100644
--- a/src/test/java/liqp/RenderSettingsTest.java
+++ b/src/test/java/liqp/RenderSettingsTest.java
@@ -153,7 +153,7 @@ public void testEnvironmentMapConfigurator() throws Exception {
TemplateParser parser = new TemplateParser.Builder().withFilter(new Filter("secret") {
@Override
- public Object apply(Object value, TemplateContext context, Object... params) {
+ public Object apply(TemplateContext context, Object value, Object... params) {
ObjectAppender.Controller sb = context.newObjectAppender(3);
sb.append(value);
sb.append(" ");
diff --git a/src/test/java/liqp/TemplateTest.java b/src/test/java/liqp/TemplateTest.java
index e8169331..2e3b8949 100644
--- a/src/test/java/liqp/TemplateTest.java
+++ b/src/test/java/liqp/TemplateTest.java
@@ -267,7 +267,7 @@ public void testCustomTagMissingErrorReporting() {
@Test
public void testWithCustomTag() {
// given
- TemplateParser parser = new TemplateParser.Builder().withInsertion(new Tag("custom_tag") {
+ TemplateParser parser = new TemplateParser.Builder().withTag(new Tag("custom_tag") {
@Override
public Object render(TemplateContext context, LNode... nodes) {
return "xxx";
@@ -283,7 +283,7 @@ public Object render(TemplateContext context, LNode... nodes) {
@Test
public void testWithCustomBlock() {
// given
- TemplateParser parser = new TemplateParser.Builder().withInsertion(new Block("custom_uppercase_block") {
+ TemplateParser parser = new TemplateParser.Builder().withBlock(new Block("custom_uppercase_block") {
@Override
public Object render(TemplateContext context, LNode... nodes) {
LNode block = nodes[0];
@@ -307,7 +307,7 @@ public void testWithCustomFilter() {
// given
TemplateParser parser = new TemplateParser.Builder().withFilter(new Filter("sum"){
@Override
- public Object apply(Object value, TemplateContext context, Object... params) {
+ public Object apply(TemplateContext context, Object value, Object... params) {
Object[] numbers = super.asArray(value, context);
double sum = 0;
for(Object obj : numbers) {
diff --git a/src/test/java/liqp/filters/CapitalizeTest.java b/src/test/java/liqp/filters/CapitalizeTest.java
index 156a23ce..67581f69 100644
--- a/src/test/java/liqp/filters/CapitalizeTest.java
+++ b/src/test/java/liqp/filters/CapitalizeTest.java
@@ -39,7 +39,7 @@ public void applyOriginalTest() {
Filter filter = Filters.COMMON_FILTERS.get("capitalize");
TemplateContext context = new TemplateContext();
- assertThat(filter.apply("testing", context), is((Object)"Testing"));
- assertThat(filter.apply(null, context), is((Object)""));
+ assertThat(filter.apply(context, "testing"), is((Object)"Testing"));
+ assertThat(filter.apply(context, null), is((Object)""));
}
}
diff --git a/src/test/java/liqp/filters/DateTest.java b/src/test/java/liqp/filters/DateTest.java
index bb9db6c6..b92c8caa 100644
--- a/src/test/java/liqp/filters/DateTest.java
+++ b/src/test/java/liqp/filters/DateTest.java
@@ -117,34 +117,34 @@ public void applyOriginalTest() throws Exception {
TemplateContext context = new TemplateContext();
final Filter filter = dateFilterSetting.filters.get("date");
- assertThat(filter.apply("Fri Jul 16 01:00:00 2004", context,"%m/%d/%Y"), is((Object)"07/16/2004"));
+ assertThat(filter.apply(context, "Fri Jul 16 01:00:00 2004", "%m/%d/%Y"), is((Object)"07/16/2004"));
- assertThat(filter.apply("Fri Jul 16 01:00 2004", context,"%m/%d/%Y"), is((Object)"07/16/2004"));
+ assertThat(filter.apply(context, "Fri Jul 16 01:00 2004", "%m/%d/%Y"), is((Object)"07/16/2004"));
- assertThat(filter.apply(seconds("2006-05-05 10:00:00"), context, "%B"), is((Object)"May"));
- assertThat(filter.apply(seconds("2006-06-05 10:00:00"), context,"%B"), is((Object)"June"));
- assertThat(filter.apply(seconds("2006-07-05 10:00:00"), context,"%B"), is((Object)"July"));
+ assertThat(filter.apply(context, seconds("2006-05-05 10:00:00"), "%B"), is((Object)"May"));
+ assertThat(filter.apply(context, seconds("2006-06-05 10:00:00"), "%B"), is((Object)"June"));
+ assertThat(filter.apply(context, seconds("2006-07-05 10:00:00"), "%B"), is((Object)"July"));
- assertThat(filter.apply("2006-05-05 10:00:00", context,"%B"), is((Object)"May"));
- assertThat(filter.apply("2006-06-05 10:00:00", context,"%B"), is((Object)"June"));
- assertThat(filter.apply("2006-07-05 10:00:00", context,"%B"), is((Object)"July"));
+ assertThat(filter.apply(context, "2006-05-05 10:00:00", "%B"), is((Object)"May"));
+ assertThat(filter.apply(context, "2006-06-05 10:00:00", "%B"), is((Object)"June"));
+ assertThat(filter.apply(context, "2006-07-05 10:00:00", "%B"), is((Object)"July"));
- assertThat(filter.apply("2006-07-05 10:00:00", context,""), is((Object)"2006-07-05 10:00:00"));
- assertThat(filter.apply("2006-07-05 10:00:00", context), is((Object)"2006-07-05 10:00:00"));
- assertThat(filter.apply("2006-07-05 10:00:00", context, (Object)null), is((Object)"2006-07-05 10:00:00"));
- assertThat(filter.apply("2006-07-05 10:00:00", context, (Object[])null), is((Object)"2006-07-05 10:00:00"));
- assertThat(filter.apply("2006-07-05 10:00:00", context, new Object[0]), is((Object)"2006-07-05 10:00:00"));
+ assertThat(filter.apply(context, "2006-07-05 10:00:00", ""), is((Object)"2006-07-05 10:00:00"));
+ assertThat(filter.apply(context, "2006-07-05 10:00:00"), is((Object)"2006-07-05 10:00:00"));
+ assertThat(filter.apply(context, "2006-07-05 10:00:00", (Object)null), is((Object)"2006-07-05 10:00:00"));
+ assertThat(filter.apply(context, "2006-07-05 10:00:00", (Object[])null), is((Object)"2006-07-05 10:00:00"));
+ assertThat(filter.apply(context, "2006-07-05 10:00:00", new Object[0]), is((Object)"2006-07-05 10:00:00"));
- assertThat(filter.apply("2006-07-05 10:00:00", context,"%m/%d/%Y"), is((Object)"07/05/2006"));
+ assertThat(filter.apply(context, "2006-07-05 10:00:00", "%m/%d/%Y"), is((Object)"07/05/2006"));
- assertThat(filter.apply(null, context,"%B"), is((Object)null));
+ assertThat(filter.apply(context, null, "%B"), is((Object)null));
- assertThat(filter.apply(1152098955, context,"%m/%d/%Y"), is((Object)"07/05/2006"));
- assertThat(filter.apply("1152098955", context,"%m/%d/%Y"), is((Object)"07/05/2006"));
+ assertThat(filter.apply(context, 1152098955, "%m/%d/%Y"), is((Object)"07/05/2006"));
+ assertThat(filter.apply(context, "1152098955", "%m/%d/%Y"), is((Object)"07/05/2006"));
TemplateParser parser = new TemplateParser.Builder().withFlavor(Flavor.LIQUID).withDefaultTimeZone(ZoneOffset.UTC).build();
TemplateContext anotherZone = new TemplateContext(parser, new LinkedHashMap<>());
- assertThat(filter.apply("1152098955", anotherZone,"%H"), is((Object)"11"));
- assertThat(filter.apply(1152098955, anotherZone,"%H"), is((Object)"11"));
+ assertThat(filter.apply(anotherZone, "1152098955", "%H"), is((Object)"11"));
+ assertThat(filter.apply(anotherZone, 1152098955, "%H"), is((Object)"11"));
}
private static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
@@ -188,7 +188,7 @@ public boolean support(Object in) {
// then
TemplateContext context = new TemplateContext();
- assertThat(parser.filters.get("date").apply(customDate, context, "%m/%d/%Y"), is(
+ assertThat(parser.filters.get("date").apply(context, customDate, "%m/%d/%Y"), is(
(Object) "07/05/2006"));
}
@@ -199,7 +199,7 @@ public void testParseWithZoneInfo() {
// String val = "2021-01-27 00:00:00 EST";
// when
- Object res = dateFilterSetting.filters.get("date").apply(val, new TemplateContext(),
+ Object res = dateFilterSetting.filters.get("date").apply(new TemplateContext(), val,
"%Y-%m-%d %H:%M:%S %z");
// then
diff --git a/src/test/java/liqp/filters/Divided_ByTest.java b/src/test/java/liqp/filters/Divided_ByTest.java
index 92ab4d89..0a7000ea 100644
--- a/src/test/java/liqp/filters/Divided_ByTest.java
+++ b/src/test/java/liqp/filters/Divided_ByTest.java
@@ -36,19 +36,19 @@ public void applyTest() throws RecognitionException {
@SuppressWarnings("deprecation")
@Test(expected=RuntimeException.class)
public void applyTestInvalid1() {
- Filters.COMMON_FILTERS.get("divided_by").apply(1);
+ Filters.COMMON_FILTERS.get("divided_by").apply(null, 1);
}
@SuppressWarnings("deprecation")
@Test(expected=RuntimeException.class)
public void applyTestInvalid2() {
- Filters.COMMON_FILTERS.get("divided_by").apply(1, 2, 3);
+ Filters.COMMON_FILTERS.get("divided_by").apply(null, 1, 2, 3);
}
@SuppressWarnings("deprecation")
@Test(expected=RuntimeException.class)
public void applyTestInvalid3() {
- Filters.COMMON_FILTERS.get("divided_by").apply(15L, 0L);
+ Filters.COMMON_FILTERS.get("divided_by").apply(null, 15L, 0L);
}
/*
@@ -69,9 +69,9 @@ public void applyOriginalTest() {
Filter filter = Filters.COMMON_FILTERS.get("divided_by");
- assertThat(filter.apply(12L, 3L), is((Object)4L));
- assertThat(filter.apply(14L, 3L), is((Object)4L));
- assertTrue(String.valueOf(filter.apply(14L, 3.0)).matches("4[,.]6{10,}7"));
+ assertThat(filter.apply(null, 12L, 3L), is((Object)4L));
+ assertThat(filter.apply(null, 14L, 3L), is((Object)4L));
+ assertTrue(String.valueOf(filter.apply(null, 14L, 3.0)).matches("4[,.]6{10,}7"));
// see: applyTestInvalid3()
// assert_template_result "Liquid error: divided by 0", "{{ 5 | divided_by:0 }}"
diff --git a/src/test/java/liqp/filters/DowncaseTest.java b/src/test/java/liqp/filters/DowncaseTest.java
index 1d893667..0523992b 100644
--- a/src/test/java/liqp/filters/DowncaseTest.java
+++ b/src/test/java/liqp/filters/DowncaseTest.java
@@ -42,7 +42,7 @@ public void applyOriginalTest() {
final Filter filter = Filters.COMMON_FILTERS.get("downcase");
TemplateContext templateContext = new TemplateContext();
- assertThat(filter.apply("Testing", templateContext), is((Object)"testing"));
- assertThat(filter.apply(null, templateContext), is((Object)""));
+ assertThat(filter.apply(templateContext, "Testing"), is((Object)"testing"));
+ assertThat(filter.apply(templateContext, null), is((Object)""));
}
}
diff --git a/src/test/java/liqp/filters/EscapeTest.java b/src/test/java/liqp/filters/EscapeTest.java
index 3de0e3b5..67e968ca 100644
--- a/src/test/java/liqp/filters/EscapeTest.java
+++ b/src/test/java/liqp/filters/EscapeTest.java
@@ -45,6 +45,6 @@ public void applyOriginalTest() {
Filter filter = Filters.COMMON_FILTERS.get("escape");
- assertThat(filter.apply("", new TemplateContext()), is((Object)"<strong>"));
+ assertThat(filter.apply(new TemplateContext(), ""), is((Object)"<strong>"));
}
}
diff --git a/src/test/java/liqp/filters/Escape_OnceTest.java b/src/test/java/liqp/filters/Escape_OnceTest.java
index 86176ccc..665b9108 100644
--- a/src/test/java/liqp/filters/Escape_OnceTest.java
+++ b/src/test/java/liqp/filters/Escape_OnceTest.java
@@ -47,10 +47,10 @@ public void applyOriginalTest() {
final Filter filter = Filters.COMMON_FILTERS.get("escape_once");
TemplateContext context = new TemplateContext();
- assertThat(filter.apply(Filters.COMMON_FILTERS.get("escape").apply("", context),
- context), is((Object) "<strong>"));
+ assertThat(filter.apply(context, Filters.COMMON_FILTERS.get("escape").apply(context, "")
+ ), is((Object) "<strong>"));
// the same test:
- assertThat(filter.apply("<strong>", context), is((Object)"<strong>"));
+ assertThat(filter.apply(context, "<strong>"), is((Object)"<strong>"));
}
}
diff --git a/src/test/java/liqp/filters/FilterTest.java b/src/test/java/liqp/filters/FilterTest.java
index 5b3385bc..b36ae12f 100644
--- a/src/test/java/liqp/filters/FilterTest.java
+++ b/src/test/java/liqp/filters/FilterTest.java
@@ -18,7 +18,7 @@ public void testCustomFilter() throws RecognitionException {
TemplateParser parser = new TemplateParser.Builder().withFilter(new Filter("textilize") {
@Override
- public Object apply(Object value, TemplateContext context, Object... params) {
+ public Object apply(TemplateContext context, Object value, Object... params) {
String s = super.asString(value, context).trim();
return "" + s.substring(1, s.length() - 1) + "";
}
diff --git a/src/test/java/liqp/filters/FirstTest.java b/src/test/java/liqp/filters/FirstTest.java
index 6c0ea084..e4faa4cd 100644
--- a/src/test/java/liqp/filters/FirstTest.java
+++ b/src/test/java/liqp/filters/FirstTest.java
@@ -45,7 +45,7 @@ public void applyOriginalTest() {
Filter filter = Filters.COMMON_FILTERS.get("first");
TemplateContext context = new TemplateContext();
- assertThat(filter.apply(new Integer[]{1, 2, 3}, context), is((Object)1));
- assertThat(filter.apply(new Integer[]{}, context), is((Object)null));
+ assertThat(filter.apply(context, new Integer[]{1, 2, 3}), is((Object)1));
+ assertThat(filter.apply(context, new Integer[]{}), is((Object)null));
}
}
diff --git a/src/test/java/liqp/filters/HTest.java b/src/test/java/liqp/filters/HTest.java
index f49a1c1c..8c6509e7 100644
--- a/src/test/java/liqp/filters/HTest.java
+++ b/src/test/java/liqp/filters/HTest.java
@@ -44,6 +44,6 @@ public void applyOriginalTest() {
Filter filter = Filters.COMMON_FILTERS.get("h");
- assertThat(filter.apply("", new TemplateContext()), is((Object)"<strong>"));
+ assertThat(filter.apply(new TemplateContext(), ""), is((Object)"<strong>"));
}
}
diff --git a/src/test/java/liqp/filters/JoinTest.java b/src/test/java/liqp/filters/JoinTest.java
index 819d61b0..b7070e76 100644
--- a/src/test/java/liqp/filters/JoinTest.java
+++ b/src/test/java/liqp/filters/JoinTest.java
@@ -44,7 +44,7 @@ public void applyOriginalTest() {
TemplateContext context = new TemplateContext();
Filter filter = Filters.COMMON_FILTERS.get("join");
- assertThat(filter.apply(new Integer[]{1,2,3,4}, context), is((Object)"1 2 3 4"));
- assertThat(filter.apply(new Integer[]{1,2,3,4}, context, " - "), is((Object)"1 - 2 - 3 - 4"));
+ assertThat(filter.apply(context, new Integer[]{1,2,3,4}), is((Object)"1 2 3 4"));
+ assertThat(filter.apply(context, new Integer[]{1,2,3,4}, " - "), is((Object)"1 - 2 - 3 - 4"));
}
}
diff --git a/src/test/java/liqp/filters/LastTest.java b/src/test/java/liqp/filters/LastTest.java
index 2c17eec6..33db71bb 100644
--- a/src/test/java/liqp/filters/LastTest.java
+++ b/src/test/java/liqp/filters/LastTest.java
@@ -44,7 +44,7 @@ public void applyOriginalTest() {
TemplateContext context = new TemplateContext();
Filter filter = Filters.COMMON_FILTERS.get("last");
- assertThat(filter.apply(new Integer[]{1, 2, 3}, context), is((Object)3));
- assertThat(filter.apply(new Integer[]{}, context), is((Object)null));
+ assertThat(filter.apply(context, new Integer[]{1, 2, 3}), is((Object)3));
+ assertThat(filter.apply(context, new Integer[]{}), is((Object)null));
}
}
diff --git a/src/test/java/liqp/filters/MapTest.java b/src/test/java/liqp/filters/MapTest.java
index 6d36cc9c..c303209d 100644
--- a/src/test/java/liqp/filters/MapTest.java
+++ b/src/test/java/liqp/filters/MapTest.java
@@ -53,13 +53,12 @@ public void applyOriginalTest() {
Filter filter = Filters.COMMON_FILTERS.get("map");
Object[] rendered = (Object[]) filter.apply(
- new java.util.Map,?>[]{
+ new TemplateContext(), new java.util.Map,?>[]{
Collections.singletonMap("a", 1),
Collections.singletonMap("a", 2),
Collections.singletonMap("a", 3),
Collections.singletonMap("a", 4),
},
- new TemplateContext(),
"a"
);
diff --git a/src/test/java/liqp/filters/MinusTest.java b/src/test/java/liqp/filters/MinusTest.java
index 31b9f04b..a02fa15b 100644
--- a/src/test/java/liqp/filters/MinusTest.java
+++ b/src/test/java/liqp/filters/MinusTest.java
@@ -38,13 +38,13 @@ public void applyTest() throws RecognitionException {
@SuppressWarnings("deprecation")
@Test(expected=RuntimeException.class)
public void applyTestInvalid1() {
- Filters.COMMON_FILTERS.get("minus").apply(1);
+ Filters.COMMON_FILTERS.get("minus").apply(null, 1);
}
@SuppressWarnings("deprecation")
@Test(expected=RuntimeException.class)
public void applyTestInvalid2() {
- Filters.COMMON_FILTERS.get("minus").apply(1, 2, 3);
+ Filters.COMMON_FILTERS.get("minus").apply(null, 1, 2, 3);
}
/*
diff --git a/src/test/java/liqp/filters/ModuloTest.java b/src/test/java/liqp/filters/ModuloTest.java
index f20ad9a0..a6717da0 100644
--- a/src/test/java/liqp/filters/ModuloTest.java
+++ b/src/test/java/liqp/filters/ModuloTest.java
@@ -35,13 +35,13 @@ public void applyTest() throws RecognitionException {
@Test(expected=RuntimeException.class)
public void applyTestInvalid1() {
TemplateContext context = new TemplateContext();
- Filters.COMMON_FILTERS.get("modulo").apply(1, context);
+ Filters.COMMON_FILTERS.get("modulo").apply(context, 1);
}
@Test(expected=RuntimeException.class)
public void applyTestInvalid2() {
TemplateContext context = new TemplateContext();
- Filters.COMMON_FILTERS.get("modulo").apply(1, context, 2, 3);
+ Filters.COMMON_FILTERS.get("modulo").apply(context, 1, 2, 3);
}
diff --git a/src/test/java/liqp/filters/Normalize_WhitespaceTest.java b/src/test/java/liqp/filters/Normalize_WhitespaceTest.java
index 4323af80..fac3c3b1 100644
--- a/src/test/java/liqp/filters/Normalize_WhitespaceTest.java
+++ b/src/test/java/liqp/filters/Normalize_WhitespaceTest.java
@@ -50,7 +50,7 @@ public void testNormalizeWhitespace() {
{"a", " a ", "strip whitespace from beginning and end of string"}
};
for (String[] caze: cases) {
- Object actual = filter.apply(caze[1]);
+ Object actual = filter.apply(null, caze[1]);
assertEquals(caze[2], caze[0], actual);
}
}
diff --git a/src/test/java/liqp/filters/PlusTest.java b/src/test/java/liqp/filters/PlusTest.java
index 42ccbc46..ed8b0412 100644
--- a/src/test/java/liqp/filters/PlusTest.java
+++ b/src/test/java/liqp/filters/PlusTest.java
@@ -34,13 +34,13 @@ public void applyTest() throws RecognitionException {
@SuppressWarnings("deprecation")
@Test(expected=RuntimeException.class)
public void applyTestInvalid1() {
- Filters.COMMON_FILTERS.get("plus").apply(1);
+ Filters.COMMON_FILTERS.get("plus").apply(null, 1);
}
@SuppressWarnings("deprecation")
@Test(expected=RuntimeException.class)
public void applyTestInvalid2() {
- Filters.COMMON_FILTERS.get("plus").apply(1, 2, 3);
+ Filters.COMMON_FILTERS.get("plus").apply(null, 1, 2, 3);
}
/*
diff --git a/src/test/java/liqp/filters/RemoveTest.java b/src/test/java/liqp/filters/RemoveTest.java
index 5193fe32..ff80a4e6 100644
--- a/src/test/java/liqp/filters/RemoveTest.java
+++ b/src/test/java/liqp/filters/RemoveTest.java
@@ -48,6 +48,6 @@ public void applyOriginalTest() {
TemplateContext context = new TemplateContext();
Filter filter = Filters.COMMON_FILTERS.get("remove");
- assertThat(filter.apply("a a a a", context, "a"), is((Object)" "));
+ assertThat(filter.apply(context, "a a a a", "a"), is((Object)" "));
}
}
diff --git a/src/test/java/liqp/filters/Remove_FirstTest.java b/src/test/java/liqp/filters/Remove_FirstTest.java
index 35f02566..e8d93e1b 100644
--- a/src/test/java/liqp/filters/Remove_FirstTest.java
+++ b/src/test/java/liqp/filters/Remove_FirstTest.java
@@ -48,7 +48,7 @@ public void applyOriginalTest() {
TemplateContext context = new TemplateContext();
Filter filter = Filters.COMMON_FILTERS.get("remove_first");
- assertThat(filter.apply("a a a a", context, "a "), is((Object)"a a a"));
+ assertThat(filter.apply(context, "a a a a", "a "), is((Object)"a a a"));
assertThat(TemplateParser.DEFAULT.parse("{{ 'a a a a' | remove_first: 'a ' }}").render(), is((Object)"a a a"));
}
}
diff --git a/src/test/java/liqp/filters/ReplaceTest.java b/src/test/java/liqp/filters/ReplaceTest.java
index e3fdbafa..470fae3c 100644
--- a/src/test/java/liqp/filters/ReplaceTest.java
+++ b/src/test/java/liqp/filters/ReplaceTest.java
@@ -53,6 +53,6 @@ public void applyOriginalTest() {
TemplateContext context = new TemplateContext();
Filter filter = Filters.COMMON_FILTERS.get("replace");
- assertThat(filter.apply("a a a a", context, "a", "b"), is((Object)"b b b b"));
+ assertThat(filter.apply(context, "a a a a", "a", "b"), is((Object)"b b b b"));
}
}
diff --git a/src/test/java/liqp/filters/Replace_FirstTest.java b/src/test/java/liqp/filters/Replace_FirstTest.java
index 4940301f..c335af28 100644
--- a/src/test/java/liqp/filters/Replace_FirstTest.java
+++ b/src/test/java/liqp/filters/Replace_FirstTest.java
@@ -53,7 +53,7 @@ public void applyOriginalTest() {
TemplateContext context = new TemplateContext();
Filter filter = Filters.COMMON_FILTERS.get("replace_first");
- assertThat(filter.apply("a a a a", context, "a", "b"), is((Object)"b a a a"));
+ assertThat(filter.apply(context, "a a a a", "a", "b"), is((Object)"b a a a"));
assertThat(TemplateParser.DEFAULT.parse("{{ 'a a a a' | replace_first: 'a', 'b' }}").render(), is("b a a a"));
}
}
diff --git a/src/test/java/liqp/filters/SizeTest.java b/src/test/java/liqp/filters/SizeTest.java
index 995ab196..1c6d0e2d 100644
--- a/src/test/java/liqp/filters/SizeTest.java
+++ b/src/test/java/liqp/filters/SizeTest.java
@@ -52,12 +52,12 @@ public void applyOriginalTest() {
final Filter filter = Filters.COMMON_FILTERS.get("size");
TemplateContext context = new TemplateContext();
- assertThat(filter.apply(new Integer[]{1, 2, 3}, context), is( 3));
- assertThat(filter.apply(new Object[0], context), is(0));
- assertThat(filter.apply(null, context), is(0));
- assertThat(filter.apply(new HashMap<>(), context), is(0));
- assertThat(filter.apply(Collections.singletonMap("a", 1), context), is(1));
- assertThat(filter.apply(new Inspectable() {
+ assertThat(filter.apply(context, new Integer[]{1, 2, 3}), is( 3));
+ assertThat(filter.apply(context, new Object[0]), is(0));
+ assertThat(filter.apply(context, null), is(0));
+ assertThat(filter.apply(context, new HashMap<>()), is(0));
+ assertThat(filter.apply(context, Collections.singletonMap("a", 1)), is(1));
+ assertThat(filter.apply(context, new Inspectable() {
@SuppressWarnings("unused")
public final String a = "a";
@SuppressWarnings("unused")
@@ -66,6 +66,6 @@ public void applyOriginalTest() {
public final String c = "c";
@SuppressWarnings("unused")
public final String d = "d";
- }, context), is(4));
+ }), is(4));
}
}
diff --git a/src/test/java/liqp/filters/SortTest.java b/src/test/java/liqp/filters/SortTest.java
index cd5b6bd1..bcfe600c 100644
--- a/src/test/java/liqp/filters/SortTest.java
+++ b/src/test/java/liqp/filters/SortTest.java
@@ -59,7 +59,7 @@ public void applyOriginalTest() {
Filter filter = Filters.COMMON_FILTERS.get("sort");
- assertThat(filter.apply(new Integer[]{4,3,2,1}, context), is((Object)new Integer[]{1,2,3,4}));
+ assertThat(filter.apply(context, new Integer[]{4,3,2,1}), is((Object)new Integer[]{1,2,3,4}));
java.util.Map,?>[] unsorted = new java.util.Map[]{
Collections.singletonMap("a", 4),
@@ -68,7 +68,7 @@ public void applyOriginalTest() {
Collections.singletonMap("a", 1),
};
- java.util.Map,?>[] sorted = (Sort.SortableMap[])filter.apply(unsorted, context, "a");
+ java.util.Map,?>[] sorted = (Sort.SortableMap[])filter.apply(context, unsorted, "a");
java.util.Map,?>[] expected = new java.util.Map[]{
Collections.singletonMap("a", 1),
@@ -104,7 +104,7 @@ public void testInspectable() {
new Pojo(4), new Pojo(3), new Pojo(2), new Pojo(1)
};
- java.util.Map,?>[] sorted = (Sort.SortableMap[]) filter.apply(unsortedIns, context, "a");
+ java.util.Map,?>[] sorted = (Sort.SortableMap[]) filter.apply(context, unsortedIns, "a");
java.util.Map,?>[] expected = new java.util.Map[]{
Collections.singletonMap("a", 1),
Collections.singletonMap("a", 2),
@@ -136,7 +136,7 @@ public void testLiquidSupport() {
new PojoWithSupport(4), new PojoWithSupport(3), new PojoWithSupport(2), new PojoWithSupport(1)
};
- java.util.Map,?>[] sorted = (Sort.SortableMap[]) filter.apply(unsortedIns, context, "a");
+ java.util.Map,?>[] sorted = (Sort.SortableMap[]) filter.apply(context, unsortedIns, "a");
java.util.Map,?>[] expected = new java.util.Map[]{
Collections.singletonMap("a", 1),
Collections.singletonMap("a", 2),
diff --git a/src/test/java/liqp/filters/SplitTest.java b/src/test/java/liqp/filters/SplitTest.java
index 1df62a79..af57ed6a 100644
--- a/src/test/java/liqp/filters/SplitTest.java
+++ b/src/test/java/liqp/filters/SplitTest.java
@@ -51,9 +51,9 @@ public void applyOriginalTest() {
final Filter filter = Filters.COMMON_FILTERS.get("split");
- assertThat(filter.apply("12~34", context, "~"), is((Object)new String[]{"12", "34"}));
- assertThat(filter.apply("A? ~ ~ ~ ,Z", context, "~ ~ ~"), is((Object)new String[]{"A? ", " ,Z"}));
- assertThat(filter.apply("A?Z", context, "~"), is((Object)new String[]{"A?Z"}));
- assertThat(filter.apply("AxZ", context, Pattern.compile("x")), is((Object)new String[]{"A", "Z"}));
+ assertThat(filter.apply(context, "12~34", "~"), is((Object)new String[]{"12", "34"}));
+ assertThat(filter.apply(context, "A? ~ ~ ~ ,Z", "~ ~ ~"), is((Object)new String[]{"A? ", " ,Z"}));
+ assertThat(filter.apply(context, "A?Z", "~"), is((Object)new String[]{"A?Z"}));
+ assertThat(filter.apply(context, "AxZ", Pattern.compile("x")), is((Object)new String[]{"A", "Z"}));
}
}
diff --git a/src/test/java/liqp/filters/Strip_HTMLTest.java b/src/test/java/liqp/filters/Strip_HTMLTest.java
index 710fb088..e9a96569 100644
--- a/src/test/java/liqp/filters/Strip_HTMLTest.java
+++ b/src/test/java/liqp/filters/Strip_HTMLTest.java
@@ -47,9 +47,9 @@ public void applyOriginalTest() {
TemplateContext context = new TemplateContext();
Filter filter = Filters.COMMON_FILTERS.get("strip_html");
- assertThat(filter.apply("test
", context), is((Object)"test"));
- assertThat(filter.apply("test
", context), is((Object)"test"));
- assertThat(filter.apply("", context), is((Object)""));
- assertThat(filter.apply(null, context), is((Object)""));
+ assertThat(filter.apply(context, "test
"), is((Object)"test"));
+ assertThat(filter.apply(context, "test
"), is((Object)"test"));
+ assertThat(filter.apply(context, ""), is((Object)""));
+ assertThat(filter.apply(context, null), is((Object)""));
}
}
diff --git a/src/test/java/liqp/filters/TimesTest.java b/src/test/java/liqp/filters/TimesTest.java
index 2438a535..5682651d 100644
--- a/src/test/java/liqp/filters/TimesTest.java
+++ b/src/test/java/liqp/filters/TimesTest.java
@@ -42,13 +42,13 @@ public void applyTest() throws RecognitionException {
@SuppressWarnings("deprecation")
@Test(expected=RuntimeException.class)
public void applyTestInvalid1() {
- Filters.COMMON_FILTERS.get("times").apply(1);
+ Filters.COMMON_FILTERS.get("times").apply(null, 1);
}
@SuppressWarnings("deprecation")
@Test(expected=RuntimeException.class)
public void applyTestInvalid2() {
- Filters.COMMON_FILTERS.get("times").apply(1, 2, 3);
+ Filters.COMMON_FILTERS.get("times").apply(null, 1, 2, 3);
}
/*
@@ -69,14 +69,11 @@ public void applyoriginaltest() {
Filter filter = Filters.COMMON_FILTERS.get("times");
- assertThat(filter.apply(3L, 4L), is((Object)12L));
+ assertThat(filter.apply(null, 3L, 4L), is((Object)12L));
// assert_template_result "0", "{{ 'foo' | times:4 }}" // see: applyTest()
- assertTrue(String.valueOf(filter.apply(2.1, 3L)).matches("6[.,]3"));
- assertEquals(new PlainBigDecimal("7.25"), LValue.asFormattedNumber((BigDecimal) filter.apply(
- 0.0725, 100)));
- assertEquals(new PlainBigDecimal("-7.25"), LValue.asFormattedNumber((BigDecimal) filter.apply(
- -0.0725, 100)));
- assertEquals(new PlainBigDecimal("7.25"), LValue.asFormattedNumber((BigDecimal) filter.apply(
- -0.0725, -100)));
+ assertTrue(String.valueOf(filter.apply(null, 2.1, 3L)).matches("6[.,]3"));
+ assertEquals(new PlainBigDecimal("7.25"), LValue.asFormattedNumber((PlainBigDecimal) filter.apply(null, 0.0725, 100)));
+ assertEquals(new PlainBigDecimal("-7.25"), LValue.asFormattedNumber((PlainBigDecimal) filter.apply(null, -0.0725, 100)));
+ assertEquals(new PlainBigDecimal("7.25"), LValue.asFormattedNumber((PlainBigDecimal) filter.apply(null, -0.0725, -100)));
}
}
diff --git a/src/test/java/liqp/filters/TruncateTest.java b/src/test/java/liqp/filters/TruncateTest.java
index 352f4697..a4439d35 100644
--- a/src/test/java/liqp/filters/TruncateTest.java
+++ b/src/test/java/liqp/filters/TruncateTest.java
@@ -51,9 +51,9 @@ public void applyOriginalTest() {
TemplateContext context = new TemplateContext();
final Filter filter = Filters.COMMON_FILTERS.get("truncate");
- assertThat(filter.apply("1234567890", context, 7), is((Object)"1234..."));
- assertThat(filter.apply("1234567890", context, 20), is((Object)"1234567890"));
- assertThat(filter.apply("1234567890", context, 0), is((Object)"..."));
- assertThat(filter.apply("1234567890", context), is((Object)"1234567890"));
+ assertThat(filter.apply(context, "1234567890", 7), is((Object)"1234..."));
+ assertThat(filter.apply(context, "1234567890", 20), is((Object)"1234567890"));
+ assertThat(filter.apply(context, "1234567890", 0), is((Object)"..."));
+ assertThat(filter.apply(context, "1234567890"), is((Object)"1234567890"));
}
}
diff --git a/src/test/java/liqp/filters/TruncatewordsTest.java b/src/test/java/liqp/filters/TruncatewordsTest.java
index eb70024b..169d2f2d 100644
--- a/src/test/java/liqp/filters/TruncatewordsTest.java
+++ b/src/test/java/liqp/filters/TruncatewordsTest.java
@@ -52,10 +52,10 @@ public void applyOriginalTest() {
TemplateContext context = new TemplateContext();
final Filter filter = Filters.COMMON_FILTERS.get("truncatewords");
- assertThat(filter.apply("one two three", context, 4), is((Object)"one two three"));
- assertThat(filter.apply("one two three", context, 2), is((Object)"one two..."));
- assertThat(filter.apply("one two three", context, 3), is((Object)"one two three"));
- assertThat(filter.apply("Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13” x 16” x 10.5” high) with cover.", context, 15),
+ assertThat(filter.apply(context, "one two three", 4), is((Object)"one two three"));
+ assertThat(filter.apply(context, "one two three", 2), is((Object)"one two..."));
+ assertThat(filter.apply(context, "one two three", 3), is((Object)"one two three"));
+ assertThat(filter.apply(context, "Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13” x 16” x 10.5” high) with cover.", 15),
is((Object)"Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13”..."));
}
}
diff --git a/src/test/java/liqp/filters/UpcaseTest.java b/src/test/java/liqp/filters/UpcaseTest.java
index 1776141a..4e9bcb92 100644
--- a/src/test/java/liqp/filters/UpcaseTest.java
+++ b/src/test/java/liqp/filters/UpcaseTest.java
@@ -42,7 +42,7 @@ public void applyOriginalTest() {
TemplateContext context = new TemplateContext();
final Filter filter = Filters.COMMON_FILTERS.get("upcase");
- assertThat(filter.apply("Testing", context), is((Object)"TESTING"));
- assertThat(filter.apply(null, context), is((Object)""));
+ assertThat(filter.apply(context, "Testing"), is((Object)"TESTING"));
+ assertThat(filter.apply(context, null), is((Object)""));
}
}
diff --git a/src/test/java/liqp/nodes/BlockNodeTest.java b/src/test/java/liqp/nodes/BlockNodeTest.java
index 0852b0b5..3c0b7900 100644
--- a/src/test/java/liqp/nodes/BlockNodeTest.java
+++ b/src/test/java/liqp/nodes/BlockNodeTest.java
@@ -19,7 +19,7 @@ public class BlockNodeTest {
*/
@Test
public void customTagTest() throws RecognitionException {
- TemplateParser parser = new TemplateParser.Builder().withInsertion(new Block("testtag"){
+ TemplateParser parser = new TemplateParser.Builder().withBlock(new Block("testtag"){
@Override
public Object render(TemplateContext context, LNode... nodes) {
return null;
diff --git a/src/test/java/liqp/parser/ParseTest.java b/src/test/java/liqp/parser/ParseTest.java
index 12df5f4a..f0a36471 100644
--- a/src/test/java/liqp/parser/ParseTest.java
+++ b/src/test/java/liqp/parser/ParseTest.java
@@ -2,7 +2,10 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import liqp.Template;
+import liqp.TemplateContext;
import org.junit.Test;
import liqp.TemplateParser;
@@ -123,4 +126,37 @@ public void keywords_as_identifier() throws Exception {
.render(" { \"var\": { \"end\": \"content\" } } "),
is("var2: var2:content"));
}
+
+ @Test
+ public void testStripSpaces() {
+ String source = "a \n \n {{ a }} \n \n c";
+
+ // default
+ String res = new TemplateParser.Builder()
+ .build()
+ .parse(source).render("a", "b");
+ assertEquals("a \n \n b \n \n c", res);
+
+
+ // false is default
+ res = new TemplateParser.Builder()
+ .withStripSpaceAroundTags(false)
+ .build()
+ .parse(source).render("a", "b");
+ assertEquals("a \n \n b \n \n c", res);
+
+ // true
+ res = new TemplateParser.Builder()
+ .withStripSpaceAroundTags(true)
+ .build()
+ .parse(source).render("a", "b");
+ assertEquals("abc", res);
+
+ res = new TemplateParser.Builder()
+ .withStripSpaceAroundTags(true)
+ .withStripSingleLine(true)
+ .build()
+ .parse(source).render("a", "b");
+ assertEquals("a \n \nb \n c", res);
+ }
}
diff --git a/src/test/java/liqp/tags/IncludeRelativeTest.java b/src/test/java/liqp/tags/IncludeRelativeTest.java
index dab0bfde..29fab57c 100644
--- a/src/test/java/liqp/tags/IncludeRelativeTest.java
+++ b/src/test/java/liqp/tags/IncludeRelativeTest.java
@@ -11,15 +11,15 @@
import java.io.IOException;
import java.nio.file.Path;
+import java.nio.file.Paths;
-import static liqp.TemplateParser.pwd;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class IncludeRelativeTest {
@Test
public void testSimpleCase() throws IOException {
- Path root = pwd().resolve("src/test/jekyll/relative_include");
+ Path root = Paths.get(".").toAbsolutePath().resolve("src/test/jekyll/relative_include");
Path index = root.resolve("hello.liquid");
TemplateParser parser = new TemplateParser.Builder()
@@ -34,7 +34,7 @@ public void testSimpleCase() throws IOException {
@Test
public void testLiquid() throws IOException {
- Path root = pwd().resolve("src/test/jekyll/relative_include");
+ Path root = Paths.get(".").toAbsolutePath().resolve("src/test/jekyll/relative_include");
Path index = root.resolve("hello.liquid");
TemplateParser parser = new TemplateParser.Builder()
@@ -51,12 +51,12 @@ public void testLiquid() throws IOException {
@Test
public void testLiquidWithCustomIncludeShouldAllowOverride() throws IOException {
- Path root = pwd().resolve("src/test/jekyll/relative_include");
+ Path root = Paths.get(".").toAbsolutePath().resolve("src/test/jekyll/relative_include");
Path index = root.resolve("hello.liquid");
TemplateParser parser = new TemplateParser.Builder()
.withFlavor(Flavor.LIQUID)
- .withInsertion(new Tag("include_relative") {
+ .withTag(new Tag("include_relative") {
@Override
public Object render(TemplateContext context, LNode... nodes) {
return "World";
@@ -86,7 +86,7 @@ public Object render(TemplateContext context, LNode... nodes) {
// And I should see "Welcome back Dear Reader!" in "_site/2018/09/02/star-wars.html"
@Test
public void testIncludeANestedFileRelativeToAPost() throws IOException {
- Path root = pwd().resolve("src/test/jekyll/relative_include");
+ Path root = Paths.get(".").toAbsolutePath().resolve("src/test/jekyll/relative_include");
Path index = root.resolve("nested_include.liquid");
TemplateParser parser = new TemplateParser.Builder()
@@ -103,14 +103,14 @@ public void testIncludeANestedFileRelativeToAPost() throws IOException {
public void testCustomBlocksStackWithCustomBlockIncludeRelative() {
TemplateParser parser = new TemplateParser.Builder()
.withFlavor(Flavor.LIQUID)
- .withInsertion(new Block("another") {
+ .withBlock(new Block("another") {
@Override
public Object render(TemplateContext context, LNode... nodes) {
LNode blockNode = nodes[nodes.length - 1];
return "[" + super.asString(blockNode.render(context), context) + "]";
}
})
- .withInsertion(new Block("include_relative") {
+ .withBlock(new Block("include_relative") {
@Override
public Object render(TemplateContext context, LNode... nodes) {
return "World";
diff --git a/src/test/java/liqp/tags/IncludeTest.java b/src/test/java/liqp/tags/IncludeTest.java
index 3106f36b..8b1ecd88 100644
--- a/src/test/java/liqp/tags/IncludeTest.java
+++ b/src/test/java/liqp/tags/IncludeTest.java
@@ -322,6 +322,7 @@ public void errorInIncludeCauseIgnoreErrorWhenNoExceptionsFromIncludeLegacy() th
File index = new File(jekyll, "index_with_errored_include.html");
Template template = new TemplateParser.Builder()
.withFlavor(Flavor.JEKYLL)
+ .withShowExceptionsFromInclude(false)
.build()
.parse(index);
@@ -348,7 +349,7 @@ public void errorInIncludeCauseMissingIncludeWithCustomRendering() throws IOExce
// when
template.render();
- // them
+ // then
fail();
}