@@ -39,14 +39,36 @@ func TestValidateAsyncFuncs(t *testing.T) {
3939 }, ErrNotFunction )
4040}
4141
42- func TestIsFuncTakesContext (t * testing.T ) {
42+ func TestIsFuncTakesContexts (t * testing.T ) {
4343 a := assert .New (t )
4444
45- a .TrueNow (isFuncTakesContext (reflect .TypeOf (func (context.Context ) {})))
46- a .TrueNow (isFuncTakesContext (reflect .TypeOf (func (context.Context , int ) {})))
47- a .NotTrueNow (isFuncTakesContext (reflect .TypeOf (func () {})))
48- a .NotTrueNow (isFuncTakesContext (reflect .TypeOf (func (int ) {})))
49- a .NotTrueNow (isFuncTakesContext (reflect .TypeOf (func (int , context.Context ) {})))
45+ isTakeContext , contextNum := isFuncTakesContexts (reflect .TypeOf (func (context.Context ) {}))
46+ a .TrueNow (isTakeContext )
47+ a .EqualNow (contextNum , 1 )
48+
49+ isTakeContext , contextNum = isFuncTakesContexts (reflect .TypeOf (func (context.Context , int ) {}))
50+ a .TrueNow (isTakeContext )
51+ a .EqualNow (contextNum , 1 )
52+
53+ isTakeContext , contextNum = isFuncTakesContexts (reflect .TypeOf (func (context.Context , context.Context , int ) {}))
54+ a .TrueNow (isTakeContext )
55+ a .EqualNow (contextNum , 2 )
56+
57+ isTakeContext , contextNum = isFuncTakesContexts (reflect .TypeOf (func (context.Context , int , context.Context ) {}))
58+ a .TrueNow (isTakeContext )
59+ a .EqualNow (contextNum , 1 )
60+
61+ isTakeContext , contextNum = isFuncTakesContexts (reflect .TypeOf (func () {}))
62+ a .NotTrueNow (isTakeContext )
63+ a .EqualNow (contextNum , 0 )
64+
65+ isTakeContext , contextNum = isFuncTakesContexts (reflect .TypeOf (func (int ) {}))
66+ a .NotTrueNow (isTakeContext )
67+ a .EqualNow (contextNum , 0 )
68+
69+ isTakeContext , contextNum = isFuncTakesContexts (reflect .TypeOf (func (int , context.Context ) {}))
70+ a .NotTrueNow (isTakeContext )
71+ a .EqualNow (contextNum , 0 )
5072}
5173
5274func TestIsFuncReturnsError (t * testing.T ) {
0 commit comments