-
Notifications
You must be signed in to change notification settings - Fork 5
/
integration_test.go
59 lines (50 loc) · 1.31 KB
/
integration_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
56
57
58
59
package toc_test
import (
"bytes"
"os"
"testing"
"github.com/stretchr/testify/require"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/parser"
"go.abhg.dev/goldmark/toc"
"gopkg.in/yaml.v3"
)
func TestIntegration(t *testing.T) {
t.Parallel()
testsdata, err := os.ReadFile("testdata/tests.yaml")
require.NoError(t, err)
var tests []struct {
Desc string `yaml:"desc"`
Give string `yaml:"give"`
Want string `yaml:"want"`
Title string `yaml:"title"`
TitleDepth int `yaml:"titleDepth"`
ListID string `yaml:"listID"`
TitleID string `yaml:"titleID"`
MinDepth int `yaml:"minDepth"`
MaxDepth int `yaml:"maxDepth"`
Compact bool `yaml:"compact"`
}
require.NoError(t, yaml.Unmarshal(testsdata, &tests))
for _, tt := range tests {
tt := tt
t.Run(tt.Desc, func(t *testing.T) {
t.Parallel()
md := goldmark.New(
goldmark.WithExtensions(&toc.Extender{
Title: tt.Title,
TitleDepth: tt.TitleDepth,
MinDepth: tt.MinDepth,
MaxDepth: tt.MaxDepth,
Compact: tt.Compact,
ListID: tt.ListID,
TitleID: tt.TitleID,
}),
goldmark.WithParserOptions(parser.WithAutoHeadingID()),
)
var buf bytes.Buffer
require.NoError(t, md.Convert([]byte(tt.Give), &buf))
require.Equal(t, tt.Want, buf.String())
})
}
}