-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtypes_test.go
118 lines (113 loc) · 2.02 KB
/
types_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package text
import (
"reflect"
"testing"
)
var parseEncodingTests = []struct {
Input string
Expect Encoding
Error string
}{
{
Input: "utf8",
Expect: UTF8,
},
{
Input: "utf8m",
Expect: UTF8M,
},
{
Input: "utf16",
Expect: UTF16,
},
{
Input: "utf16be",
Expect: UTF16BE,
},
{
Input: "utf16le",
Expect: UTF16LE,
},
{
Input: "utf16bem",
Expect: UTF16BEM,
},
{
Input: "utf16lem",
Expect: UTF16LEM,
},
{
Input: "sjis",
Expect: SJIS,
},
{
Input: "auto",
Expect: AUTO,
},
{
Input: "error",
Error: "\"error\" cannot convert to Encoding",
},
}
func TestParseEncoding(t *testing.T) {
for _, v := range parseEncodingTests {
result, err := ParseEncoding(v.Input)
if err != nil {
if len(v.Error) < 1 {
t.Errorf("unexpected error %q for %q", err.Error(), v.Input)
} else if err.Error() != v.Error {
t.Errorf("error %q, want error %q for %q", err, v.Error, v.Input)
}
continue
}
if 0 < len(v.Error) {
t.Errorf("no error, want error %q for %q", v.Error, v.Input)
continue
}
if !reflect.DeepEqual(result, v.Expect) {
t.Errorf("result = %#v, want %#v for %q", result, v.Expect, v.Input)
}
}
}
var parseLineBreakTests = []struct {
Input string
Expect LineBreak
Error string
}{
{
Input: "crlf",
Expect: CRLF,
},
{
Input: "cr",
Expect: CR,
},
{
Input: "lf",
Expect: LF,
},
{
Input: "error",
Error: "\"error\" cannot convert to LineBreak",
},
}
func TestParseLineBreak(t *testing.T) {
for _, v := range parseLineBreakTests {
result, err := ParseLineBreak(v.Input)
if err != nil {
if len(v.Error) < 1 {
t.Errorf("unexpected error %q for %q", err.Error(), v.Input)
} else if err.Error() != v.Error {
t.Errorf("error %q, want error %q for %q", err, v.Error, v.Input)
}
continue
}
if 0 < len(v.Error) {
t.Errorf("no error, want error %q for %q", v.Error, v.Input)
continue
}
if !reflect.DeepEqual(result, v.Expect) {
t.Errorf("result = %#v, want %#v for %q", result, v.Expect, v.Input)
}
}
}