Skip to content

Commit 3c852f3

Browse files
committed
Replace CallStack.size() with peek() for path stack integrity test
Instead of adding a new public size() method to CallStack, use the existing public peek() method to verify stack integrity. This achieves the same test coverage (ensuring push/pop operations are balanced) without expanding the public API surface. The test now verifies that the top path on the stack remains the same before and after rendering, which is equivalent to checking stack size but uses only existing public methods.
1 parent a800f68 commit 3c852f3

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/main/java/com/hubspot/jinjava/interpret/CallStack.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.hubspot.jinjava.interpret;
22

3-
import com.google.common.annotations.VisibleForTesting;
43
import java.util.Optional;
54
import java.util.Stack;
65

@@ -112,12 +111,6 @@ public boolean isEmpty() {
112111
return stack.empty() && (parent == null || parent.isEmpty());
113112
}
114113

115-
@VisibleForTesting
116-
public int size() {
117-
int localSize = stack.size();
118-
return parent == null ? localSize : localSize + parent.size();
119-
}
120-
121114
private void pushToStack(String path, int lineNumber, int startPosition) {
122115
if (isEmpty()) {
123116
topLineNumber = lineNumber;

src/test/java/com/hubspot/jinjava/lib/tag/FromTagTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,15 @@ public Optional<LocationResolver> getLocationResolver() {
204204
);
205205

206206
interpreter.getContext().getCurrentPathStack().push("root.jinja", 1, 0);
207-
int initialStackSize = interpreter.getContext().getCurrentPathStack().size();
207+
Optional<String> initialTopPath = interpreter
208+
.getContext()
209+
.getCurrentPathStack()
210+
.peek();
208211

209212
interpreter.render(interpreter.getResource("root.jinja"));
210213

211-
assertThat(interpreter.getContext().getCurrentPathStack().size())
212-
.isEqualTo(initialStackSize);
214+
assertThat(interpreter.getContext().getCurrentPathStack().peek())
215+
.isEqualTo(initialTopPath);
213216
assertThat(interpreter.getErrors()).isEmpty();
214217
}
215218

0 commit comments

Comments
 (0)