zenity/date_test.go

47 lines
938 B
Go
Raw Permalink Normal View History

2021-04-11 22:02:21 -04:00
package zenity_test
import (
"context"
"errors"
"os"
"testing"
"time"
"github.com/ncruces/zenity"
2022-03-29 09:09:01 -04:00
"go.uber.org/goleak"
2021-04-11 22:02:21 -04:00
)
func ExampleCalendar() {
zenity.Calendar("Select a date from below:",
zenity.DefaultDate(2006, time.January, 1))
// Output:
}
func TestCalendarTimeout(t *testing.T) {
2022-03-29 09:09:01 -04:00
defer goleak.VerifyNone(t)
ctx, cancel := context.WithTimeout(context.Background(), time.Second/5)
defer cancel()
2021-04-11 22:02:21 -04:00
_, err := zenity.Calendar("", zenity.Context(ctx))
2022-03-29 09:09:01 -04:00
if skip, err := skip(err); skip {
t.Skip("skipping:", err)
}
2021-04-11 22:02:21 -04:00
if !os.IsTimeout(err) {
t.Error("did not timeout:", err)
}
}
func TestCalendarCancel(t *testing.T) {
2022-03-29 09:09:01 -04:00
defer goleak.VerifyNone(t)
2021-04-11 22:02:21 -04:00
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, err := zenity.Calendar("", zenity.Context(ctx))
2022-03-29 09:09:01 -04:00
if skip, err := skip(err); skip {
t.Skip("skipping:", err)
}
2021-04-11 22:02:21 -04:00
if !errors.Is(err, context.Canceled) {
t.Error("was not canceled:", err)
}
}