~adnano/kiln

ref: 7ac653c62085191327b594a7ae1617cd561c2d32 kiln/frontmatter_test.go -rw-r--r-- 1.4 KiB
7ac653c6Adnan Maolood docs: Tweak wording 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main

import (
	"testing"
)

func TestExtractFrontmatter(t *testing.T) {
	tests := []struct {
		Raw         string
		Frontmatter string
		Content     string
	}{
		{
			Raw:         "",
			Frontmatter: "",
			Content:     "",
		},
		{
			Raw:         "---\na: b\nc: d\n---",
			Frontmatter: "\na: b\nc: d",
			Content:     "",
		},
		{
			Raw:         "---\na: b\nc: d\n---\nHello, world!",
			Frontmatter: "\na: b\nc: d",
			Content:     "\nHello, world!",
		},
		{
			Raw:         "# Hello, world!",
			Frontmatter: "",
			Content:     "# Hello, world!",
		},
		{
			Raw:         "---\ne: f\ng: h",
			Frontmatter: "\ne: f\ng: h",
			Content:     "",
		},
		{
			Raw:         "----\na: b\nc: d",
			Frontmatter: "",
			Content:     "----\na: b\nc: d",
		},
		{
			Raw:         "---\n---",
			Frontmatter: "",
			Content:     "",
		},
		{
			Raw:         "\n---\n---\nHello, world!",
			Frontmatter: "",
			Content:     "\n---\n---\nHello, world!",
		},
		{
			Raw:         "---",
			Frontmatter: "",
			Content:     "",
		},
		{
			Raw:         "----",
			Frontmatter: "",
			Content:     "----",
		},
	}

	for _, test := range tests {
		frontmatter, content := extractFrontmatter([]byte(test.Raw))
		if string(frontmatter) != test.Frontmatter {
			t.Fatalf("expected frontmatter %q, got %q", test.Frontmatter, string(frontmatter))
		}
		if string(content) != test.Content {
			t.Fatalf("expected content %q, got %q", test.Content, string(content))
		}
	}
}