-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathmain_test.go
More file actions
80 lines (74 loc) · 1.67 KB
/
Copy pathmain_test.go
File metadata and controls
80 lines (74 loc) · 1.67 KB
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
package main
import (
"testing"
"golang.org/x/text/encoding"
)
func TestStripExt(t *testing.T) {
tests := []struct {
name string
input string
want string
}{
{name: "simple ext", input: "foo.idx", want: "foo"},
{name: "path ext", input: "path/to/file.tex", want: "path/to/file"},
{name: "no ext", input: "noext", want: "noext"},
{name: "multiple dots", input: "a.b.c", want: "a.b"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := stripExt(tt.input); got != tt.want {
t.Fatalf("stripExt(%q) = %q, want %q", tt.input, got, tt.want)
}
})
}
}
func TestCheckEncoding(t *testing.T) {
tests := []struct {
name string
input string
check func(t *testing.T, got encoding.Encoding)
}{
{
name: "utf-8 lowercase",
input: "utf-8",
check: func(t *testing.T, got encoding.Encoding) {
if got != encoding.Nop {
t.Fatalf("checkEncoding(%q) did not return encoding.Nop", "utf-8")
}
},
},
{
name: "utf-8 uppercase",
input: "UTF-8",
check: func(t *testing.T, got encoding.Encoding) {
if got != encoding.Nop {
t.Fatalf("checkEncoding(%q) did not return encoding.Nop", "UTF-8")
}
},
},
{
name: "gbk",
input: "gbk",
check: func(t *testing.T, got encoding.Encoding) {
if got == nil {
t.Fatalf("checkEncoding(%q) returned nil", "gbk")
}
},
},
{
name: "big5",
input: "big5",
check: func(t *testing.T, got encoding.Encoding) {
if got == nil {
t.Fatalf("checkEncoding(%q) returned nil", "big5")
}
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := checkEncoding(tt.input)
tt.check(t, got)
})
}
}