2021-04-11 22:59:08 -04:00
|
|
|
package zenity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2021-06-18 11:16:04 -04:00
|
|
|
func TestFileFilters_name(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
data FileFilters
|
|
|
|
want string
|
|
|
|
}{
|
2022-12-14 22:05:44 -05:00
|
|
|
{FileFilters{{"", []string{`*.png`}, true}}, "*.png"},
|
|
|
|
{FileFilters{{"", []string{`*.png`, `*.jpg`}, true}}, "*.png *.jpg"},
|
|
|
|
{FileFilters{{"Image files", []string{`*.png`, `*.jpg`}, true}}, "Image files"},
|
2021-06-18 11:16:04 -04:00
|
|
|
}
|
|
|
|
for i, tt := range tests {
|
|
|
|
tt.data.name()
|
|
|
|
if got := tt.data[0].Name; got != tt.want {
|
2021-07-07 08:24:46 -04:00
|
|
|
t.Errorf("FileFilters.name[%d] = %q; want %q", i, got, tt.want)
|
2021-06-18 11:16:04 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-13 08:28:26 -04:00
|
|
|
func TestFileFilters_simplify(t *testing.T) {
|
2021-04-11 22:59:08 -04:00
|
|
|
tests := []struct {
|
2022-12-14 22:05:44 -05:00
|
|
|
data []string
|
2021-04-11 22:59:08 -04:00
|
|
|
want []string
|
|
|
|
}{
|
2022-12-14 22:05:44 -05:00
|
|
|
{[]string{``}, nil},
|
|
|
|
{[]string{`*.\?`}, nil},
|
|
|
|
{[]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"}},
|
2021-04-13 08:28:26 -04:00
|
|
|
}
|
|
|
|
for i, tt := range tests {
|
2022-12-14 22:05:44 -05:00
|
|
|
filters := FileFilters{FileFilter{Patterns: tt.data}}
|
|
|
|
filters.simplify()
|
|
|
|
if got := filters[0].Patterns; !reflect.DeepEqual(got, tt.want) {
|
2021-07-07 08:24:46 -04:00
|
|
|
t.Errorf("FileFilters.simplify[%d] = %q; want %q", i, got, tt.want)
|
2021-04-13 08:28:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-14 22:05:44 -05:00
|
|
|
func TestFileFilters_casefold(t *testing.T) {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-13 08:28:26 -04:00
|
|
|
func TestFileFilters_types(t *testing.T) {
|
|
|
|
tests := []struct {
|
2022-12-14 22:05:44 -05:00
|
|
|
data []string
|
2021-04-13 08:28:26 -04:00
|
|
|
want []string
|
|
|
|
}{
|
2022-12-14 22:05:44 -05:00
|
|
|
{[]string{``}, nil},
|
|
|
|
{[]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"}},
|
2021-04-11 22:59:08 -04:00
|
|
|
}
|
2021-04-13 08:28:26 -04:00
|
|
|
for i, tt := range tests {
|
2022-12-14 22:05:44 -05:00
|
|
|
filters := FileFilters{FileFilter{Patterns: tt.data}}
|
|
|
|
if got := filters.types(); !reflect.DeepEqual(got, tt.want) {
|
2021-07-07 08:24:46 -04:00
|
|
|
t.Errorf("FileFilters.types[%d] = %v; want %v", i, got, tt.want)
|
2021-04-11 22:59:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|