zenity/file_filter_test.go
2021-04-13 13:32:08 +01:00

59 lines
2.2 KiB
Go

package zenity
import (
"reflect"
"testing"
)
func TestFileFilters_simplify(t *testing.T) {
tests := []struct {
data FileFilters
want []string
}{
{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"}},
{FileFilters{{"", []string{`*.pn?`}}}, nil},
{FileFilters{{"", []string{`*.pn;`}}}, []string{"pn;"}},
{FileFilters{{"", []string{`*.pn\?`}}}, []string{"pn?"}},
{FileFilters{{"", []string{`*.[PpNnGg]`}}}, nil},
{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 {
if got := tt.data.types(); !reflect.DeepEqual(got, tt.want) {
t.Fatalf("FileFilters.types[%d] = %v, want %v", i, got, tt.want)
}
}
}