-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader_test.go
97 lines (92 loc) · 1.75 KB
/
reader_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
87
88
89
90
91
92
93
94
95
96
97
package skkdict
import (
"bytes"
"fmt"
"io"
"reflect"
"testing"
)
func assertEquals(t *testing.T, actual, expected interface{}, format string, a ...interface{}) {
if !reflect.DeepEqual(actual, expected) {
msg := fmt.Sprintf(format, a...)
t.Errorf("not equal: %s\nactual=%+v\nexpected=%+v", msg, actual, expected)
}
}
func TestReader(t *testing.T) {
f := func(s string, expected []*Entry) {
br := bytes.NewReader([]byte(s))
r := NewReader(br)
for _, exp := range expected {
act, err := r.Read()
if err != nil {
t.Fatalf("Reader.Read failed: %s", err)
}
assertEquals(t, act, exp, "source:%q", r.ll)
}
_, err := r.Read()
if err == nil {
t.Fatalf("Reader should end with io.EOF but got line:%q", r.ll)
} else if err != io.EOF {
t.Fatalf("Reader failed unexpectedly: %s", err)
}
}
f(``, []*Entry{})
f(`;;`, []*Entry{nil})
f(`りりs /凛々/凛凛/律々;=凛々しい/`, []*Entry{
{
Label: "りりs",
Words: []Word{
{Text: "凛々"},
{Text: "凛凛"},
{Text: "律々", Desc: "=凛々しい"},
},
},
})
f(`;;
あい /愛/哀/相/挨/
おん /音/温/御/恩/穏/遠/
;;
ぐん /群/郡/軍/
こと /事/異/言/殊/琴/`, []*Entry{
nil,
{
Label: "あい",
Words: []Word{
{Text: "愛"},
{Text: "哀"},
{Text: "相"},
{Text: "挨"},
},
},
{
Label: "おん",
Words: []Word{
{Text: "音"},
{Text: "温"},
{Text: "御"},
{Text: "恩"},
{Text: "穏"},
{Text: "遠"},
},
},
nil,
{
Label: "ぐん",
Words: []Word{
{Text: "群"},
{Text: "郡"},
{Text: "軍"},
},
},
{
Label: "こと",
Words: []Word{
{Text: "事"},
{Text: "異"},
{Text: "言"},
{Text: "殊"},
{Text: "琴"},
},
},
})
}