/** * Creates a new interpreter instance using the global context and global config * * @return a new interpreter instance */ public JinjavaInterpreter newInterpreter() { return new JinjavaInterpreter(this, this.getGlobalContext(), this.getGlobalConfig()); }
@Test public void itAvoidsNestedImportCycle() throws IOException { Jinjava jinjava = new Jinjava(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); interpreter.render(Resources.toString(Resources.getResource("tags/importtag/a-imports-b.jinja"), StandardCharsets.UTF_8)); assertThat(context.get("a")).isEqualTo("foo"); assertThat(context.get("b")).isEqualTo("bar"); assertThat(interpreter.getErrorsCopy().get(0).getMessage()).contains("Rendering cycle detected:", "b-imports-a.jinja"); }
@Test public void itAvoidsSimpleImportCycle() throws IOException { Jinjava jinjava = new Jinjava(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); interpreter.render(Resources.toString(Resources.getResource("tags/importtag/imports-self.jinja"), StandardCharsets.UTF_8)); assertThat(context.get("c")).isEqualTo("hello"); assertThat(interpreter.getErrorsCopy().get(0).getMessage()).contains("Rendering cycle detected:", "imports-self.jinja"); }
@Test public void itAvoidsNestedImportCycle() throws IOException { Jinjava jinjava = new Jinjava(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); interpreter.render(Resources.toString(Resources.getResource("tags/importtag/a-imports-b.jinja"), StandardCharsets.UTF_8)); assertThat(context.get("a")).isEqualTo("foo"); assertThat(context.get("b")).isEqualTo("bar"); assertThat(interpreter.getErrorsCopy().get(0).getMessage()).contains("Rendering cycle detected:", "b-imports-a.jinja"); }
@Test public void itAvoidsSimpleImportCycle() throws IOException { Jinjava jinjava = new Jinjava(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); interpreter.render(Resources.toString(Resources.getResource("tags/importtag/imports-self.jinja"), StandardCharsets.UTF_8)); assertThat(context.get("c")).isEqualTo("hello"); assertThat(interpreter.getErrorsCopy().get(0).getMessage()).contains("Rendering cycle detected:", "imports-self.jinja"); }
@Before public void setup() { Jinjava jinjava = new Jinjava(); jinjava.setResourceLocator(new ResourceLocator() { @Override public String getString(String fullName, Charset encoding, JinjavaInterpreter interpreter) throws IOException { return Resources.toString( Resources.getResource(String.format("tags/macrotag/%s", fullName)), StandardCharsets.UTF_8); } }); context = new Context(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); JinjavaInterpreter.pushCurrent(interpreter); context.put("padding", 42); }
@Before public void setup() { Jinjava jinjava = new Jinjava(); jinjava.setResourceLocator(new ResourceLocator() { @Override public String getString(String fullName, Charset encoding, JinjavaInterpreter interpreter) throws IOException { return Resources.toString( Resources.getResource(String.format("tags/macrotag/%s", fullName)), StandardCharsets.UTF_8); } }); context = new Context(); interpreter = new JinjavaInterpreter(jinjava, context, jinjava.getGlobalConfig()); JinjavaInterpreter.pushCurrent(interpreter); context.put("padding", 42); }