Skip to content

Commit 4ac6fee

Browse files
committed
schema: cover deeper-heading skip in countSameLevelMatches
Adds TestCountSameLevelMatches_SkipsDeeperHeadings to exercise the level filter inside countSameLevelMatches via the trailing max-exceeded path. A `### Detail` between two `## B`s must not count toward B's max=2 so only the third `## B` is flagged. https://claude.ai/code/session_012GGH62fZUzLuzP8T4ocGkJ
1 parent 76a790e commit 4ac6fee

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

internal/schema/plan156_coverage_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package schema
22

33
import (
44
"strconv"
5+
"strings"
56
"testing"
67

78
"github.com/stretchr/testify/assert"
@@ -289,6 +290,38 @@ func TestScopeMatchesHeading_NilScope(t *testing.T) {
289290
assert.False(t, scopeMatchesHeading(Scope{}, DocHeading{Text: "x"}, nil))
290291
}
291292

293+
// TestCountSameLevelMatches_SkipsDeeperHeadings covers the
294+
// level filter inside countSameLevelMatches via the trailing
295+
// max-exceeded path: a deeper heading between matching same-
296+
// level occurrences must not count toward the scope's max.
297+
func TestCountSameLevelMatches_SkipsDeeperHeadings(t *testing.T) {
298+
raw := map[string]any{
299+
"sections": []any{
300+
map[string]any{"heading": "A"},
301+
map[string]any{"heading": map[string]any{
302+
"regex": "B",
303+
"repeat": map[string]any{"max": 2},
304+
}},
305+
},
306+
}
307+
sch, err := ParseInline(raw, "kind x")
308+
require.NoError(t, err)
309+
// Doc: B (out of order), nested ### Detail, A, B, B.
310+
// Three Bs at level 2, with a deeper Detail mixed in. Only
311+
// the third B (4th match attempt) should be flagged.
312+
doc := newDocFile(t, "doc.md",
313+
"# T\n\n## B\n\n### Detail\n\nx\n\n## A\n\ny\n\n## B\n\nz\n\n## B\n\nw\n")
314+
diags := Validate(doc, sch, nil, false, makeDiagForTest)
315+
var exceeded int
316+
for _, d := range diags {
317+
if strings.Contains(d.Message, "exceeds scope") {
318+
exceeded++
319+
}
320+
}
321+
assert.Equal(t, 1, exceeded,
322+
"deeper Detail heading must not count toward B's max")
323+
}
324+
292325
// TestScopeRunIndices_NilMatcherReturnsNil covers the early
293326
// return for a nil-matcher scope (preamble-shaped scope routed
294327
// through the helper directly).

0 commit comments

Comments
 (0)