-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreplace_old_new_test.go
50 lines (46 loc) · 982 Bytes
/
replace_old_new_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
package kanji
import (
"bufio"
"os"
"strconv"
"strings"
"testing"
)
func TestNewOldFormNewFormReplacer(t *testing.T) {
f, err := os.Open("./testdata/golden_old-new.txt")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
defer f.Close()
replacer := NewOldFormNewFormReplacer()
s := bufio.NewScanner(f)
var line int
for s.Scan() {
l := s.Text()
line++
if strings.HasPrefix(l, "!") {
continue
}
a := strings.Split(l, " ")
if len(a) != 4 {
t.Errorf("invalid golden file, line=%d, %s", line, l)
continue
}
code, err := strconv.ParseInt(a[0], 16, strconv.IntSize)
if err != nil {
t.Errorf("invalid golden file, line=%d, parse int error %v, %s", line, err, l)
continue
}
r := rune(code)
t.Run(l, func(t *testing.T) {
got := replacer.Replace(string(r))
want := a[3]
if got != want {
t.Errorf("want %s, got %s", want, got)
}
})
}
if err := s.Err(); err != nil {
t.Errorf("unexpected error, %v", err)
}
}