Skip to content

Commit

Permalink
Use sensible current path for eager execution test fixtures for relative
Browse files Browse the repository at this point in the history
path resolving
  • Loading branch information
jasmith-hs committed Sep 11, 2024
1 parent ffacfab commit f1742bc
Show file tree
Hide file tree
Showing 43 changed files with 105 additions and 101 deletions.
6 changes: 2 additions & 4 deletions src/test/java/com/hubspot/jinjava/EagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down Expand Up @@ -89,7 +89,7 @@ public Optional<LocationResolver> getLocationResolver() {
);
interpreter = new JinjavaInterpreter(parentInterpreter);
expectedTemplateInterpreter =
new ExpectedTemplateInterpreter(jinjava, interpreter, "eager");
ExpectedTemplateInterpreter.withSensibleCurrentPath(jinjava, interpreter, "eager");
localContext = interpreter.getContext();

localContext.put("deferred", DeferredValue.instance());
Expand Down Expand Up @@ -1590,7 +1590,6 @@ public void itReconstructsAliasedMacroSecondPass() {

@Test
public void itReconstructsBlockPathWhenDeferred() {
interpreter.getContext().getCurrentPathStack().push("Child path", 0, 0);
expectedTemplateInterpreter.assertExpectedOutputNonIdempotent(
"reconstructs-block-path-when-deferred/test"
);
Expand All @@ -1606,7 +1605,6 @@ public void itReconstructsBlockPathWhenDeferredSecondPass() {

@Test
public void itReconstructsBlockPathWhenDeferredNested() {
interpreter.getContext().getCurrentPathStack().push("Child path", 0, 0);
expectedTemplateInterpreter.assertExpectedOutputNonIdempotent(
"reconstructs-block-path-when-deferred-nested/test"
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% do %}\
{% set current_path = 'filters.jinja' %}\
{% set current_path = 'eager/allows-variable-sharing-alias-name/filters.jinja' %}\
{% set __temp_import_alias_854547461__ = {} %}\
{% for __ignored__ in [0] %}
{% set bar = deferred %}\
Expand All @@ -8,10 +8,10 @@
{% set filters = {} %}\
{% do __temp_import_alias_854547461__.update({'filters': filters}) %}\
{% do filters.update(deferred) %}
{% do __temp_import_alias_854547461__.update({'bar': bar,'foo': 123,'import_resource_path': 'filters.jinja','filters': filters}) %}\
{% do __temp_import_alias_854547461__.update({'bar': bar,'foo': 123,'import_resource_path': 'eager/allows-variable-sharing-alias-name/filters.jinja','filters': filters}) %}\
{% endfor %}\
{% set filters = __temp_import_alias_854547461__ %}\
{% set current_path = '' %}\
{% set current_path = 'eager/allows-variable-sharing-alias-name/test.jinja' %}\
{% enddo %}

{{ filters }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% import 'filters.jinja' as filters %}
{% import './filters.jinja' as filters %}

{{ filters }}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% set foo = 'start' %}\
{% for __ignored__ in [0] %}
{% do %}\
{% set current_path = 'deferred-modification.jinja' %}\
{% set current_path = 'eager/supplements/deferred-modification.jinja' %}\
{% set __temp_import_alias_3016318__ = {} %}\
{% for __ignored__ in [0] %}\
{% if deferred %}
Expand All @@ -13,14 +13,14 @@

{% set foo = filter:join.filter([foo, 'b'], ____int3rpr3t3r____, '') %}\
{% do __temp_import_alias_3016318__.update({'foo': foo}) %}
{% do __temp_import_alias_3016318__.update({'foo': foo,'import_resource_path': 'deferred-modification.jinja'}) %}\
{% do __temp_import_alias_3016318__.update({'foo': foo,'import_resource_path': 'eager/supplements/deferred-modification.jinja'}) %}\
{% endfor %}\
{% set bar1 = __temp_import_alias_3016318__ %}\
{% set current_path = '' %}\
{% set current_path = 'eager/does-not-override-import-modification-in-for/test.jinja' %}\
{% enddo %}
{{ bar1.foo }}
{% do %}\
{% set current_path = 'deferred-modification.jinja' %}\
{% set current_path = 'eager/supplements/deferred-modification.jinja' %}\
{% set __temp_import_alias_3016319__ = {} %}\
{% for __ignored__ in [0] %}\
{% if deferred %}
Expand All @@ -32,15 +32,15 @@

{% set foo = filter:join.filter([foo, 'b'], ____int3rpr3t3r____, '') %}\
{% do __temp_import_alias_3016319__.update({'foo': foo}) %}
{% do __temp_import_alias_3016319__.update({'import_resource_path': 'deferred-modification.jinja'}) %}\
{% do __temp_import_alias_3016319__.update({'import_resource_path': 'eager/supplements/deferred-modification.jinja'}) %}\
{% endfor %}\
{% set bar2 = __temp_import_alias_3016319__ %}\
{% set current_path = '' %}\
{% set current_path = 'eager/does-not-override-import-modification-in-for/test.jinja' %}\
{% enddo %}
{{ bar2.foo }}

{% do %}\
{% set current_path = 'deferred-modification.jinja' %}\
{% set current_path = 'eager/supplements/deferred-modification.jinja' %}\
{% set __temp_import_alias_3016318__ = {} %}\
{% for __ignored__ in [0] %}\
{% if deferred %}
Expand All @@ -52,14 +52,14 @@

{% set foo = filter:join.filter([foo, 'b'], ____int3rpr3t3r____, '') %}\
{% do __temp_import_alias_3016318__.update({'foo': foo}) %}
{% do __temp_import_alias_3016318__.update({'import_resource_path': 'deferred-modification.jinja'}) %}\
{% do __temp_import_alias_3016318__.update({'import_resource_path': 'eager/supplements/deferred-modification.jinja'}) %}\
{% endfor %}\
{% set bar1 = __temp_import_alias_3016318__ %}\
{% set current_path = '' %}\
{% set current_path = 'eager/does-not-override-import-modification-in-for/test.jinja' %}\
{% enddo %}
{{ bar1.foo }}
{% do %}\
{% set current_path = 'deferred-modification.jinja' %}\
{% set current_path = 'eager/supplements/deferred-modification.jinja' %}\
{% set __temp_import_alias_3016319__ = {} %}\
{% for __ignored__ in [0] %}\
{% if deferred %}
Expand All @@ -71,10 +71,10 @@

{% set foo = filter:join.filter([foo, 'b'], ____int3rpr3t3r____, '') %}\
{% do __temp_import_alias_3016319__.update({'foo': foo}) %}
{% do __temp_import_alias_3016319__.update({'import_resource_path': 'deferred-modification.jinja'}) %}\
{% do __temp_import_alias_3016319__.update({'import_resource_path': 'eager/supplements/deferred-modification.jinja'}) %}\
{% endfor %}\
{% set bar2 = __temp_import_alias_3016319__ %}\
{% set current_path = '' %}\
{% set current_path = 'eager/does-not-override-import-modification-in-for/test.jinja' %}\
{% enddo %}
{{ bar2.foo }}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% set foo = 'start' %}
{% for i in range(2) %}
{% import "deferred-modification.jinja" as bar1 %}
{% import "../supplements/deferred-modification.jinja" as bar1 %}
{{ bar1.foo }}
{% import "deferred-modification.jinja" as bar2 %}
{% import "../supplements/deferred-modification.jinja" as bar2 %}
{{ bar2.foo }}
{% endfor %}
{{ foo }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% import 'eager/settings.jinja' as shared %}
{% import './settings.jinja' as shared %}

{% if deferred %}
{{ shared.load_settings() }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- set myname = deferred + (3 + 4) -%}
{%- from "macro-and-set.jinja" import foo as from_foo, bar as from_bar -%}
{%- from "../supplements/macro-and-set.jinja" import foo as from_foo, bar as from_bar -%}
from_foo: {{ from_foo() }}
from_bar: {{ from_bar }}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ bar: {{ bar }}
---
{% set myname = deferred + 7 %}\
{% do %}\
{% set current_path = 'macro-and-set.jinja' %}\
{% set current_path = 'eager/supplements/macro-and-set.jinja' %}\
{% set __temp_import_alias_902286926__ = {} %}\
{% for __ignored__ in [0] %}
{% set bar = myname + 19 %}\
{% do __temp_import_alias_902286926__.update({'bar': bar}) %}
Hello {{ myname }}
{% do __temp_import_alias_902286926__.update({'import_resource_path': 'macro-and-set.jinja'}) %}\
{% do __temp_import_alias_902286926__.update({'import_resource_path': 'eager/supplements/macro-and-set.jinja'}) %}\
{% endfor %}\
{% set simple = __temp_import_alias_902286926__ %}\
{% set current_path = '' %}\
{% set current_path = 'eager/handles-deferred-import-vars/test.jinja' %}\
{% enddo %}\
simple.foo: {% set deferred_import_resource_path = 'macro-and-set.jinja' %}\
simple.foo: {% set deferred_import_resource_path = 'eager/supplements/macro-and-set.jinja' %}\
{% macro simple.foo() %}\
Hello {{ myname }}\
{% endmacro %}\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{%- set myname = deferred + (1 + 2) -%}
{%- from "macro-and-set.jinja" import foo, bar -%}
{%- from "../supplements/macro-and-set.jinja" import foo, bar -%}
foo: {{ foo() }}
bar: {{ bar }}
---
{% set myname = deferred + (3 + 4) -%}
{%- import "macro-and-set.jinja" as simple -%}
{%- import "../supplements/macro-and-set.jinja" as simple -%}
simple.foo: {{ simple.foo() }}
simple.bar: {{ simple.bar }}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% do %}\
{% set current_path = 'deferred-modification.jinja' %}\
{% set current_path = 'eager/supplements/deferred-modification.jinja' %}\
{% set __temp_import_alias_3016318__ = {} %}\
{% for __ignored__ in [0] %}\
{% if deferred %}
Expand All @@ -11,14 +11,14 @@

{% set foo = filter:join.filter([foo, 'b'], ____int3rpr3t3r____, '') %}\
{% do __temp_import_alias_3016318__.update({'foo': foo}) %}
{% do __temp_import_alias_3016318__.update({'foo': foo,'import_resource_path': 'deferred-modification.jinja'}) %}\
{% do __temp_import_alias_3016318__.update({'foo': foo,'import_resource_path': 'eager/supplements/deferred-modification.jinja'}) %}\
{% endfor %}\
{% set bar1 = __temp_import_alias_3016318__ %}\
{% set current_path = '' %}\
{% set current_path = 'eager/handles-double-import-modification/test.jinja' %}\
{% enddo %}
---
{% do %}\
{% set current_path = 'deferred-modification.jinja' %}\
{% set current_path = 'eager/supplements/deferred-modification.jinja' %}\
{% set __temp_import_alias_3016319__ = {} %}\
{% for __ignored__ in [0] %}\
{% if deferred %}
Expand All @@ -30,11 +30,11 @@

{% set foo = filter:join.filter([foo, 'b'], ____int3rpr3t3r____, '') %}\
{% do __temp_import_alias_3016319__.update({'foo': foo}) %}
{% do __temp_import_alias_3016319__.update({'foo': foo,'import_resource_path': 'deferred-modification.jinja'}) %}\
{% do __temp_import_alias_3016319__.update({'foo': foo,'import_resource_path': 'eager/supplements/deferred-modification.jinja'}) %}\
{% endfor %}\
{% set bar2 = __temp_import_alias_3016319__ %}\
{% set current_path = '' %}\
{% set current_path = 'eager/handles-double-import-modification/test.jinja' %}\
{% enddo %}
---
{{ bar1.foo }}
{{ bar2.foo }}
{{ bar2.foo }}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% import "deferred-modification.jinja" as bar1 %}
{% import "../supplements/deferred-modification.jinja" as bar1 %}
---
{% import "deferred-modification.jinja" as bar2 %}
{% import "../supplements/deferred-modification.jinja" as bar2 %}
---
{{ bar1.foo }}
{{ bar2.foo }}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{% set primary_line_height = 100 %}\
{% if deferred %}
{% do %}\
{% set current_path = '../settag/set-val.jinja' %}\
{% set current_path = 'eager/supplements/set-val.jinja' %}\
{% set __temp_import_alias_902286926__ = {} %}\
{% for __ignored__ in [0] %}\
{% set primary_line_height = 42 %}\
{% do __temp_import_alias_902286926__.update({'primary_line_height': primary_line_height}) %}\
{% do __temp_import_alias_902286926__.update({'primary_line_height': 42,'import_resource_path': '../settag/set-val.jinja'}) %}\
{% do __temp_import_alias_902286926__.update({'primary_line_height': 42,'import_resource_path': 'eager/supplements/set-val.jinja'}) %}\
{% endfor %}\
{% set simple = __temp_import_alias_902286926__ %}\
{% set current_path = '' %}\
{% set current_path = 'eager/handles-import-in-deferred-if/test.jinja' %}\
{% enddo %}
{% else %}
{% do %}\
{% set current_path = '../settag/set-val.jinja' %}\
{% set current_path = 'eager/supplements/set-val.jinja' %}\
{% set primary_line_height = 42 %}\
{% set current_path = '' %}\
{% set current_path = 'eager/handles-import-in-deferred-if/test.jinja' %}\
{% enddo %}
{% endif %}
simple.primary_line_height (deferred): {{ simple.primary_line_height }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{% set primary_line_height = 100 %}
{% set secondary_line_height = 200 %}
{% if deferred %}
{% import "../settag/set-val.jinja" as simple %}
{% import "../supplements/set-val.jinja" as simple %}
{% else %}
{% import "../settag/set-val.jinja" %}
{% import "../supplements/set-val.jinja" %}
{% endif %}
simple.primary_line_height (deferred): {{ simple.primary_line_height }}
primary_line_height (deferred): {{ primary_line_height }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% set myname = 'person' %}
{% if deferred %}
{%- import "macro-and-set.jinja" as simple -%}
{%- import "../supplements/macro-and-set.jinja" as simple -%}
{% else %}
{%- import "macro-and-set.jinja" as simple -%}
{%- import "../supplements/macro-and-set.jinja" as simple -%}
{% endif %}
simple.foo: {{ simple.foo() }}
simple.bar: {{ simple.bar }}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{%- set myname = (1 + 2) -%}
{%- from "macro-and-set.jinja" import foo, bar -%}
{%- from "../supplements/macro-and-set.jinja" import foo, bar -%}
foo: {{ foo() }}
bar: {{ bar }}
---
{% set myname = (3 + 4) -%}
{%- import "macro-and-set.jinja" as simple -%}
{%- import "../supplements/macro-and-set.jinja" as simple -%}
simple.foo: {{ simple.foo() }}
simple.bar: {{ simple.bar }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% if deferred %}
{% do %}{% set path = 'eager/handles-same-name-import-var/set-var-and-deferred.jinja' %}{% set value = null %}{% set my_var = {} %}{% set my_var = {'foo': 'bar'} %}{% set my_var = {'my_var': my_var} %}
{% set value = deferred %}{% do my_var.update({"value": value}) %}
{% do my_var.update({'import_resource_path': 'eager/handles-same-name-import-var/set-var-and-deferred.jinja','value': value}) %}{% set path = '' %}{% enddo %}
{{ my_var }}
{% endif %}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[fn:map_entry('import_resource_path', '../settag/set-var-and-deferred.jinja'), fn:map_entry('my_var', {'my_var': {'foo': 'bar'} , 'value': 'resolved', 'import_resource_path': '../settag/set-var-and-deferred.jinja'} ), fn:map_entry('path', ''), fn:map_entry('value', 'resolved')]
[fn:map_entry('import_resource_path', 'eager/handles-same-name-import-var/set-var-and-deferred.jinja'), fn:map_entry('my_var', {'my_var': {'foo': 'bar'} , 'value': 'resolved', 'import_resource_path': 'eager/handles-same-name-import-var/set-var-and-deferred.jinja'} ), fn:map_entry('path', ''), fn:map_entry('value', 'resolved')]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% if deferred %}
{% do %}\
{% set current_path = '../settag/set-var-and-deferred.jinja' %}\
{% set current_path = 'eager/handles-same-name-import-var/set-var-and-deferred.jinja' %}\
{% set __temp_import_alias_1059697132__ = {} %}\
{% for __ignored__ in [0] %}\
{% if deferred %}
Expand All @@ -9,7 +9,7 @@
{% do __temp_import_alias_1059697132__.update({'path': path}) %}\
{% set my_var = {'my_var': {'foo': 'bar'} } %}\
{% do __temp_import_alias_1059697132__.update({'my_var': my_var}) %}\
{% set path = '../settag/set-var-and-deferred.jinja' %}\
{% set path = 'eager/handles-same-name-import-var/set-var-and-deferred.jinja' %}\
{% do __temp_import_alias_1059697132__.update({'path': path}) %}\
{% set value = null %}\
{% do __temp_import_alias_1059697132__.update({'value': value}) %}\
Expand All @@ -24,16 +24,16 @@
{% set my_var = {'my_var': {'foo': 'bar'} } %}\
{% do __temp_import_alias_1059697132__.update({'my_var': my_var}) %}\
{% do my_var.update({'value': value}) %}
{% do my_var.update({'import_resource_path': '../settag/set-var-and-deferred.jinja', 'value': value}) %}\
{% do my_var.update({'import_resource_path': 'eager/handles-same-name-import-var/set-var-and-deferred.jinja', 'value': value}) %}\
{% set path = '' %}\
{% do __temp_import_alias_1059697132__.update({'path': path}) %}\
{% enddo %}
{{ my_var }}
{% endif %}
{% do __temp_import_alias_1059697132__.update({'path': path,'import_resource_path': '../settag/set-var-and-deferred.jinja','value': value}) %}\
{% do __temp_import_alias_1059697132__.update({'path': path,'import_resource_path': 'eager/handles-same-name-import-var/set-var-and-deferred.jinja','value': value}) %}\
{% endfor %}\
{% set my_var = __temp_import_alias_1059697132__ %}\
{% set current_path = '' %}\
{% set current_path = 'eager/handles-same-name-import-var/test.jinja' %}\
{% enddo %}
{{ filter:dictsort.filter(my_var, ____int3rpr3t3r____, false, 'key') }}
{% endif %}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% if deferred %}
{% import '../settag/set-var-and-deferred.jinja' as my_var %}
{% import './set-var-and-deferred.jinja' as my_var %}
{{ my_var|dictsort(false, 'key') }}
{% endif %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set myname = deferred + 3 %}\
{% set __macro_getPath_331491059_temp_variable_1__ %}\
{% set __macro_getPath_1519775617_temp_variable_1__ %}\
Hello {{ myname }}\
{% endset %}\
{% print __macro_getPath_331491059_temp_variable_1__ %}
{% print __macro_getPath_1519775617_temp_variable_1__ %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{%- from "simple-with-call.jinja" import getPath -%}
{%- from "../supplements/simple-with-call.jinja" import getPath -%}
{%- set myname = deferred + (1 + 2) -%}
{% print getPath() %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set myname = deferred + 3 %}\
{% set __macro_getPath_331491059_temp_variable_1__ %}\
{% set __macro_getPath_1519775617_temp_variable_1__ %}\
Hello {{ myname }}\
{% endset %}\
{% print __macro_getPath_331491059_temp_variable_1__ %}
{% print __macro_getPath_1519775617_temp_variable_1__ %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{%- import "simple-with-call.jinja" as simple -%}
{%- import "../supplements/simple-with-call.jinja" as simple -%}
{%- set myname = deferred + (1 + 2) -%}
{% print simple.getPath() %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set myname = deferred + 3 %}\
{% set deferred_import_resource_path = 'eager/takes-param.jinja' %}\
{% set deferred_import_resource_path = 'eager/reconstructs-aliased-macro/takes-param.jinja' %}\
{% macro macros.takes_param(foo) %}\
{% set bar = 'bar' %}
{% print foo %}
Expand Down
Loading

0 comments on commit f1742bc

Please sign in to comment.