diff --git a/src/test/java/com/hubspot/jinjava/EagerTest.java b/src/test/java/com/hubspot/jinjava/EagerTest.java index 76d5f170f..4c8e19375 100644 --- a/src/test/java/com/hubspot/jinjava/EagerTest.java +++ b/src/test/java/com/hubspot/jinjava/EagerTest.java @@ -60,7 +60,7 @@ public String getString( JinjavaInterpreter interpreter ) throws IOException { return Resources.toString( - Resources.getResource(String.format("tags/macrotag/%s", fullName)), + Resources.getResource(fullName), StandardCharsets.UTF_8 ); } @@ -1597,4 +1597,16 @@ public void prepareContext(Context context) { "keeps-meta-context-variables-through-import/test" ); } + + @Test + public void itWrapsMacroThatWouldChangeCurrentPathInChildScope() { + interpreter + .getContext() + .put(RelativePathResolver.CURRENT_PATH_CONTEXT_KEY, "starting path"); + expectedTemplateInterpreter = + ExpectedTemplateInterpreter.withSensibleCurrentPath(jinjava, interpreter, "eager"); + expectedTemplateInterpreter.assertExpectedOutputNonIdempotent( + "wraps-macro-that-would-change-current-path-in-child-scope/test" + ); + } } diff --git a/src/test/resources/eager/wraps-macro-that-would-change-current-path-in-child-scope/dir1/macro.jinja b/src/test/resources/eager/wraps-macro-that-would-change-current-path-in-child-scope/dir1/macro.jinja new file mode 100644 index 000000000..45fb53d08 --- /dev/null +++ b/src/test/resources/eager/wraps-macro-that-would-change-current-path-in-child-scope/dir1/macro.jinja @@ -0,0 +1,4 @@ +{% macro foo_importer() -%} + {%- include "../dir2/included.jinja" -%} + {%- print foo -%} +{%- endmacro %} \ No newline at end of file diff --git a/src/test/resources/eager/wraps-macro-that-would-change-current-path-in-child-scope/dir2/included.jinja b/src/test/resources/eager/wraps-macro-that-would-change-current-path-in-child-scope/dir2/included.jinja new file mode 100644 index 000000000..bde4ef606 --- /dev/null +++ b/src/test/resources/eager/wraps-macro-that-would-change-current-path-in-child-scope/dir2/included.jinja @@ -0,0 +1,2 @@ +{% set foo = deferred %} +{{ foo }} \ No newline at end of file diff --git a/src/test/resources/eager/wraps-macro-that-would-change-current-path-in-child-scope/test.expected.jinja b/src/test/resources/eager/wraps-macro-that-would-change-current-path-in-child-scope/test.expected.jinja new file mode 100644 index 000000000..025cd0eb5 --- /dev/null +++ b/src/test/resources/eager/wraps-macro-that-would-change-current-path-in-child-scope/test.expected.jinja @@ -0,0 +1,8 @@ +Starting current_path: starting path +Intermediate current_path: starting path +{% for __ignored__ in [0] %}\ +{% set foo = deferred %} +{{ foo }}\ +{% print foo %}\ +{% endfor %} +Ending current_path: starting path \ No newline at end of file diff --git a/src/test/resources/eager/wraps-macro-that-would-change-current-path-in-child-scope/test.jinja b/src/test/resources/eager/wraps-macro-that-would-change-current-path-in-child-scope/test.jinja new file mode 100644 index 000000000..e1f64358a --- /dev/null +++ b/src/test/resources/eager/wraps-macro-that-would-change-current-path-in-child-scope/test.jinja @@ -0,0 +1,5 @@ +Starting current_path: {{ current_path }} +{% from "./dir1/macro.jinja" import foo_importer -%} +Intermediate current_path: {{ current_path }} +{{ foo_importer() }} +Ending current_path: {{ current_path }}