From d49c704372beeac1bb0e0c8af356b1cb12aba421 Mon Sep 17 00:00:00 2001 From: Jack Smith Date: Thu, 16 May 2024 15:17:06 -0400 Subject: [PATCH] Add test that meta context variables are not overridden when importing --- .../java/com/hubspot/jinjava/EagerTest.java | 17 +++++++++++++++++ .../import-target.jinja | 1 + .../test.expected.jinja | 4 ++++ .../test.jinja | 5 +++++ 4 files changed, 27 insertions(+) create mode 100644 src/test/resources/eager/keeps-meta-context-variables-through-import/import-target.jinja create mode 100644 src/test/resources/eager/keeps-meta-context-variables-through-import/test.expected.jinja create mode 100644 src/test/resources/eager/keeps-meta-context-variables-through-import/test.jinja diff --git a/src/test/java/com/hubspot/jinjava/EagerTest.java b/src/test/java/com/hubspot/jinjava/EagerTest.java index fc23ebf4d..b897b8cfa 100644 --- a/src/test/java/com/hubspot/jinjava/EagerTest.java +++ b/src/test/java/com/hubspot/jinjava/EagerTest.java @@ -1572,4 +1572,21 @@ public void itReconstructsBlockPathWhenDeferredNestedSecondPass() { "reconstructs-block-path-when-deferred-nested/test.expected" ); } + + @Test + public void itKeepsMetaContextVariablesThroughImport() { + setupWithExecutionMode( + new EagerExecutionMode() { + @Override + public void prepareContext(Context context) { + super.prepareContext(context); + context.getMetaContextVariables().add("meta"); + } + } + ); + interpreter.getContext().put("meta", new ArrayList<>()); + expectedTemplateInterpreter.assertExpectedOutput( + "keeps-meta-context-variables-through-import/test" + ); + } } diff --git a/src/test/resources/eager/keeps-meta-context-variables-through-import/import-target.jinja b/src/test/resources/eager/keeps-meta-context-variables-through-import/import-target.jinja new file mode 100644 index 000000000..707978124 --- /dev/null +++ b/src/test/resources/eager/keeps-meta-context-variables-through-import/import-target.jinja @@ -0,0 +1 @@ +I am a boring import \ No newline at end of file diff --git a/src/test/resources/eager/keeps-meta-context-variables-through-import/test.expected.jinja b/src/test/resources/eager/keeps-meta-context-variables-through-import/test.expected.jinja new file mode 100644 index 000000000..dbced8528 --- /dev/null +++ b/src/test/resources/eager/keeps-meta-context-variables-through-import/test.expected.jinja @@ -0,0 +1,4 @@ +{% set list = deferred %} + +{% set meta = ['overridden'] %}{% do list.append(meta) %} +{{ list }} \ No newline at end of file diff --git a/src/test/resources/eager/keeps-meta-context-variables-through-import/test.jinja b/src/test/resources/eager/keeps-meta-context-variables-through-import/test.jinja new file mode 100644 index 000000000..5b1adc00c --- /dev/null +++ b/src/test/resources/eager/keeps-meta-context-variables-through-import/test.jinja @@ -0,0 +1,5 @@ +{% set meta = ['overridden'] %} +{% set list = deferred %} +{% import '../../eager/keeps-meta-context-variables-through-import/import-target.jinja' %} +{% do list.append(meta) %} +{{ list }} \ No newline at end of file