zenity/list_test.go

69 lines
1.4 KiB
Go
Raw Normal View History

2021-04-07 09:16:35 -04:00
package zenity_test
import (
"context"
"errors"
"os"
"testing"
"time"
"github.com/ncruces/zenity"
2021-04-30 14:19:14 -04:00
"go.uber.org/goleak"
2021-04-07 09:16:35 -04:00
)
func ExampleList() {
zenity.List(
"Select items from the list below:",
[]string{"apples", "oranges", "bananas", "strawberries"},
zenity.Title("Select items from the list"),
zenity.DisallowEmpty(),
)
// Output:
}
func ExampleListItems() {
zenity.ListItems(
"Select items from the list below:",
"apples", "oranges", "bananas", "strawberries")
// Output:
}
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"),
)
// Output:
}
func ExampleListMultipleItems() {
zenity.ListMultipleItems(
"Select items from the list below:",
"apples", "oranges", "bananas", "strawberries")
// Output:
}
2021-04-30 14:19:14 -04:00
func TestList_timeout(t *testing.T) {
defer goleak.VerifyNone(t)
2021-04-07 09:16:35 -04:00
ctx, cancel := context.WithTimeout(context.Background(), time.Second/10)
2021-04-30 14:19:14 -04:00
defer cancel()
2021-04-07 09:16:35 -04:00
2021-04-29 11:05:28 -04:00
_, err := zenity.List("", nil, zenity.Context(ctx))
2021-04-07 09:16:35 -04:00
if !os.IsTimeout(err) {
t.Error("did not timeout:", err)
}
}
2021-04-30 14:19:14 -04:00
func TestList_cancel(t *testing.T) {
defer goleak.VerifyNone(t)
2021-04-07 09:16:35 -04:00
ctx, cancel := context.WithCancel(context.Background())
cancel()
2021-04-29 11:05:28 -04:00
_, err := zenity.List("", nil, zenity.Context(ctx))
2021-04-07 09:16:35 -04:00
if !errors.Is(err, context.Canceled) {
t.Error("was not canceled:", err)
}
}