Skip to content

Commit 457ab73

Browse files
committed
test(index): fix review-round-2 gaps in locate helper tests
- Use require.True (not assert.True) before b[off] indexing in TestLinkCloseOffset: assert continues on failure, causing a panic on the immediately following b[-1] index if the offset is -1. - Add third duplicate heading to TestHeadingInfo to exercise the disambiguation counter beyond c==1 (verifies "alpha-2" suffix). - Add bare-dash case to TestListItemValue to document that " -" does not match piListItemRE (contrast with frontMatterListItem). - Remove section-separator comment (CLAUDE.md: no "what" comments). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017DMVDTLs2U9kcVMEyLNZgK
1 parent 3eae156 commit 457ab73

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

internal/index/locate_test.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,6 @@ func TestEnclosingListKey_FindsParentKey(t *testing.T) {
269269
assert.Equal(t, "inputs", got)
270270
}
271271

272-
// --- Dedicated tests for unexported helpers in locate.go ---
273-
274272
// parseDoc parses body-only markdown (no front matter) and returns root + source.
275273
func parseDoc(src string) (goldast.Node, []byte) {
276274
b := []byte(src)
@@ -334,29 +332,34 @@ func nthHeading(root goldast.Node, n int) *goldast.Heading {
334332

335333
func TestHeadingInfo(t *testing.T) {
336334
t.Parallel()
337-
src := "# Alpha\n\n# Alpha\n\n## Beta\n"
335+
src := "# Alpha\n\n# Alpha\n\n# Alpha\n\n## Beta\n"
338336
root, b := parseDoc(src)
339337

340338
h1 := nthHeading(root, 1)
341339
h2 := nthHeading(root, 2)
342340
h3 := nthHeading(root, 3)
341+
h4 := nthHeading(root, 4)
343342
require.NotNil(t, h1)
344343
require.NotNil(t, h2)
345344
require.NotNil(t, h3)
345+
require.NotNil(t, h4)
346346

347347
anchor, level, name := headingInfo(h1, b, root)
348348
assert.Equal(t, "alpha", anchor)
349349
assert.Equal(t, 1, level)
350350
assert.Equal(t, "Alpha", name)
351351

352-
// Duplicate slug disambiguated with suffix.
352+
// Second and third occurrences get sequential suffixes.
353353
anchor2, _, _ := headingInfo(h2, b, root)
354354
assert.Equal(t, "alpha-1", anchor2)
355355

356-
anchor3, level3, name3 := headingInfo(h3, b, root)
357-
assert.Equal(t, "beta", anchor3)
358-
assert.Equal(t, 2, level3)
359-
assert.Equal(t, "Beta", name3)
356+
anchor3, _, _ := headingInfo(h3, b, root)
357+
assert.Equal(t, "alpha-2", anchor3)
358+
359+
anchor4, level4, name4 := headingInfo(h4, b, root)
360+
assert.Equal(t, "beta", anchor4)
361+
assert.Equal(t, 2, level4)
362+
assert.Equal(t, "Beta", name4)
360363
}
361364

362365
func TestLocateInAST(t *testing.T) {
@@ -418,7 +421,7 @@ func TestLinkCloseOffset(t *testing.T) {
418421
return goldast.WalkContinue, nil
419422
})
420423
off := linkCloseOffset(b, shortcut, shortcutAfter)
421-
assert.True(t, off >= 0, "shortcut ref close offset must be ≥ 0")
424+
require.True(t, off >= 0, "shortcut ref close offset must be ≥ 0")
422425
assert.Equal(t, byte(']'), b[off], "shortcut ref must close at ']'")
423426

424427
// Full reference [text][label]: close must land on the ']' of the label part.
@@ -437,7 +440,7 @@ func TestLinkCloseOffset(t *testing.T) {
437440
return goldast.WalkContinue, nil
438441
})
439442
off2 := linkCloseOffset(b2, full, fullAfter)
440-
assert.True(t, off2 >= 0, "full ref close offset must be ≥ 0")
443+
require.True(t, off2 >= 0, "full ref close offset must be ≥ 0")
441444
assert.Equal(t, byte(']'), b2[off2], "full ref must close at ']' of label part")
442445
// The close must be past the text-closing ']' (i.e., farther into the source).
443446
assert.Greater(t, off2, fullAfter, "full ref close must be past the text bracket")
@@ -535,6 +538,12 @@ func TestListItemValue(t *testing.T) {
535538

536539
_, ok = listItemValue("key: value")
537540
assert.False(t, ok)
541+
542+
// Bare dash without a value does not match (piListItemRE requires
543+
// whitespace after the dash); contrast with frontMatterListItem which
544+
// accepts bare "-".
545+
_, ok = listItemValue(" -")
546+
assert.False(t, ok)
538547
}
539548

540549
func TestHeadingOnLine(t *testing.T) {

0 commit comments

Comments
 (0)