Skip to content

Commit

Permalink
#506: Add unit test (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebussieres authored May 21, 2020
1 parent 7b98a75 commit 0e829c0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.mitchellbosecke.pebble;

import static org.junit.jupiter.api.Assertions.assertEquals;

import com.mitchellbosecke.pebble.error.PebbleException;
import com.mitchellbosecke.pebble.template.PebbleTemplate;

import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

/**
* This class tests if includes with parameters work.
Expand Down Expand Up @@ -59,4 +57,23 @@ void testIncludeWithParametersIsolated() throws PebbleException, IOException {

}

@Test
void testIncludeWithParameterObject() throws PebbleException, IOException {

PebbleEngine pebble = new PebbleEngine.Builder().strictVariables(false).build();
PebbleTemplate template = pebble
.getTemplate("templates/template.includeWithParameterObject1.peb");
Map<String, Object> context = new HashMap<>();
context.put("object", new TestObject());

Writer writer = new StringWriter();
template.evaluate(writer, context);

assertEquals("Hello title", writer.toString());
}

public static class TestObject {

public String title = "title";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{# used by IncludeWithParameterTest.testIncludeWithParameterObject #}
{% include './template.includeWithParameterObject2.peb' with { 'sub' : object } %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello {{ sub.title }}

0 comments on commit 0e829c0

Please sign in to comment.