zenity/file_filter_test.go

82 lines
3 KiB
Go
Raw Normal View History

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
}{
{FileFilters{{"", []string{`*.png`}}}, "*.png"},
{FileFilters{{"", []string{`*.png`, `*.jpg`}}}, "*.png *.jpg"},
{FileFilters{{"Image files", []string{`*.png`, `*.jpg`}}}, "Image files"},
}
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 {
data FileFilters
want []string
}{
2021-06-16 08:34:50 -04:00
{FileFilters{{"", []string{``}}}, nil},
2021-04-13 08:28:26 -04:00
{FileFilters{{"", []string{`*.png`}}}, []string{"*.png"}},
{FileFilters{{"", []string{`*.pn?`}}}, []string{"*.pn?"}},
{FileFilters{{"", []string{`*.pn;`}}}, []string{"*.pn?"}},
2021-06-16 08:34:50 -04:00
{FileFilters{{"", []string{`*.pn\?`}}}, nil},
2021-04-13 08:28:26 -04:00
{FileFilters{{"", []string{`*.[PpNnGg]`}}}, []string{"*.?"}},
{FileFilters{{"", []string{`*.[Pp][Nn][Gg]`}}}, []string{"*.PNG"}},
{FileFilters{{"", []string{`*.[Pp][\Nn][G\g]`}}}, []string{"*.PNG"}},
{FileFilters{{"", []string{`*.[PNG`}}}, []string{"*.[PNG"}},
{FileFilters{{"", []string{`*.]PNG`}}}, []string{"*.]PNG"}},
{FileFilters{{"", []string{`*.[[]PNG`}}}, []string{"*.[PNG"}},
{FileFilters{{"", []string{`*.[]]PNG`}}}, []string{"*.]PNG"}},
{FileFilters{{"", []string{`*.[\[]PNG`}}}, []string{"*.[PNG"}},
{FileFilters{{"", []string{`*.[\]]PNG`}}}, []string{"*.]PNG"}},
2021-06-16 08:34:50 -04:00
{FileFilters{{"", []string{`public.png`}}}, []string{"public.png"}},
2021-04-13 08:28:26 -04:00
}
for i, tt := range tests {
tt.data.simplify()
if got := tt.data[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
}
}
}
func TestFileFilters_types(t *testing.T) {
tests := []struct {
data FileFilters
want []string
}{
2021-06-16 08:34:50 -04:00
{FileFilters{{"", []string{``}}}, nil},
{FileFilters{{"", []string{`*.png`}}}, []string{"", "png"}},
2021-04-11 22:59:08 -04:00
{FileFilters{{"", []string{`*.pn?`}}}, nil},
2021-06-16 08:34:50 -04:00
{FileFilters{{"", []string{`*.pn;`}}}, []string{"", "pn;"}},
{FileFilters{{"", []string{`*.pn\?`}}}, []string{"", "pn?"}},
2021-04-11 22:59:08 -04:00
{FileFilters{{"", []string{`*.[PpNnGg]`}}}, nil},
2021-06-16 08:34:50 -04:00
{FileFilters{{"", []string{`*.[Pp][Nn][Gg]`}}}, []string{"", "PNG"}},
{FileFilters{{"", []string{`*.[Pp][\Nn][G\g]`}}}, []string{"", "PNG"}},
{FileFilters{{"", []string{`*.[PNG`}}}, []string{"", "[PNG"}},
{FileFilters{{"", []string{`*.]PNG`}}}, []string{"", "]PNG"}},
{FileFilters{{"", []string{`*.[[]PNG`}}}, []string{"", "[PNG"}},
{FileFilters{{"", []string{`*.[]]PNG`}}}, []string{"", "]PNG"}},
{FileFilters{{"", []string{`*.[\[]PNG`}}}, []string{"", "[PNG"}},
{FileFilters{{"", []string{`*.[\]]PNG`}}}, []string{"", "]PNG"}},
{FileFilters{{"", []string{`public.png`}}}, []string{"", "public.png"}},
2021-06-18 11:16:04 -04:00
{FileFilters{{"", []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 {
if got := tt.data.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
}
}
}