Skip to content

Commit 5877c7e

Browse files
committed
Add tests for malformed nested marker diagnostics
Cover the HasClosure() checks on nested markers in FindMarkerPairs: malformed nested start/end markers emit specific diagnostics without affecting depth tracking. https://claude.ai/code/session_01J3g8NnEwGYyJWXD1bqtTii
1 parent a244240 commit 5877c7e

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

internal/archetype/gensection/engine_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,42 @@ func TestEngine_Fix_BalancedNestedMarkers(t *testing.T) {
173173
assert.NotContains(t, result, "old outer")
174174
}
175175

176+
func TestEngine_Check_MalformedNestedStartMarker(t *testing.T) {
177+
// A malformed nested start marker (missing ?>) should emit a
178+
// diagnostic without affecting depth tracking.
179+
src := "<?mock\nkey: a\n?>\n<?mock\nkey: b\n<?/mock?>\n"
180+
f := newTestFile(t, "test.md", src)
181+
d := &mockDirective{content: ""}
182+
e := NewEngine(d)
183+
diags := e.Check(f)
184+
found := false
185+
for _, d := range diags {
186+
if strings.Contains(d.Message, "<?mock is missing closing ?>") {
187+
found = true
188+
}
189+
}
190+
assert.True(t, found,
191+
"expected malformed nested start marker diagnostic, got %v", diags)
192+
}
193+
194+
func TestEngine_Check_MalformedNestedEndMarker(t *testing.T) {
195+
// A malformed nested end marker (missing ?>) inside balanced
196+
// nesting should emit a diagnostic without decrementing depth.
197+
src := "<?mock\nkey: a\n?>\n<?mock\nkey: b\n?>\ninner\n<?/mock\n<?/mock?>\n<?/mock?>\n"
198+
f := newTestFile(t, "test.md", src)
199+
d := &mockDirective{content: ""}
200+
e := NewEngine(d)
201+
diags := e.Check(f)
202+
found := false
203+
for _, d := range diags {
204+
if strings.Contains(d.Message, "<?/mock is missing closing ?>") {
205+
found = true
206+
}
207+
}
208+
assert.True(t, found,
209+
"expected malformed nested end marker diagnostic, got %v", diags)
210+
}
211+
176212
func TestEngine_Check_InvalidYAML(t *testing.T) {
177213
src := "<?mock\n: invalid : yaml ::: [\n?>\n<?/mock?>\n"
178214
f := newTestFile(t, "test.md", src)

0 commit comments

Comments
 (0)