zenity/zenity_test.go

78 lines
3.2 KiB
Go
Raw Normal View History

2021-07-06 20:54:32 -04:00
package zenity
import (
"context"
"image/color"
"reflect"
"testing"
2022-05-17 10:36:00 -04:00
"time"
2021-07-06 20:54:32 -04:00
)
func Test_applyOptions(t *testing.T) {
2022-05-17 10:36:00 -04:00
date := time.Date(2006, 1, 1, 0, 0, 0, 0, time.Local)
2021-07-06 20:54:32 -04:00
tests := []struct {
name string
args Option
want options
}{
// General options
{name: "Title", args: Title("Title"), want: options{title: stringPtr("Title")}},
{name: "Width", args: Width(100), want: options{width: 100}},
{name: "Height", args: Height(100), want: options{height: 100}},
{name: "OKLabel", args: OKLabel("OK"), want: options{okLabel: stringPtr("OK")}},
{name: "CancelLabel", args: CancelLabel("Cancel"), want: options{cancelLabel: stringPtr("Cancel")}},
{name: "ExtraButton", args: ExtraButton("Extra"), want: options{extraButton: stringPtr("Extra")}},
{name: "DefaultCancel", args: DefaultCancel(), want: options{defaultCancel: true}},
2022-05-17 10:36:00 -04:00
{name: "Icon", args: Icon(ErrorIcon), want: options{icon: ErrorIcon}},
2021-07-06 20:54:32 -04:00
// Message options
{name: "NoWrap", args: NoWrap(), want: options{noWrap: true}},
{name: "Ellipsize", args: Ellipsize(), want: options{ellipsize: true}},
// Entry options
{name: "EntryText", args: EntryText("text"), want: options{entryText: "text"}},
{name: "HideText", args: HideText(), want: options{hideText: true}},
{name: "Username", args: Username(), want: options{username: true}},
// List options
{name: "DisallowEmpty", args: DisallowEmpty(), want: options{disallowEmpty: true}},
{name: "DefaultItems", args: DefaultItems("a", "b"), want: options{defaultItems: []string{"a", "b"}}},
2022-05-17 10:36:00 -04:00
// Calendar options
{name: "DefaultDate", args: DefaultDate(2006, time.January, 1), want: options{time: &date}},
2021-07-06 20:54:32 -04:00
// File selection options
{name: "Directory", args: Directory(), want: options{directory: true}},
{name: "ConfirmOverwrite", args: ConfirmOverwrite(), want: options{confirmOverwrite: true}},
{name: "ConfirmCreate", args: ConfirmCreate(), want: options{confirmCreate: true}},
{name: "ShowHidden", args: ShowHidden(), want: options{showHidden: true}},
{name: "Filename", args: Filename("file.go"), want: options{filename: "file.go"}},
2021-07-12 20:43:52 -04:00
{name: "FileFilter", args: FileFilter{"Go files", []string{"*.go"}}, want: options{
fileFilters: FileFilters{{"Go files", []string{"*.go"}}},
}},
{name: "FileFilters", args: FileFilters{{"Go files", []string{"*.go"}}}, want: options{
2021-07-06 20:54:32 -04:00
fileFilters: FileFilters{{"Go files", []string{"*.go"}}},
}},
2022-05-17 10:36:00 -04:00
// Color selection options
{name: "Color", args: Color(color.Black), want: options{color: color.Black}},
{name: "ShowPalette", args: ShowPalette(), want: options{showPalette: true}},
2021-07-06 20:54:32 -04:00
// Progress indication options
{name: "MaxValue", args: MaxValue(100), want: options{maxValue: 100}},
2021-07-12 20:43:52 -04:00
{name: "Pulsate", args: Pulsate(), want: options{maxValue: -1}},
2021-07-06 20:54:32 -04:00
{name: "NoCancel", args: NoCancel(), want: options{noCancel: true}},
{name: "TimeRemaining", args: TimeRemaining(), want: options{timeRemaining: true}},
// Context for timeout
{name: "Context", args: Context(context.TODO()), want: options{ctx: context.TODO()}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := applyOptions([]Option{tt.args}); !reflect.DeepEqual(got, tt.want) {
2021-07-07 08:24:46 -04:00
t.Errorf("applyOptions() = %v; want %v", got, tt.want)
2021-07-06 20:54:32 -04:00
}
})
}
}