Skip to content

Commit 9664ae2

Browse files
hs-lsongclaude
andcommitted
test: Add test for chained extends with undefined parent path
Verifies that when a grandchild template extends a child template (resolved path), and the child extends a parent (undefined path), the child's extends and block tags are correctly preserved. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 323ab52 commit 9664ae2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/test/java/com/hubspot/jinjava/mode/PreserveUndefinedExecutionModeTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,26 @@ public void itPreservesUndefinedVariablesInExtendedTemplate() {
280280
assertThat(output).isEqualTo("Title: {{ title }} - {{ message }}");
281281
}
282282

283+
@Test
284+
public void itPreservesNestedExtendsWhenParentPathIsUndefined() {
285+
// Chained inheritance: grandchild extends child (resolved), child extends parent (undefined)
286+
jinjava.setResourceLocator((fullName, encoding, interpreter) -> {
287+
if (fullName.equals("child.html")) {
288+
return "{% extends parentPath %}{% block content %}child: {{ childVar }}{% endblock %}";
289+
}
290+
return "";
291+
});
292+
293+
String template =
294+
"{% extends 'child.html' %}{% block content %}grandchild content{% endblock %}";
295+
String output = render(template);
296+
// The child template's extends and block should be preserved since parentPath is undefined
297+
assertThat(output)
298+
.isEqualTo(
299+
"{% extends parentPath %}{% block content %}child: {{ childVar }}{% endblock %}"
300+
);
301+
}
302+
283303
@Test
284304
public void itPreservesComments() {
285305
String output = render("{# this is a comment #}");

0 commit comments

Comments
 (0)