diff options
author | pabs@pablotron.org <pabs@pablotron.org> | 2014-12-18 16:04:12 -0500 |
---|---|---|
committer | pabs@pablotron.org <pabs@pablotron.org> | 2014-12-18 16:04:12 -0500 |
commit | dfc94a5739c99ed0e307fefaeb0dd612a14e8e03 (patch) | |
tree | 8666c1d6e25b013edb517821164e7e86a24eece1 /java/pablotron/luigi | |
parent | da021e741bab02e14268e0d5e3e03b27521ae03b (diff) | |
download | luigi-template-dfc94a5739c99ed0e307fefaeb0dd612a14e8e03.tar.bz2 luigi-template-dfc94a5739c99ed0e307fefaeb0dd612a14e8e03.zip |
add custom and custom args tests
Diffstat (limited to 'java/pablotron/luigi')
-rw-r--r-- | java/pablotron/luigi/Test.java | 30 |
1 files changed, 26 insertions, 4 deletions
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<String, String> args = new HashMap<String, String>() {{ put("name", "paul"); }}; + private static final Map<String, Filter.Handler> filters = new HashMap<String, Filter.Handler>() {{ + put("custom", new Filter.Handler() { + public String filter(String val, String args[], Map<String, String> row) { + return "custom"; + } + }); + + put("custom_with_arg", new Filter.Handler() { + public String filter(String val, String args[], Map<String, String> 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)); } }; |