-
Notifications
You must be signed in to change notification settings - Fork 4
/
extender_test.go
45 lines (42 loc) · 1.05 KB
/
extender_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
package katex
import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/yuin/goldmark"
)
func TestExtenderTestExtender(t *testing.T) {
entries, err := os.ReadDir("testdata")
if err != nil {
t.Fatal(err)
}
for _, entry := range entries {
if filepath.Ext(entry.Name()) != ".md" {
continue
}
t.Run(entry.Name(), func(t *testing.T) {
in, err := os.ReadFile(filepath.Join("testdata", entry.Name()))
if err != nil {
t.Fatal(err)
}
want, err := os.ReadFile(filepath.Join("testdata", strings.TrimSuffix(entry.Name(), ".md")+".html"))
if err != nil {
t.Fatal(err)
}
if bytes.HasPrefix(want, []byte("<link ")) {
want = want[bytes.Index(want, []byte("\n"))+1:]
}
got := bytes.Buffer{}
err = goldmark.New(goldmark.WithExtensions(&Extender{})).Convert(in, &got)
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(want, got.Bytes()); diff != "" {
t.Fatalf("%s:\n\nwant:\n%s\n\ngot:\n%s\n\ndiff:\n%s\n", entry.Name(), want, got.String(), diff)
}
})
}
}