-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmd_test.go
70 lines (49 loc) · 1.14 KB
/
md_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
package hype
import (
"context"
"io"
"strings"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func Test_Markdown_UnknownAtom(t *testing.T) {
t.Skip()
t.Parallel()
r := require.New(t)
root := "testdata/markdown/unknown-atom"
p := testParser(t, root)
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()
doc, err := p.ParseExecuteFile(ctx, "hype.md")
r.NoError(err)
exp := `<a for="io#EOF" href="https://pkg.go.dev/io#EOF" target="_blank"><code>io.EOF</code></a>`
act := doc.String()
act = strings.TrimSpace(act)
// fmt.Println(act)
r.Equal(act, exp)
}
func Test_Markdown(t *testing.T) {
t.Parallel()
r := require.New(t)
fn := Markdown()
in := strings.NewReader(`# Hello World`)
out, err := fn(&Parser{}, in)
r.NoError(err)
b, err := io.ReadAll(out)
r.NoError(err)
act := string(b)
act = strings.TrimSpace(act)
exp := "<page>\n<h1>Hello World</h1>\n</page>"
r.Equal(exp, act)
}
func Test_Markdown_Error(t *testing.T) {
t.Parallel()
r := require.New(t)
fn := Markdown()
_, err := fn(nil, nil)
r.Error(err)
_, err = fn(nil, brokenReader{})
r.Error(err)
}