|
1 | 1 | package com.hubspot.jinjava.tree; |
2 | 2 |
|
| 3 | +import static com.hubspot.jinjava.lib.expression.DefaultExpressionStrategy.ECHO_UNDEFINED; |
3 | 4 | import static org.assertj.core.api.Assertions.assertThat; |
4 | 5 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
5 | 6 |
|
6 | 7 | import com.google.common.io.Resources; |
7 | 8 | import com.hubspot.jinjava.BaseInterpretingTest; |
8 | 9 | import com.hubspot.jinjava.Jinjava; |
9 | 10 | import com.hubspot.jinjava.JinjavaConfig; |
| 11 | +import com.hubspot.jinjava.features.FeatureConfig; |
| 12 | +import com.hubspot.jinjava.features.FeatureStrategies; |
10 | 13 | import com.hubspot.jinjava.interpret.Context; |
11 | 14 | import com.hubspot.jinjava.interpret.JinjavaInterpreter; |
12 | 15 | import com.hubspot.jinjava.interpret.UnknownTokenException; |
@@ -129,6 +132,29 @@ public void itRendersStringRange() throws Exception { |
129 | 132 | assertThat(node.render(interpreter).toString()).isEqualTo("345"); |
130 | 133 | } |
131 | 134 |
|
| 135 | + @Test |
| 136 | + public void itRenderEchoUndefined() { |
| 137 | + final JinjavaConfig config = JinjavaConfig |
| 138 | + .newBuilder() |
| 139 | + .withFeatureConfig( |
| 140 | + FeatureConfig.newBuilder().add(ECHO_UNDEFINED, FeatureStrategies.ACTIVE).build() |
| 141 | + ) |
| 142 | + .build(); |
| 143 | + final JinjavaInterpreter jinjavaInterpreter = new Jinjava(config).newInterpreter(); |
| 144 | + jinjavaInterpreter.getContext().put("subject", "this"); |
| 145 | + |
| 146 | + String template = |
| 147 | + "{{ subject | capitalize() }} expression {{ testing.template('hello_world') }} " + |
| 148 | + "has a {{ unknown | lower() }} " + |
| 149 | + "token but {{ unknown | default(\"replaced\") }} and empty {{ '' }}"; |
| 150 | + Node node = new TreeParser(jinjavaInterpreter, template).buildTree(); |
| 151 | + assertThat(jinjavaInterpreter.render(node)) |
| 152 | + .isEqualTo( |
| 153 | + "This expression {{ testing.template('hello_world') }} " + |
| 154 | + "has a {{ unknown | lower() }} token but replaced and empty " |
| 155 | + ); |
| 156 | + } |
| 157 | + |
132 | 158 | @Test |
133 | 159 | public void itFailsOnUnknownTokensVariables() throws Exception { |
134 | 160 | final JinjavaConfig config = JinjavaConfig |
|
0 commit comments