-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
finders_test.go
83 lines (55 loc) · 1.1 KB
/
finders_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
package hype
import (
"testing"
"testing/fstest"
"github.com/stretchr/testify/require"
)
func byXYZCab(t testing.TB) *fstest.MapFS {
t.Helper()
mod := `# Page One
some text with a [link](http://example.com) inside of it.
<img src="foo.jpg" alt="foo" />
Here is some more text.
<img src="bar.jpg" alt="bar" />
and finally:
<code src="code.go"></code>
`
cab := &fstest.MapFS{
"hype.md": &fstest.MapFile{
Data: []byte(mod),
},
}
return cab
}
func byXYZDoc(t testing.TB) *Document {
t.Helper()
p := NewParser(byXYZCab(t))
doc, err := p.ParseFile("hype.md")
if err != nil {
t.Fatal(err)
}
return doc
}
func Test_ByAtom(t *testing.T) {
t.Parallel()
r := require.New(t)
doc := byXYZDoc(t)
nodes := ByAtom(doc.Children(), "img")
r.Len(nodes, 2)
}
func Test_ByAttrs(t *testing.T) {
t.Parallel()
r := require.New(t)
doc := byXYZDoc(t)
nodes := ByAttrs(doc.Children(), map[string]string{
"src": "*",
})
r.Len(nodes, 3)
}
func Test_ByType(t *testing.T) {
t.Parallel()
r := require.New(t)
doc := byXYZDoc(t)
nodes := ByType[*SourceCode](doc.Children())
r.Len(nodes, 1)
}