62 lines
1.1 KiB
Go
62 lines
1.1 KiB
Go
package documents
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestParseFile verifies ParseFile loads front matter and markdown sections.
|
|
func TestParseFile(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
repo := t.TempDir()
|
|
path := filepath.Join(repo, "docs", "ai")
|
|
if err := os.MkdirAll(path, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
file := filepath.Join(path, "repo-memory.md")
|
|
content := strings.TrimSpace(`
|
|
---
|
|
title: Zeus Repo Memory
|
|
repo: zeus
|
|
---
|
|
|
|
# Repo Memory
|
|
|
|
Intro text.
|
|
|
|
## Module Map
|
|
|
|
- app/app
|
|
- gateway
|
|
|
|
## Danger Zones
|
|
|
|
- shared libs
|
|
`)
|
|
if err := os.WriteFile(file, []byte(content), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
doc, err := ParseFile(repo, file)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if got, want := doc.Title, "Zeus Repo Memory"; got != want {
|
|
t.Fatalf("title = %q, want %q", got, want)
|
|
}
|
|
if got, want := doc.DocPath, "docs/ai/repo-memory.md"; got != want {
|
|
t.Fatalf("doc path = %q, want %q", got, want)
|
|
}
|
|
if len(doc.Sections) != 3 {
|
|
t.Fatalf("sections = %d, want 3", len(doc.Sections))
|
|
}
|
|
if got, want := doc.Sections[1].Heading, "Module Map"; got != want {
|
|
t.Fatalf("section heading = %q, want %q", got, want)
|
|
}
|
|
}
|