zenity/zenity_test.go

87 lines
3.8 KiB
Go
Raw Permalink 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"
2022-06-04 08:09:58 -04:00
2022-06-28 09:25:19 -04:00
"github.com/ncruces/zenity/internal/zencmd"
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
2022-12-14 19:26:34 -05:00
{name: "Title", args: Title("Title"), want: options{title: ptr("Title")}},
2021-07-06 20:54:32 -04:00
{name: "Width", args: Width(100), want: options{width: 100}},
{name: "Height", args: Height(100), want: options{height: 100}},
2022-12-14 19:26:34 -05:00
{name: "OKLabel", args: OKLabel("OK"), want: options{okLabel: ptr("OK")}},
{name: "CancelLabel", args: CancelLabel("Cancel"), want: options{cancelLabel: ptr("Cancel")}},
{name: "ExtraButton", args: ExtraButton("Extra"), want: options{extraButton: ptr("Extra")}},
2021-07-06 20:54:32 -04:00
{name: "DefaultCancel", args: DefaultCancel(), want: options{defaultCancel: true}},
2022-05-18 09:48:09 -04:00
{name: "WindowIcon", args: WindowIcon(ErrorIcon), want: options{windowIcon: ErrorIcon}},
{name: "WindowIcon", args: WindowIcon("error"), want: options{windowIcon: "error"}},
2022-05-17 10:36:00 -04:00
{name: "Icon", args: Icon(ErrorIcon), want: options{icon: ErrorIcon}},
2022-05-17 11:18:12 -04:00
{name: "Icon", args: Icon("error"), want: options{icon: "error"}},
2022-06-02 07:24:24 -04:00
{name: "Modal", args: Modal(), want: options{modal: true}},
2022-06-28 09:25:19 -04:00
{name: "Attach", args: Attach(zencmd.ParseWindowId("12345")), want: options{attach: zencmd.ParseWindowId("12345")}},
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
2022-12-07 09:35:37 -05:00
{name: "CheckList", args: CheckList(), want: options{listKind: checkListKind}},
{name: "RadioList", args: RadioList(), want: options{listKind: radioListKind}},
2021-07-06 20:54:32 -04:00
{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"}},
2022-12-15 06:26:08 -05:00
{name: "FileFilter", args: FileFilter{"All files", []string{"*.*"}, true}, want: options{
fileFilters: FileFilters{{"All files", []string{"*.*"}, true}},
2021-07-12 20:43:52 -04:00
}},
2022-12-14 22:05:44 -05:00
{name: "FileFilters", args: FileFilters{{"Go files", []string{"*.go"}, true}}, want: options{
fileFilters: FileFilters{{"Go files", []string{"*.go"}, true}},
2021-07-06 20:54:32 -04:00
}},
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
}
})
}
}