54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package zenity_test
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"image/color"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/ncruces/zenity"
|
|
"go.uber.org/goleak"
|
|
)
|
|
|
|
func ExampleSelectColor() {
|
|
zenity.SelectColor(
|
|
zenity.Color(color.NRGBA{R: 0x66, G: 0x33, B: 0x99, A: 0x80}))
|
|
// Output:
|
|
}
|
|
|
|
func ExampleSelectColor_palette() {
|
|
zenity.SelectColor(
|
|
zenity.ShowPalette(),
|
|
zenity.Color(color.NRGBA{R: 0x66, G: 0x33, B: 0x99, A: 0xff}))
|
|
// Output:
|
|
}
|
|
|
|
func TestSelectColor_timeout(t *testing.T) {
|
|
defer goleak.VerifyNone(t)
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second/10)
|
|
defer cancel()
|
|
|
|
_, err := zenity.SelectColor(zenity.Context(ctx))
|
|
if skip, err := skip(err); skip {
|
|
t.Skip("skipping:", err)
|
|
}
|
|
if !os.IsTimeout(err) {
|
|
t.Error("did not timeout:", err)
|
|
}
|
|
}
|
|
|
|
func TestSelectColor_cancel(t *testing.T) {
|
|
defer goleak.VerifyNone(t)
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
cancel()
|
|
|
|
_, err := zenity.SelectColor(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)
|
|
}
|
|
}
|