-
Notifications
You must be signed in to change notification settings - Fork 7
/
integration_test.go
58 lines (45 loc) · 1.13 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
package wikilink_test
import (
"bytes"
"os"
"testing"
"github.com/stretchr/testify/require"
"github.com/yuin/goldmark"
"go.abhg.dev/goldmark/wikilink"
"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"`
}
require.NoError(t, yaml.Unmarshal(testsdata, &tests))
md := goldmark.New(goldmark.WithExtensions(&wikilink.Extender{
Resolver: _resolver,
}))
for _, tt := range tests {
tt := tt
t.Run(tt.Desc, func(t *testing.T) {
t.Parallel()
var buf bytes.Buffer
require.NoError(t, md.Convert([]byte(tt.Give), &buf))
require.Equal(t, tt.Want, buf.String())
})
}
}
var (
_resolver = resolver{}
// Links with this target will return a nil destination.
_doesNotExistTarget = []byte("Does Not Exist")
)
type resolver struct{}
func (resolver) ResolveWikilink(n *wikilink.Node) ([]byte, error) {
if bytes.Equal(n.Target, _doesNotExistTarget) {
return nil, nil
}
return wikilink.DefaultResolver.ResolveWikilink(n)
}