Skip to content

Commit

Permalink
Fix setup of old test which was not properly testing any real logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmith-hs committed Oct 5, 2023
1 parent d5c198b commit dfcd35b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.hubspot.jinjava.interpret.Context;
import com.hubspot.jinjava.interpret.DeferredValue;
import com.hubspot.jinjava.interpret.JinjavaInterpreter;
import com.hubspot.jinjava.interpret.RenderResult;
import com.hubspot.jinjava.lib.filter.Filter;
import com.hubspot.jinjava.lib.tag.ImportTag;
import com.hubspot.jinjava.lib.tag.ImportTagTest;
Expand All @@ -22,12 +23,12 @@
import com.hubspot.jinjava.loader.RelativePathResolver;
import com.hubspot.jinjava.loader.ResourceLocator;
import com.hubspot.jinjava.mode.EagerExecutionMode;
import com.hubspot.jinjava.objects.collections.PyMap;
import com.hubspot.jinjava.tree.parse.DefaultTokenScannerSymbols;
import com.hubspot.jinjava.tree.parse.TagToken;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
Expand Down Expand Up @@ -165,66 +166,32 @@ public void itHandlesMultiLayerAliased() {
@Test
@SuppressWarnings("unchecked")
public void itHandlesMultiLayerAliasedAndDeferred() {
setupResourceLocator();
String child2Alias = "double_child";
JinjavaInterpreter child = getChildInterpreter(interpreter, CONTEXT_VAR);
JinjavaInterpreter child2 = getChildInterpreter(child, child2Alias);

child2.render("{% set foo = 'foo val' %}");
child.render("{% set bar = 'bar val' %}");
child2.render("{% set foo_d = deferred %}");

getAliasedStrategy(child2Alias, child).integrateChild(child2);
getAliasedStrategy(CONTEXT_VAR, interpreter).integrateChild(child);
RenderResult result = jinjava.renderForResult(
"{% import 'layer-one.jinja' as context_var %}",
new HashMap<>()
);

assertThat(interpreter.getContext().get(CONTEXT_VAR)).isInstanceOf(PyMap.class);
assertThat(
((Map<String, Object>) interpreter.getContext().get(CONTEXT_VAR)).get(child2Alias)
)
.isInstanceOf(DeferredValue.class);
assertThat(result.getContext().get(CONTEXT_VAR)).isInstanceOf(DeferredValue.class);
assertThat(
(
(
(Map<String, Object>) (
(DeferredValue) (
(Map<String, Object>) (interpreter.getContext().get(CONTEXT_VAR))
).get(child2Alias)
).getOriginalValue()
).get("foo")
)
)
.isEqualTo("foo val");

assertThat(
(((Map<String, Object>) interpreter.getContext().get(CONTEXT_VAR)).get("bar"))
)
.isEqualTo("bar val");
}

@Test
@SuppressWarnings("unchecked")
public void itHandlesMultiLayerAliasedAndNullDeferred() {
String child2Alias = "double_child";
JinjavaInterpreter child = getChildInterpreter(interpreter, CONTEXT_VAR);
JinjavaInterpreter child2 = getChildInterpreter(child, child2Alias);

child2.render("{% set foo = 'foo val' %}");
child.render("{% set bar = 'bar val' %}");
child2.render("{% set foo_d = deferred %}");

getAliasedStrategy(child2Alias, child).integrateChild(child2);
getAliasedStrategy(CONTEXT_VAR, interpreter).integrateChild(child);

assertThat(interpreter.getContext().get(CONTEXT_VAR)).isInstanceOf(PyMap.class);
assertThat(
((Map<String, Object>) interpreter.getContext().get(CONTEXT_VAR)).get(child2Alias)
(Map<String, Object>) (
(DeferredValue) result.getContext().get(CONTEXT_VAR)
).getOriginalValue()
).get(child2Alias)
)
.isInstanceOf(DeferredValue.class);
assertThat(
(
(
(Map<String, Object>) (
(DeferredValue) (
(Map<String, Object>) interpreter.getContext().get(CONTEXT_VAR)
(
(Map<String, Object>) (
(DeferredValue) result.getContext().get(CONTEXT_VAR)
).getOriginalValue()
)
).get(child2Alias)
).getOriginalValue()
).get("foo")
Expand All @@ -233,7 +200,11 @@ public void itHandlesMultiLayerAliasedAndNullDeferred() {
.isEqualTo("foo val");

assertThat(
(((Map<String, Object>) interpreter.getContext().get(CONTEXT_VAR)).get("bar"))
(
(Map<String, Object>) (
(DeferredValue) result.getContext().get(CONTEXT_VAR)
).getOriginalValue()
).get("bar")
)
.isEqualTo("bar val");
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/tags/eager/importtag/layer-one.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% set bar = 'bar val' %}
{% import 'layer-two.jinja' as double_child %}
2 changes: 2 additions & 0 deletions src/test/resources/tags/eager/importtag/layer-two.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% set foo = 'foo val' %}
{% set foo_d = deferred %}

0 comments on commit dfcd35b

Please sign in to comment.