-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathintegration_test.go
89 lines (71 loc) · 1.88 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package hashtag_test
import (
"bytes"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"github.com/yuin/goldmark"
"go.abhg.dev/goldmark/hashtag"
"gopkg.in/yaml.v3"
)
func TestIntegration_Default(t *testing.T) {
t.Parallel()
testIntegration(t, "default.yaml",
goldmark.New(goldmark.WithExtensions(&hashtag.Extender{})))
}
func TestIntegration_Obsidian(t *testing.T) {
t.Parallel()
testIntegration(t, "obsidian.yaml",
goldmark.New(goldmark.WithExtensions(&hashtag.Extender{
Variant: hashtag.ObsidianVariant,
})))
}
func TestIntegration_Resolver(t *testing.T) {
t.Parallel()
testIntegration(t, "resolver.yaml",
goldmark.New(goldmark.WithExtensions(&hashtag.Extender{
Resolver: almostAlwaysResolver{},
})))
}
func TestIntegration_Attributes(t *testing.T) {
t.Parallel()
testIntegration(t, "attributes.yaml",
goldmark.New(goldmark.WithExtensions(&hashtag.Extender{
Resolver: almostAlwaysResolver{},
Attributes: []hashtag.Attribute{
{
Name: "class",
Value: "p-category",
},
},
})))
}
func testIntegration(t *testing.T, file string, md goldmark.Markdown) {
testsdata, err := os.ReadFile(filepath.Join("testdata", file))
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))
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 _unknownTag = []byte("unknown")
// Resolves all tags except "unknown".
type almostAlwaysResolver struct{}
func (almostAlwaysResolver) ResolveHashtag(n *hashtag.Node) ([]byte, error) {
if bytes.Equal(n.Tag, _unknownTag) {
return nil, nil
}
return append([]byte("/tag/"), n.Tag...), nil
}