-
Notifications
You must be signed in to change notification settings - Fork 11
/
parser_test.go
85 lines (71 loc) · 1.72 KB
/
parser_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
package crumbs
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseLines(t *testing.T) {
test := `
* main idea
** topic 1
*** sub topic 1 1
*** sub topic 1 2
**** sub sub topic
** topic 2
*** sub topic 2 1
`
got, err := ParseLines(strings.SplitAfter(test, "\n"), "")
if err != nil {
t.Error(err)
}
assert.Equal(t, 1, len(got.childrens))
assert.Equal(t, got.childrens[0].text, "main idea")
assert.Equal(t, 2, len(got.childrens[0].childrens))
assert.Equal(t, got.childrens[0].childrens[0].text, "topic 1")
assert.Equal(t, got.childrens[0].childrens[1].text, "topic 2")
assert.Equal(t, 2, len(got.childrens[0].childrens[0].childrens))
assert.Equal(t, got.childrens[0].childrens[0].childrens[1].text, "sub topic 1 2")
}
func TestLookForIcon(t *testing.T) {
tests := []struct {
imagespath string
entry Entry
want string
}{
{
"./images/png",
Entry{text: "[[blob.png]] La vispa Teresa avea tra l'erbetta, a volo sorpresa"},
"images/png/blob.png",
},
{
"/home/lus/Pictures/fontawesome/PNG",
Entry{text: "[[blob.png]] La vispa Teresa avea tra l'erbetta, a volo sorpresa"},
"/home/lus/Pictures/fontawesome/PNG/blob.png",
},
}
for _, tt := range tests {
fn := lookForIcon(tt.imagespath)
fn(&tt.entry)
t.Run(tt.imagespath, func(t *testing.T) {
if got := tt.entry.icon; got != tt.want {
t.Errorf("got [%v] want [%v]", got, tt.want)
}
})
}
}
func TestDepth(t *testing.T) {
tests := []struct {
line string
want int
}{
{"* main idea LV.1", 1},
{"** topic 1 LV.2", 2},
{"*** sub topic LV.3", 3},
{"******* LV.7", 7},
}
for _, tt := range tests {
t.Run(tt.line, func(t *testing.T) {
assert.Equal(t, depth(tt.line), tt.want)
})
}
}