|
4 | 4 | import com.github.mustachejava.util.CapturingMustacheVisitor; |
5 | 5 | import com.github.mustachejavabenchmarks.JsonCapturer; |
6 | 6 | import com.github.mustachejavabenchmarks.JsonInterpreterTest; |
| 7 | +import com.google.common.base.Function; |
7 | 8 | import junit.framework.TestCase; |
8 | 9 | import org.codehaus.jackson.JsonGenerator; |
9 | 10 | import org.codehaus.jackson.JsonNode; |
@@ -351,6 +352,39 @@ public String apply(@Nullable String s) { |
351 | 352 | assertEquals("This is not interesting.", sw.toString()); |
352 | 353 | } |
353 | 354 |
|
| 355 | + public void testFunctions() throws IOException { |
| 356 | + MustacheFactory c = init(); |
| 357 | + Mustache m = c.compile(new StringReader("{{#f}}{{foo}}{{/f}}"), "test"); |
| 358 | + { |
| 359 | + StringWriter sw = new StringWriter(); |
| 360 | + m.execute(sw, new Object() { |
| 361 | + Function f = new Function<String, String>() { |
| 362 | + @Override |
| 363 | + public String apply(String s) { |
| 364 | + return s.toUpperCase(); |
| 365 | + } |
| 366 | + }; |
| 367 | + String foo = "bar"; |
| 368 | + }).flush(); |
| 369 | + assertEquals("BAR", sw.toString()); |
| 370 | + } |
| 371 | + { |
| 372 | + StringWriter sw = new StringWriter(); |
| 373 | + m.execute(sw, new Object() { |
| 374 | + Function f = new TemplateFunction() { |
| 375 | + @Override |
| 376 | + public String apply(String s) { |
| 377 | + return s.toUpperCase(); |
| 378 | + } |
| 379 | + }; |
| 380 | + String foo = "bar"; |
| 381 | + String FOO = "baz"; |
| 382 | + }).flush(); |
| 383 | + assertEquals("baz", sw.toString()); |
| 384 | + } |
| 385 | + } |
| 386 | + |
| 387 | + |
354 | 388 | public void testComplex() throws MustacheException, IOException { |
355 | 389 | StringWriter json = new StringWriter(); |
356 | 390 | MappingJsonFactory jf = new MappingJsonFactory(); |
|
0 commit comments