forked from ncruces/zenity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_filter_test.go
118 lines (113 loc) · 3.76 KB
/
file_filter_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 zenity
import (
"reflect"
"testing"
)
func TestFileFilters_name(t *testing.T) {
t.Parallel()
tests := []struct {
data FileFilters
want string
}{
{FileFilters{{"", []string{`*.png`}, true}}, "*.png"},
{FileFilters{{"", []string{`*.png`, `*.jpg`}, true}}, "*.png *.jpg"},
{FileFilters{{"Image files", []string{`*.png`, `*.jpg`}, true}}, "Image files"},
}
for i, tt := range tests {
tt.data.name()
if got := tt.data[0].Name; got != tt.want {
t.Errorf("FileFilters.name[%d] = %q; want %q", i, got, tt.want)
}
}
}
func TestFileFilters_simplify(t *testing.T) {
t.Parallel()
tests := []struct {
data []string
want []string
}{
{[]string{``}, nil},
{[]string{`*.\?`}, nil},
{[]string{`*.`}, []string{`*.`}},
{[]string{`*.png`}, []string{"*.png"}},
{[]string{`*.pn?`}, []string{"*.pn?"}},
{[]string{`*.pn;`}, []string{"*.pn?"}},
{[]string{`*.[PpNnGg]`}, []string{"*.?"}},
{[]string{`*.[Pp][Nn][Gg]`}, []string{"*.PNG"}},
{[]string{`*.[Pp][\Nn][G\g]`}, []string{"*.PNG"}},
{[]string{`*.[PNG`}, []string{"*.[PNG"}},
{[]string{`*.]PNG`}, []string{"*.]PNG"}},
{[]string{`*.[[]PNG`}, []string{"*.[PNG"}},
{[]string{`*.[]]PNG`}, []string{"*.]PNG"}},
{[]string{`*.[\[]PNG`}, []string{"*.[PNG"}},
{[]string{`*.[\]]PNG`}, []string{"*.]PNG"}},
{[]string{`public.png`}, []string{"public.png"}},
}
for i, tt := range tests {
filters := FileFilters{FileFilter{Patterns: tt.data}}
filters.simplify()
if got := filters[0].Patterns; !reflect.DeepEqual(got, tt.want) {
t.Errorf("FileFilters.simplify[%d] = %q; want %q", i, got, tt.want)
}
}
}
func TestFileFilters_casefold(t *testing.T) {
t.Parallel()
tests := []struct {
data []string
want []string
}{
{[]string{`*.png`}, []string{`*.[pP][nN][gG]`}},
{[]string{`*.pn?`}, []string{`*.[pP][nN]?`}},
{[]string{`*.pn;`}, []string{`*.[pP][nN];`}},
{[]string{`*.pn\?`}, []string{`*.[pP][nN]\?`}},
{[]string{`*.[PpNnGg]`}, []string{`*.[PppPNnnNGggG]`}},
{[]string{`*.[Pp][Nn][Gg]`}, []string{`*.[PppP][NnnN][GggG]`}},
{[]string{`*.[Pp][\Nn][G\g]`}, []string{`*.[PppP][\NnnN][Gg\gG]`}},
{[]string{`*.[PNG`}, []string{`*.[PpNnGg`}},
{[]string{`*.]PNG`}, []string{`*.][Pp][Nn][Gg]`}},
{[]string{`*.[[]PNG`}, []string{`*.[[][Pp][Nn][Gg]`}},
{[]string{`*.[]]PNG`}, []string{`*.[]][Pp][Nn][Gg]`}},
{[]string{`*.[\[]PNG`}, []string{`*.[\[][Pp][Nn][Gg]`}},
{[]string{`*.[\]]PNG`}, []string{`*.[\]][Pp][Nn][Gg]`}},
}
for i, tt := range tests {
filters := FileFilters{FileFilter{Patterns: tt.data}}
filters[0].CaseFold = true
filters.casefold()
if got := filters[0].Patterns; !reflect.DeepEqual(got, tt.want) {
t.Errorf("FileFilters.casefold[%d] = %q; want %q", i, got, tt.want)
}
}
}
func TestFileFilters_types(t *testing.T) {
t.Parallel()
tests := []struct {
data []string
want []string
}{
{[]string{``}, nil},
{[]string{`*.`}, []string{".", ""}},
{[]string{`*.png`}, []string{".", "png"}},
{[]string{`*.pn?`}, nil},
{[]string{`*.pn;`}, []string{".", "pn;"}},
{[]string{`*.pn\?`}, []string{".", "pn?"}},
{[]string{`*.[PpNnGg]`}, nil},
{[]string{`*.[Pp][Nn][Gg]`}, []string{".", "PNG"}},
{[]string{`*.[Pp][\Nn][G\g]`}, []string{".", "PNG"}},
{[]string{`*.[PNG`}, []string{".", "[PNG"}},
{[]string{`*.]PNG`}, []string{".", "]PNG"}},
{[]string{`*.[[]PNG`}, []string{".", "[PNG"}},
{[]string{`*.[]]PNG`}, []string{".", "]PNG"}},
{[]string{`*.[\[]PNG`}, []string{".", "[PNG"}},
{[]string{`*.[\]]PNG`}, []string{".", "]PNG"}},
{[]string{`public.png`}, []string{".", "public.png"}},
{[]string{`-public-.png`}, []string{".", "png"}},
}
for i, tt := range tests {
filters := FileFilters{FileFilter{Patterns: tt.data}}
if got := filters.types(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("FileFilters.types[%d] = %v; want %v", i, got, tt.want)
}
}
}