z_func_4_filetest.gno

4.07 Kb ยท 148 lines
  1package main
  2
  3import (
  4	"errors"
  5	"strings"
  6
  7	"gno.land/p/jeronimoalbi/expect"
  8)
  9
 10var (
 11	output strings.Builder
 12	t      = expect.MockTestingT(&output)
 13)
 14
 15func main() {
 16	expect.Func(t, func() any { return "foo" }).ToReturn("bar")
 17	expect.Func(t, func() any { return []byte("foo") }).ToReturn([]byte("bar"))
 18	expect.Func(t, func() any { return true }).ToReturn(false)
 19	expect.Func(t, func() any { return float32(1) }).ToReturn(float32(2))
 20	expect.Func(t, func() any { return float64(1.1) }).ToReturn(float64(1.2))
 21	expect.Func(t, func() any { return uint(1) }).ToReturn(uint(2))
 22	expect.Func(t, func() any { return uint8(1) }).ToReturn(uint8(2))
 23	expect.Func(t, func() any { return uint16(1) }).ToReturn(uint16(2))
 24	expect.Func(t, func() any { return uint32(1) }).ToReturn(uint32(2))
 25	expect.Func(t, func() any { return uint64(1) }).ToReturn(uint64(2))
 26	expect.Func(t, func() any { return int(1) }).ToReturn(int(2))
 27	expect.Func(t, func() any { return int8(1) }).ToReturn(int8(2))
 28	expect.Func(t, func() any { return int16(1) }).ToReturn(int16(2))
 29	expect.Func(t, func() any { return int32(1) }).ToReturn(int32(2))
 30	expect.Func(t, func() any { return int64(1) }).ToReturn(int64(2))
 31
 32	expect.Func(t, func() (any, error) { return "foo", nil }).ToReturn("bar")
 33	expect.Func(t, func() (any, error) { return []byte("foo"), nil }).ToReturn([]byte("bar"))
 34	expect.Func(t, func() (any, error) { return true, nil }).ToReturn(false)
 35	expect.Func(t, func() (any, error) { return float32(1), nil }).ToReturn(float32(2))
 36	expect.Func(t, func() (any, error) { return float64(1.1), nil }).ToReturn(float64(1.2))
 37	expect.Func(t, func() (any, error) { return uint(1), nil }).ToReturn(uint(2))
 38	expect.Func(t, func() (any, error) { return uint8(1), nil }).ToReturn(uint8(2))
 39	expect.Func(t, func() (any, error) { return uint16(1), nil }).ToReturn(uint16(2))
 40	expect.Func(t, func() (any, error) { return uint32(1), nil }).ToReturn(uint32(2))
 41	expect.Func(t, func() (any, error) { return uint64(1), nil }).ToReturn(uint64(2))
 42	expect.Func(t, func() (any, error) { return int(1), nil }).ToReturn(int(2))
 43	expect.Func(t, func() (any, error) { return int8(1), nil }).ToReturn(int8(2))
 44	expect.Func(t, func() (any, error) { return int16(1), nil }).ToReturn(int16(2))
 45	expect.Func(t, func() (any, error) { return int32(1), nil }).ToReturn(int32(2))
 46	expect.Func(t, func() (any, error) { return int64(1), nil }).ToReturn(int64(2))
 47
 48	expect.Func(t, func() (any, error) { return 0, errors.New("Boom!") }).ToReturn(1)
 49	expect.Func(t, func() {}).ToReturn(1)
 50
 51	println(output.String())
 52}
 53
 54// Output:
 55// Expected values to match
 56// Got: foo
 57// Want: bar
 58// Expected values to match
 59// Got: foo
 60// Want: bar
 61// Expected values to match
 62// Got: true
 63// Want: false
 64// Expected values to match
 65// Got: 1
 66// Want: 2
 67// Expected values to match
 68// Got: 1.1
 69// Want: 1.2
 70// Expected values to match
 71// Got: 1
 72// Want: 2
 73// Expected values to match
 74// Got: 1
 75// Want: 2
 76// Expected values to match
 77// Got: 1
 78// Want: 2
 79// Expected values to match
 80// Got: 1
 81// Want: 2
 82// Expected values to match
 83// Got: 1
 84// Want: 2
 85// Expected values to match
 86// Got: 1
 87// Want: 2
 88// Expected values to match
 89// Got: 1
 90// Want: 2
 91// Expected values to match
 92// Got: 1
 93// Want: 2
 94// Expected values to match
 95// Got: 1
 96// Want: 2
 97// Expected values to match
 98// Got: 1
 99// Want: 2
100// Expected values to match
101// Got: foo
102// Want: bar
103// Expected values to match
104// Got: foo
105// Want: bar
106// Expected values to match
107// Got: true
108// Want: false
109// Expected values to match
110// Got: 1
111// Want: 2
112// Expected values to match
113// Got: 1.1
114// Want: 1.2
115// Expected values to match
116// Got: 1
117// Want: 2
118// Expected values to match
119// Got: 1
120// Want: 2
121// Expected values to match
122// Got: 1
123// Want: 2
124// Expected values to match
125// Got: 1
126// Want: 2
127// Expected values to match
128// Got: 1
129// Want: 2
130// Expected values to match
131// Got: 1
132// Want: 2
133// Expected values to match
134// Got: 1
135// Want: 2
136// Expected values to match
137// Got: 1
138// Want: 2
139// Expected values to match
140// Got: 1
141// Want: 2
142// Expected values to match
143// Got: 1
144// Want: 2
145// Function returned unexpected error
146// Got: Boom!
147// Unsupported func type
148// Got: unknown