2020-01-18 07:40:16 -05:00
|
|
|
package zenity_test
|
|
|
|
|
|
|
|
import (
|
2020-01-29 06:09:06 -05:00
|
|
|
"context"
|
|
|
|
"errors"
|
2020-01-18 07:40:16 -05:00
|
|
|
"image/color"
|
2020-01-29 06:09:06 -05:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
2020-01-18 07:40:16 -05:00
|
|
|
|
|
|
|
"github.com/ncruces/zenity"
|
2021-04-30 14:19:14 -04:00
|
|
|
"go.uber.org/goleak"
|
2020-01-18 07:40:16 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func ExampleSelectColor() {
|
|
|
|
zenity.SelectColor(
|
2020-01-21 11:13:45 -05:00
|
|
|
zenity.Color(color.NRGBA{R: 0x66, G: 0x33, B: 0x99, A: 0x80}))
|
2020-01-18 07:40:16 -05:00
|
|
|
// Output:
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExampleSelectColor_palette() {
|
|
|
|
zenity.SelectColor(
|
|
|
|
zenity.ShowPalette(),
|
2020-01-21 11:13:45 -05:00
|
|
|
zenity.Color(color.NRGBA{R: 0x66, G: 0x33, B: 0x99, A: 0xff}))
|
2020-01-18 07:40:16 -05:00
|
|
|
// Output:
|
|
|
|
}
|
2020-01-29 06:09:06 -05:00
|
|
|
|
2021-04-30 14:19:14 -04:00
|
|
|
func TestSelectColor_timeout(t *testing.T) {
|
|
|
|
defer goleak.VerifyNone(t)
|
2020-01-29 06:09:06 -05:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second/10)
|
2021-04-30 14:19:14 -04:00
|
|
|
defer cancel()
|
2020-01-29 06:09:06 -05:00
|
|
|
|
|
|
|
_, err := zenity.SelectColor(zenity.Context(ctx))
|
|
|
|
if !os.IsTimeout(err) {
|
2020-01-29 09:15:21 -05:00
|
|
|
t.Error("did not timeout:", err)
|
2020-01-29 06:09:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-30 14:19:14 -04:00
|
|
|
func TestSelectColor_cancel(t *testing.T) {
|
|
|
|
defer goleak.VerifyNone(t)
|
2020-01-29 06:09:06 -05:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
cancel()
|
|
|
|
|
|
|
|
_, err := zenity.SelectColor(zenity.Context(ctx))
|
|
|
|
if !errors.Is(err, context.Canceled) {
|
2020-01-29 09:15:21 -05:00
|
|
|
t.Error("was not canceled:", err)
|
2020-01-29 06:09:06 -05:00
|
|
|
}
|
|
|
|
}
|