Skip to content

Commit e43312a

Browse files
committed
Fix lint: break long test lines and add frontmatter coverage
Wrap string literals in include tests to stay under 120-char limit. Add TestFix_RecursiveExpansionWithFrontmatter to cover the frontmatter-reconstruction path in expandNestedIncludes. https://claude.ai/code/session_01J3g8NnEwGYyJWXD1bqtTii
1 parent edbb164 commit e43312a

1 file changed

Lines changed: 55 additions & 12 deletions

File tree

internal/rules/include/rule_test.go

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,15 @@ func TestCheck_MaxDepthExceeded(t *testing.T) {
540540

541541
func TestCheck_NoCycle(t *testing.T) {
542542
// A includes B, B includes C (no cycle). No errors expected.
543+
bContent := "# B\n\n<?include\nfile: c.md\n?>\n" +
544+
"Final content\n<?/include?>\n"
543545
fsys := fstest.MapFS{
544-
"b.md": {Data: []byte("# B\n\n<?include\nfile: c.md\n?>\nFinal content\n<?/include?>\n")},
546+
"b.md": {Data: []byte(bContent)},
545547
"c.md": {Data: []byte("Final content\n")},
546548
}
547-
src := "# A\n\n<?include\nfile: b.md\n?>\n# B\n\n<?include\nfile: c.md\n?>\nFinal content\n<?/include?>\n<?/include?>\n"
549+
src := "# A\n\n<?include\nfile: b.md\n?>\n" +
550+
"# B\n\n<?include\nfile: c.md\n?>\n" +
551+
"Final content\n<?/include?>\n<?/include?>\n"
548552
f := newTestFile(t, "a.md", src, fsys)
549553
r := &Rule{}
550554
diags := r.Check(f)
@@ -554,25 +558,34 @@ func TestCheck_NoCycle(t *testing.T) {
554558
func TestFix_NestedInclude(t *testing.T) {
555559
// A includes B, B includes C. Fix should produce B's content
556560
// (which contains C's include markers) as-is.
561+
bContent := "# B\n\n<?include\nfile: c.md\n?>\n" +
562+
"Final content\n<?/include?>\n"
557563
fsys := fstest.MapFS{
558-
"b.md": {Data: []byte("# B\n\n<?include\nfile: c.md\n?>\nFinal content\n<?/include?>\n")},
564+
"b.md": {Data: []byte(bContent)},
559565
"c.md": {Data: []byte("Final content\n")},
560566
}
561567
src := "# A\n\n<?include\nfile: b.md\n?>\nold\n<?/include?>\n"
562568
f := newTestFile(t, "a.md", src, fsys)
563569
r := &Rule{}
564570
got := string(r.Fix(f))
565-
want := "# A\n\n<?include\nfile: b.md\n?>\n# B\n\n<?include\nfile: c.md\n?>\nFinal content\n<?/include?>\n<?/include?>\n"
566-
assert.Equal(t, want, got, "Fix output mismatch\ngot:\n%s\nwant:\n%s", got, want)
571+
want := "# A\n\n<?include\nfile: b.md\n?>\n" +
572+
"# B\n\n<?include\nfile: c.md\n?>\n" +
573+
"Final content\n<?/include?>\n<?/include?>\n"
574+
assert.Equal(t, want, got,
575+
"Fix output mismatch\ngot:\n%s\nwant:\n%s", got, want)
567576
}
568577

569578
func TestCheck_NestedIncludeUpToDate(t *testing.T) {
570579
// A includes B, B itself contains a catalog section.
571580
// The expanded content in A should be accepted without errors.
581+
bContent := "# B\n\n<?catalog\nglob: \"*.md\"\n?>\n" +
582+
"- item\n<?/catalog?>\n"
572583
fsys := fstest.MapFS{
573-
"b.md": {Data: []byte("# B\n\n<?catalog\nglob: \"*.md\"\n?>\n- item\n<?/catalog?>\n")},
584+
"b.md": {Data: []byte(bContent)},
574585
}
575-
src := "# A\n\n<?include\nfile: b.md\n?>\n# B\n\n<?catalog\nglob: \"*.md\"\n?>\n- item\n<?/catalog?>\n<?/include?>\n"
586+
src := "# A\n\n<?include\nfile: b.md\n?>\n" +
587+
"# B\n\n<?catalog\nglob: \"*.md\"\n?>\n" +
588+
"- item\n<?/catalog?>\n<?/include?>\n"
576589
f := newTestFile(t, "a.md", src, fsys)
577590
r := &Rule{}
578591
diags := r.Check(f)
@@ -587,32 +600,62 @@ func TestFix_RecursiveExpansion(t *testing.T) {
587600
// A includes B, B includes C. B.md on disk has stale content for C.
588601
// Fix A should recursively expand B's includes to produce correct
589602
// content in a single pass.
603+
bContent := "# B\n\n<?include\nfile: c.md\n?>\n" +
604+
"stale\n<?/include?>\n"
590605
fsys := fstest.MapFS{
591-
"b.md": {Data: []byte("# B\n\n<?include\nfile: c.md\n?>\nstale\n<?/include?>\n")},
606+
"b.md": {Data: []byte(bContent)},
592607
"c.md": {Data: []byte("Fresh from C\n")},
593608
}
594609
src := "# A\n\n<?include\nfile: b.md\n?>\nold\n<?/include?>\n"
595610
f := newTestFile(t, "a.md", src, fsys)
596611
r := &Rule{}
597612
got := string(r.Fix(f))
598-
want := "# A\n\n<?include\nfile: b.md\n?>\n# B\n\n<?include\nfile: c.md\n?>\nFresh from C\n<?/include?>\n<?/include?>\n"
599-
assert.Equal(t, want, got, "Fix output mismatch\ngot:\n%s\nwant:\n%s", got, want)
613+
want := "# A\n\n<?include\nfile: b.md\n?>\n" +
614+
"# B\n\n<?include\nfile: c.md\n?>\n" +
615+
"Fresh from C\n<?/include?>\n<?/include?>\n"
616+
assert.Equal(t, want, got,
617+
"Fix output mismatch\ngot:\n%s\nwant:\n%s", got, want)
600618
}
601619

602620
func TestCheck_RecursiveExpansion(t *testing.T) {
603621
// A includes B, B includes C. B.md on disk has stale C content, but
604622
// A has the correct recursively-expanded content. Check should pass.
623+
bContent := "# B\n\n<?include\nfile: c.md\n?>\n" +
624+
"stale\n<?/include?>\n"
605625
fsys := fstest.MapFS{
606-
"b.md": {Data: []byte("# B\n\n<?include\nfile: c.md\n?>\nstale\n<?/include?>\n")},
626+
"b.md": {Data: []byte(bContent)},
607627
"c.md": {Data: []byte("Fresh from C\n")},
608628
}
609-
src := "# A\n\n<?include\nfile: b.md\n?>\n# B\n\n<?include\nfile: c.md\n?>\nFresh from C\n<?/include?>\n<?/include?>\n"
629+
src := "# A\n\n<?include\nfile: b.md\n?>\n" +
630+
"# B\n\n<?include\nfile: c.md\n?>\n" +
631+
"Fresh from C\n<?/include?>\n<?/include?>\n"
610632
f := newTestFile(t, "a.md", src, fsys)
611633
r := &Rule{}
612634
diags := r.Check(f)
613635
expectDiags(t, diags, 0)
614636
}
615637

638+
func TestFix_RecursiveExpansionWithFrontmatter(t *testing.T) {
639+
// B.md has frontmatter and a nested include. Recursive expansion
640+
// should preserve frontmatter when reconstructing B's content.
641+
bContent := "---\ntitle: B\n---\n# B\n\n<?include\n" +
642+
"file: c.md\n?>\nstale\n<?/include?>\n"
643+
fsys := fstest.MapFS{
644+
"b.md": {Data: []byte(bContent)},
645+
"c.md": {Data: []byte("Fresh from C\n")},
646+
}
647+
src := "# A\n\n<?include\nfile: b.md\n?>\nold\n<?/include?>\n"
648+
f := newTestFile(t, "a.md", src, fsys)
649+
r := &Rule{}
650+
got := string(r.Fix(f))
651+
// Frontmatter is stripped by default, so only body appears.
652+
want := "# A\n\n<?include\nfile: b.md\n?>\n" +
653+
"# B\n\n<?include\nfile: c.md\n?>\n" +
654+
"Fresh from C\n<?/include?>\n<?/include?>\n"
655+
assert.Equal(t, want, got,
656+
"Fix output mismatch\ngot:\n%s\nwant:\n%s", got, want)
657+
}
658+
616659
// =====================================================================
617660
// No FS
618661
// =====================================================================

0 commit comments

Comments
 (0)