zenity/file_filter_test.go

60 lines
2.2 KiB
Go
Raw Normal View History

2021-04-11 22:59:08 -04:00
package zenity
import (
"reflect"
"testing"
)
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-04-13 08:28:26 -04:00
{FileFilters{{"", []string{`*.png`}}}, []string{"*.png"}},
{FileFilters{{"", []string{`*.pn?`}}}, []string{"*.pn?"}},
{FileFilters{{"", []string{`*.pn;`}}}, []string{"*.pn?"}},
{FileFilters{{"", []string{`*.pn\?`}}}, []string{""}},
{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"}},
}
for i, tt := range tests {
tt.data.simplify()
if got := tt.data[0].Patterns; !reflect.DeepEqual(got, tt.want) {
t.Errorf("FileFilters.simplify[%d] = %q, want %q", i, got, tt.want)
}
}
}
func TestFileFilters_types(t *testing.T) {
tests := []struct {
data FileFilters
want []string
}{
{FileFilters{{"", []string{`*.png`}}}, []string{"png"}},
2021-04-11 22:59:08 -04:00
{FileFilters{{"", []string{`*.pn?`}}}, nil},
2021-04-13 08:28:26 -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-04-13 08:28:26 -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"}},
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) {
t.Fatalf("FileFilters.types[%d] = %v, want %v", i, got, tt.want)
2021-04-11 22:59:08 -04:00
}
}
}