public void leaveScope() { Context parent = context.getParent(); scopeDepth--; if (parent != null) { parent.addDependencies(context.getDependencies()); context = parent; } }
@Test public void itHasIncludesReferenceInContext() throws Exception { RenderResult renderResult = jinjava.renderForResult(Resources.toString(Resources.getResource("tags/includetag/include-tag-dependencies.html"), StandardCharsets.UTF_8), new HashMap<String, Object>()); SetMultimap<String, String> dependencies = renderResult.getContext().getDependencies(); assertThat(dependencies.size()).isEqualTo(2); assertThat(dependencies.get("coded_files")).isNotEmpty(); assertThat(dependencies.get("coded_files").contains("{% include \"tags/includetag/hello.html\" %}")); assertThat(dependencies.get("coded_files").contains("{% include \"tags/includetag/cat.html\" %}")); }
@Test public void itHasIncludesReferenceInContext() throws Exception { RenderResult renderResult = jinjava.renderForResult(Resources.toString(Resources.getResource("tags/includetag/include-tag-dependencies.html"), StandardCharsets.UTF_8), new HashMap<String, Object>()); SetMultimap<String, String> dependencies = renderResult.getContext().getDependencies(); assertThat(dependencies.size()).isEqualTo(2); assertThat(dependencies.get("coded_files")).isNotEmpty(); assertThat(dependencies.get("coded_files").contains("{% include \"tags/includetag/hello.html\" %}")); assertThat(dependencies.get("coded_files").contains("{% include \"tags/includetag/cat.html\" %}")); }
@Test public void itHasExtendsReferenceInContext() throws Exception { RenderResult renderResult = jinjava.renderForResult(locator.fixture("super-child.html"), new HashMap<String, Object>()); SetMultimap<String, String> dependencies = renderResult.getContext().getDependencies(); assertThat(dependencies.size()).isEqualTo(1); assertThat(dependencies.get("coded_files")).isNotEmpty(); assertThat(dependencies.get("coded_files").contains("super-base.html")); }
@Test public void itHasExtendsReferenceInContext() throws Exception { RenderResult renderResult = jinjava.renderForResult(locator.fixture("super-child.html"), new HashMap<String, Object>()); SetMultimap<String, String> dependencies = renderResult.getContext().getDependencies(); assertThat(dependencies.size()).isEqualTo(1); assertThat(dependencies.get("coded_files")).isNotEmpty(); assertThat(dependencies.get("coded_files").contains("super-base.html")); }
@Test public void bubbleUpDependenciesFromLowerScope() { String dependencyType = "foo"; String dependencyIdentifier = "123"; interpreter.enterScope(); interpreter.getContext().addDependency(dependencyType, dependencyIdentifier); assertThat(interpreter.getContext().getDependencies().get(dependencyType)).contains(dependencyIdentifier); interpreter.leaveScope(); assertThat(interpreter.getContext().getDependencies().get(dependencyType)).contains(dependencyIdentifier); }
@Test public void bubbleUpDependenciesFromLowerScope() { String dependencyType = "foo"; String dependencyIdentifier = "123"; interpreter.enterScope(); interpreter.getContext().addDependency(dependencyType, dependencyIdentifier); assertThat(interpreter.getContext().getDependencies().get(dependencyType)).contains(dependencyIdentifier); interpreter.leaveScope(); assertThat(interpreter.getContext().getDependencies().get(dependencyType)).contains(dependencyIdentifier); }