zenity/color_test.go

47 lines
898 B
Go
Raw Normal View History

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"
)
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
func TestSelectColorTimeout(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second/10)
_, err := zenity.SelectColor(zenity.Context(ctx))
if !os.IsTimeout(err) {
t.Error("did not timeout", err)
}
cancel()
}
func TestSelectColorCancel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, err := zenity.SelectColor(zenity.Context(ctx))
if !errors.Is(err, context.Canceled) {
t.Error("not canceled", err)
}
}