forked from liuzl/gocc
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy paths2t_test.go
60 lines (42 loc) · 1.08 KB
/
s2t_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
package opencc
import (
"fmt"
"os"
"path"
"strings"
"testing"
"github.com/longbridge/opencc"
"github.com/sergi/go-diff/diffmatchpatch"
)
func readFile(filename string) string {
pwd, _ := os.Getwd()
data, err := os.ReadFile(path.Join(pwd, "fixtures", filename))
if err != nil {
panic(err)
}
return strings.TrimSpace(string(data))
}
func Test_s2t(t *testing.T) {
raw := readFile("html-raw.txt")
expected := readFile("html-s2t.txt")
cc, _ := opencc.New("s2t")
out, _ := cc.Convert(raw)
fmt.Println(out)
if strings.TrimSpace(expected) != strings.TrimSpace(out) {
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(expected, out, true)
t.Errorf(dmp.DiffPrettyText(diffs))
}
}
func TestFinance_s2hk_finance(t *testing.T) {
raw := readFile("html-raw.txt")
expected := readFile("html-s2hk-finance.txt")
cc, _ := opencc.New("s2hk-finance")
out, _ := cc.Convert(raw)
fmt.Println(out)
if strings.TrimSpace(expected) != strings.TrimSpace(out) {
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(expected, out, true)
t.Errorf(dmp.DiffPrettyText(diffs))
}
}