-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
list_test.go
135 lines (120 loc) · 3.23 KB
/
list_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package zenity_test
import (
"context"
"errors"
"fmt"
"os"
"reflect"
"testing"
"time"
"github.com/ncruces/zenity"
"go.uber.org/goleak"
)
func ExampleList() {
zenity.List(
"Select items from the list below:",
[]string{"apples", "oranges", "bananas", "strawberries"},
zenity.Title("Select items from the list"),
zenity.DisallowEmpty(),
)
}
func ExampleListItems() {
zenity.ListItems(
"Select items from the list below:",
"apples", "oranges", "bananas", "strawberries")
}
func ExampleListMultiple() {
zenity.ListMultiple(
"Select items from the list below:",
[]string{"apples", "oranges", "bananas", "strawberries"},
zenity.Title("Select items from the list"),
zenity.DefaultItems("apples", "bananas"),
)
}
func ExampleListMultipleItems() {
zenity.ListMultipleItems(
"Select items from the list below:",
"apples", "oranges", "bananas", "strawberries")
}
func TestList_timeout(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
defer goleak.VerifyNone(t)
ctx, cancel := context.WithTimeout(context.Background(), time.Second/5)
defer cancel()
_, err := zenity.List("", []string{""}, zenity.Context(ctx))
if skip, err := skip(err); skip {
t.Skip("skipping:", err)
}
if !os.IsTimeout(err) {
t.Error("did not timeout:", err)
}
}
func TestList_cancel(t *testing.T) {
defer goleak.VerifyNone(t)
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, err := zenity.List("", []string{""}, zenity.Context(ctx))
if skip, err := skip(err); skip {
t.Skip("skipping:", err)
}
if !errors.Is(err, context.Canceled) {
t.Error("was not canceled:", err)
}
}
func TestList_script(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
items := []string{"apples", "oranges", "bananas", "strawberries"}
tests := []struct {
name string
call string
want string
err error
}{
{name: "Cancel", call: "cancel", err: zenity.ErrCanceled},
{name: "Apples", call: "select apples", want: "apples"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := zenity.ListItems(fmt.Sprintf("Please, %s.", tt.call), items...)
if skip, err := skip(err); skip {
t.Skip("skipping:", err)
}
if got != tt.want || err != tt.err {
t.Errorf("List() = %q, %v; want %q, %v", got, err, tt.want, tt.err)
}
})
}
}
func TestListMultiple_script(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
items := []string{"apples", "oranges", "bananas", "strawberries"}
tests := []struct {
name string
call string
want []string
err error
}{
{name: "Cancel", call: "cancel", err: zenity.ErrCanceled},
{name: "Nothing", call: "select nothing", want: []string{}},
{name: "Apples", call: "select apples", want: []string{"apples"}},
{name: "Apples & Oranges", call: "select apples and oranges",
want: []string{"apples", "oranges"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := zenity.ListMultipleItems(fmt.Sprintf("Please, %s.", tt.call), items...)
if skip, err := skip(err); skip {
t.Skip("skipping:", err)
}
if !reflect.DeepEqual(got, tt.want) || err != tt.err {
t.Errorf("ListMultiple() = %q, %v; want %v, %v", got, err, tt.want, tt.err)
}
})
}
}