From dfc94a5739c99ed0e307fefaeb0dd612a14e8e03 Mon Sep 17 00:00:00 2001 From: "pabs@pablotron.org" Date: Thu, 18 Dec 2014 16:04:12 -0500 Subject: add custom and custom args tests --- java/pablotron/luigi/Test.java | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'java/pablotron') diff --git a/java/pablotron/luigi/Test.java b/java/pablotron/luigi/Test.java index 6553939..e687308 100644 --- a/java/pablotron/luigi/Test.java +++ b/java/pablotron/luigi/Test.java @@ -2,19 +2,41 @@ package pablotron.luigi; import java.util.Map; import java.util.HashMap; -import pablotron.luigi.Template; import pablotron.luigi.LuigiError; +import pablotron.luigi.Template; +import pablotron.luigi.Filter; public final class Test { - private static final String TEMPLATE = "hello %{name | uc}"; + private static final String TEMPLATE = + "test basic: hello %{name}\n" + + "test filter: hello %{name | uc}\n" + + "test custom: %{name | custom | uc | lc}\n" + + "test custom_with_arg: %{name | custom_with_arg hello}\n"; private static final Map args = new HashMap() {{ put("name", "paul"); }}; + private static final Map filters = new HashMap() {{ + put("custom", new Filter.Handler() { + public String filter(String val, String args[], Map row) { + return "custom"; + } + }); + + put("custom_with_arg", new Filter.Handler() { + public String filter(String val, String args[], Map row) { + return (args.length > 0) ? args[0] : "custom"; + } + }); + }}; + public static void main(String cli_args[]) throws Exception { - final Template t = new Template(TEMPLATE); + // add custom filters to default filter cache + Filter.FILTERS.putAll(filters); - System.out.println(t.run(args)); + // create and run template + final Template t = new Template(TEMPLATE); + System.out.print(t.run(args)); } }; -- cgit v1.2.3