-
Notifications
You must be signed in to change notification settings - Fork 28
/
mdfilter_test.go
86 lines (61 loc) · 1.58 KB
/
mdfilter_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
package main
import (
"bytes"
"io"
"strings"
"testing"
"github.com/seanpont/assert"
)
func TestFilter1(t *testing.T) {
assert := assert.Assert(t)
md := `
This is normal markdown
#!goseq
This is some seq diagram
This is normal markdown again`
expMd := `
This is normal markdown
This is normal markdown again
`
blocks, actual := runFilter(md)
assert.Equal("["+actual+"]", "["+expMd+"]")
assert.Equal(len(blocks), 1)
assert.Equal(blocks[0], " #!goseq\n This is some seq diagram\n\n")
}
func TestFilter2(t *testing.T) {
assert := assert.Assert(t)
md := `
This is normal markdown
This is a standard code block that does nothing.
Back to normal markdown
#!goseq
This is some seq diagram
More sequence diagram
This is normal markdown again
asdasdasdasdasdasdasd
#!goseq
Seq diagram again
`
expMd := `
This is normal markdown
This is a standard code block that does nothing.
Back to normal markdown
This is normal markdown again
asdasdasdasdasdasdasd
`
blocks, actual := runFilter(md)
assert.Equal("["+actual+"]", "["+expMd+"]")
assert.Equal(len(blocks), 2)
assert.Equal(blocks[0], " #!goseq\n This is some seq diagram\n \n More sequence diagram\n\n")
assert.Equal(blocks[1], " #!goseq\n Seq diagram again\n")
}
func runFilter(input string) (blocks []string, output string) {
bufout := new(bytes.Buffer)
mf := &MarkdownFilter{strings.NewReader(input), bufout, func(codeblock string, output io.Writer) error {
blocks = append(blocks, codeblock)
return nil
}}
mf.Scan()
output = bufout.String()
return
}