|
11 | 11 | import com.hubspot.jinjava.interpret.JinjavaInterpreter; |
12 | 12 | import com.hubspot.jinjava.interpret.RenderResult; |
13 | 13 | import com.hubspot.jinjava.lib.fn.MacroFunction; |
| 14 | +import com.hubspot.jinjava.lib.tag.eager.EagerImportTagTest.PrintPathFilter; |
14 | 15 | import com.hubspot.jinjava.loader.LocationResolver; |
15 | 16 | import com.hubspot.jinjava.loader.RelativePathResolver; |
16 | 17 | import com.hubspot.jinjava.loader.ResourceLocator; |
@@ -39,6 +40,7 @@ public void setup() { |
39 | 40 | ); |
40 | 41 |
|
41 | 42 | context.put("padding", 42); |
| 43 | + context.registerFilter(new PrintPathFilter()); |
42 | 44 | } |
43 | 45 |
|
44 | 46 | @Test |
@@ -76,6 +78,21 @@ public void itAvoidsNestedImportCycle() throws IOException { |
76 | 78 | .contains("Import cycle detected", "b-imports-a.jinja"); |
77 | 79 | } |
78 | 80 |
|
| 81 | + @Test |
| 82 | + public void itHandlesNullImportedValues() throws IOException { |
| 83 | + Jinjava jinjava = new Jinjava(); |
| 84 | + interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); |
| 85 | + |
| 86 | + interpreter.render( |
| 87 | + Resources.toString( |
| 88 | + Resources.getResource("tags/importtag/imports-null.jinja"), |
| 89 | + StandardCharsets.UTF_8 |
| 90 | + ) |
| 91 | + ); |
| 92 | + assertThat(context.get("foo")).isEqualTo("foo"); |
| 93 | + assertThat(context.get("bar")).isEqualTo(null); |
| 94 | + } |
| 95 | + |
79 | 96 | @Test |
80 | 97 | public void importedContextExposesVars() { |
81 | 98 | assertThat(fixture("import")) |
@@ -352,6 +369,17 @@ public void itSetsErrorLineNumbersCorrectlyForImportedMacros() throws IOExceptio |
352 | 369 | .isEqualTo("tags/importtag/errors/macro-with-error.jinja"); |
353 | 370 | } |
354 | 371 |
|
| 372 | + @Test |
| 373 | + public void itCorrectlySetsNestedPaths() { |
| 374 | + context.put("foo", "foo"); |
| 375 | + assertThat( |
| 376 | + interpreter.render( |
| 377 | + "{% import 'double-import-macro.jinja' %}{{ print_path_macro2(foo) }}" |
| 378 | + ) |
| 379 | + ) |
| 380 | + .isEqualTo("double-import-macro.jinja\n\nimport-macro.jinja\nfoo\n"); |
| 381 | + } |
| 382 | + |
355 | 383 | private String fixture(String name) { |
356 | 384 | try { |
357 | 385 | return interpreter.renderFlat( |
|
0 commit comments