carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package docsite
2
3import "testing"
4
5const testCorpus = "testdata/corpus"
6
7func TestLoadReadsNavAndPages(t *testing.T) {
8 site, err := Load(testCorpus)
9 if err != nil {
10 t.Fatalf("load: %v", err)
11 }
12 if site.Index == nil || site.Index.Title != "Documentation" {
13 t.Fatalf("index not loaded: %+v", site.Index)
14 }
15 if len(site.Sections) != 2 {
16 t.Fatalf("got %d sections, want 2", len(site.Sections))
17 }
18 if got := site.Sections[1].Pages[0].Slug; got != "reference/cli" {
19 t.Errorf("nested slug = %q, want reference/cli", got)
20 }
21 if got := len(site.Pages()); got != 3 {
22 t.Errorf("Pages() = %d, want 3 (index + two)", got)
23 }
24}
25
26func TestParsePageFindsHeadingsLinksAndFences(t *testing.T) {
27 site, err := Load(testCorpus)
28 if err != nil {
29 t.Fatalf("load: %v", err)
30 }
31 p := site.BySlug["getting-started"]
32 if p == nil {
33 t.Fatal("no getting-started page")
34 }
35 if len(p.Headings) != 3 {
36 t.Fatalf("got %d headings, want 3", len(p.Headings))
37 }
38 if p.Headings[1].Anchor != "install-the-cli" {
39 t.Errorf("anchor = %q, want install-the-cli", p.Headings[1].Anchor)
40 }
41 if len(p.Fences) != 1 || p.Fences[0].Lang != "sh" {
42 t.Fatalf("fences = %+v, want one sh fence", p.Fences)
43 }
44 if len(p.Links) != 1 || p.Links[0].Target != "reference/cli" {
45 t.Fatalf("links = %+v, want one to reference/cli", p.Links)
46 }
47}
48
49func TestIndexLinkResolvesToIndexSlug(t *testing.T) {
50 l := parseDocsHref("/docs")
51 if l.Target != "index" {
52 t.Errorf("parseDocsHref(\"/docs\") target = %q, want index", l.Target)
53 }
54 l = parseDocsHref("/docs/reference/cli#carlos-ship")
55 if l.Target != "reference/cli" || l.Fragment != "carlos-ship" {
56 t.Errorf("got %+v, want reference/cli #carlos-ship", l)
57 }
58}
59
60func TestMarkdownFilesWalksNested(t *testing.T) {
61 files, err := MarkdownFiles(testCorpus)
62 if err != nil {
63 t.Fatalf("walk: %v", err)
64 }
65 want := map[string]bool{"index": true, "getting-started": true, "reference/cli": true}
66 if len(files) != len(want) {
67 t.Fatalf("got %v, want %d files", files, len(want))
68 }
69 for _, f := range files {
70 if !want[f] {
71 t.Errorf("unexpected file %q", f)
72 }
73 }
74}
75