-
Notifications
You must be signed in to change notification settings - Fork 1
/
collect_test.go
63 lines (50 loc) · 1.28 KB
/
collect_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
package main
import (
"testing"
"testing/fstest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.abhg.dev/stitchmd/internal/goldast"
"go.abhg.dev/stitchmd/internal/stitch"
"go.abhg.dev/stitchmd/internal/tree"
)
func TestCollector_fileDoesNotExist(t *testing.T) {
t.Parallel()
file := goldast.Parse(
goldast.DefaultParser(),
"stdin",
[]byte("- [foo](foo.md)"),
)
summary, err := stitch.ParseSummary(file)
require.NoError(t, err)
_, err = (&collector{
Parser: goldast.DefaultParser(),
FS: make(fstest.MapFS), // empty filesystem
}).Collect(file.Info, summary)
require.Error(t, err)
assert.ErrorContains(t, err, "foo.md: file does not exist")
}
func TestCollector_unknownItemType(t *testing.T) {
t.Parallel()
type badItem struct {
stitch.Item
}
summary := &stitch.Summary{
Sections: []*stitch.Section{
{Items: tree.List[stitch.Item]{
{Value: badItem{}},
}},
},
}
assert.Panics(t, func() {
_, _ = (&collector{
Parser: goldast.DefaultParser(),
FS: make(fstest.MapFS),
}).Collect(fixedPositioner{Line: 1, Column: 1}, summary)
})
}
type fixedPositioner goldast.Position
var _ goldast.Positioner = fixedPositioner{}
func (p fixedPositioner) Position(int) goldast.Position {
return goldast.Position(p)
}