github.com/timandy/routine@v1.1.4-0.20240507073150-e4a3e1fe2ba5/api_future_task_test.go (about) 1 package routine 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestFutureCallable(t *testing.T) { 10 var futureCallable FutureCallable[string] = func(task FutureTask[string]) string { 11 return "Hello" 12 } 13 assert.Equal(t, "Hello", futureCallable(nil)) 14 // 15 var fun func(FutureTask[string]) string = futureCallable 16 assert.Equal(t, "Hello", fun(nil)) 17 } 18 19 func TestCancelToken(t *testing.T) { 20 task := NewFutureTask[any](func(task FutureTask[any]) any { return nil }) 21 token, ok := task.(CancelToken) 22 assert.Same(t, task, token) 23 assert.True(t, ok) 24 } 25 26 func TestNewFutureTask(t *testing.T) { 27 assert.Panics(t, func() { 28 NewFutureTask[any](nil) 29 }) 30 // 31 task := NewFutureTask[any](func(task FutureTask[any]) any { return nil }) 32 assert.NotNil(t, task) 33 // 34 p, ok := task.(*futureTask[any]) 35 assert.Same(t, p, task) 36 assert.True(t, ok) 37 }