-
Notifications
You must be signed in to change notification settings - Fork 2
/
fmatter_test.go
55 lines (46 loc) · 909 Bytes
/
fmatter_test.go
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
package fmatter
import (
"bytes"
"fmt"
"testing"
)
func ExampleRead() {
data := []byte(`---
title: Some Title
---
content`)
var frontmatter struct{ Title string }
content, _ := Read(data, &frontmatter)
fmt.Println(content)
}
// TODO: test a few expected errors
type testItem struct {
data []byte
expectedContent []byte
}
var testItems = []testItem{
{[]byte(`---
frontmatter: simple
---
content`),
[]byte(`content`)},
{[]byte(` content`),
[]byte(` content`)},
{[]byte(`---
content`),
[]byte(`---
content`)},
}
func TestItems(t *testing.T) {
frontmatter := make(map[string]interface{})
for _, item := range testItems {
content, err := Read(item.data, frontmatter)
if err != nil {
t.Fatal(err)
}
if bytes.Compare(content, item.expectedContent) != 0 {
t.Fatalf("unexpected content:\n%v\nvs.\n%v",
string(content), string(item.expectedContent))
}
}
}