Skip to content

Commit d1b999f

Browse files
committed
tests: raw tests for bool
1 parent 4bc0d28 commit d1b999f

File tree

5 files changed

+407
-0
lines changed

5 files changed

+407
-0
lines changed

bool_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package option_test
2+
3+
import (
4+
"bytes"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
"github.com/vmihailenco/msgpack/v5"
10+
11+
"github.com/tarantool/go-option"
12+
)
13+
14+
func TestOptionalBool(t *testing.T) {
15+
var buf bytes.Buffer
16+
enc := msgpack.NewEncoder(&buf)
17+
dec := msgpack.NewDecoder(&buf)
18+
19+
someBool := option.SomeBool(true)
20+
assert.True(t, someBool.IsSome(), "Expected IsPresent() to return true")
21+
require.NoError(t, someBool.EncodeMsgpack(enc))
22+
23+
var shouldBeSomeBool option.OptionalBool
24+
require.NoError(t, shouldBeSomeBool.DecodeMsgpack(dec))
25+
assert.True(t, shouldBeSomeBool.IsSome(), "Expected IsPresent() to return true")
26+
assert.Equal(t, someBool.Unwrap(), shouldBeSomeBool.Unwrap(), "Expected Value() to return the same value")
27+
28+
emptyBool := option.NoneBool()
29+
assert.False(t, emptyBool.IsSome(), "Expected IsPresent() to return false")
30+
require.NoError(t, emptyBool.EncodeMsgpack(enc))
31+
32+
var shouldBeEmptyBool option.OptionalBool
33+
require.NoError(t, shouldBeEmptyBool.DecodeMsgpack(dec))
34+
assert.False(t, shouldBeEmptyBool.IsSome(), "Expected IsPresent() to return false")
35+
}

bytes_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package option_test
2+
3+
import (
4+
"bytes"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
"github.com/vmihailenco/msgpack/v5"
10+
11+
"github.com/tarantool/go-option"
12+
)
13+
14+
func TestOptionalBytes(t *testing.T) {
15+
var buf bytes.Buffer
16+
enc := msgpack.NewEncoder(&buf)
17+
dec := msgpack.NewDecoder(&buf)
18+
19+
someBytes := option.SomeBytes([]byte("1234"))
20+
assert.True(t, someBytes.IsSome(), "Expected IsPresent() to return true")
21+
require.NoError(t, someBytes.EncodeMsgpack(enc))
22+
23+
var shouldBeSomeBytes option.OptionalBytes
24+
require.NoError(t, shouldBeSomeBytes.DecodeMsgpack(dec))
25+
assert.True(t, shouldBeSomeBytes.IsSome(), "Expected IsPresent() to return true")
26+
assert.EqualValues(t, someBytes.Unwrap(), shouldBeSomeBytes.Unwrap(), "Expected Value() to return the same value")
27+
28+
emptyBytes := option.NoneBytes()
29+
assert.False(t, emptyBytes.IsSome(), "Expected IsPresent() to return false")
30+
require.NoError(t, emptyBytes.EncodeMsgpack(enc))
31+
32+
var shouldBeEmptyBytes option.OptionalBytes
33+
require.NoError(t, shouldBeEmptyBytes.DecodeMsgpack(dec))
34+
assert.False(t, shouldBeEmptyBytes.IsSome(), "Expected IsPresent() to return false")
35+
}

float_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package option_test
2+
3+
import (
4+
"bytes"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
"github.com/vmihailenco/msgpack/v5"
10+
11+
"github.com/tarantool/go-option"
12+
)
13+
14+
func TestOptionalFloat32(t *testing.T) {
15+
var buf bytes.Buffer
16+
enc := msgpack.NewEncoder(&buf)
17+
dec := msgpack.NewDecoder(&buf)
18+
19+
someFloat32 := option.SomeFloat32(3.11)
20+
assert.True(t, someFloat32.IsSome(), "Expected IsPresent() to return true")
21+
require.NoError(t, someFloat32.EncodeMsgpack(enc))
22+
23+
var shouldBeSomeFloat32 option.OptionalFloat32
24+
require.NoError(t, shouldBeSomeFloat32.DecodeMsgpack(dec))
25+
assert.True(t, shouldBeSomeFloat32.IsSome(), "Expected IsPresent() to return true")
26+
assert.Equal(t, someFloat32.Unwrap(), shouldBeSomeFloat32.Unwrap(), "Expected Value() to return the same value")
27+
28+
emptyFloat32 := option.NoneFloat32()
29+
assert.False(t, emptyFloat32.IsSome(), "Expected IsPresent() to return false")
30+
require.NoError(t, emptyFloat32.EncodeMsgpack(enc))
31+
32+
var shouldBeEmptyFloat32 option.OptionalFloat32
33+
require.NoError(t, shouldBeEmptyFloat32.DecodeMsgpack(dec))
34+
assert.False(t, shouldBeEmptyFloat32.IsSome(), "Expected IsPresent() to return false")
35+
}
36+
37+
func TestOptionalFloat64(t *testing.T) {
38+
var buf bytes.Buffer
39+
enc := msgpack.NewEncoder(&buf)
40+
dec := msgpack.NewDecoder(&buf)
41+
42+
someFloat64 := option.SomeFloat64(3.11)
43+
assert.True(t, someFloat64.IsSome(), "Expected IsPresent() to return true")
44+
require.NoError(t, someFloat64.EncodeMsgpack(enc))
45+
46+
var shouldBeSomeFloat64 option.OptionalFloat64
47+
require.NoError(t, shouldBeSomeFloat64.DecodeMsgpack(dec))
48+
assert.True(t, shouldBeSomeFloat64.IsSome(), "Expected IsPresent() to return true")
49+
assert.Equal(t, someFloat64.Unwrap(), shouldBeSomeFloat64.Unwrap(), "Expected Value() to return the same value")
50+
51+
emptyFloat64 := option.NoneFloat64()
52+
assert.False(t, emptyFloat64.IsSome(), "Expected IsPresent() to return false")
53+
require.NoError(t, emptyFloat64.EncodeMsgpack(enc))
54+
55+
var shouldBeEmptyFloat64 option.OptionalFloat64
56+
require.NoError(t, shouldBeEmptyFloat64.DecodeMsgpack(dec))
57+
assert.False(t, shouldBeEmptyFloat64.IsSome(), "Expected IsPresent() to return false")
58+
}

number_test.go

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
package option_test
2+
3+
import (
4+
"bytes"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
"github.com/vmihailenco/msgpack/v5"
10+
11+
"github.com/tarantool/go-option"
12+
)
13+
14+
func TestOptionalInt(t *testing.T) {
15+
var buf bytes.Buffer
16+
enc := msgpack.NewEncoder(&buf)
17+
dec := msgpack.NewDecoder(&buf)
18+
19+
someInt := option.SomeInt(123)
20+
assert.True(t, someInt.IsSome(), "Expected IsPresent() to return true")
21+
require.NoError(t, someInt.EncodeMsgpack(enc))
22+
23+
var shouldBeSomeInt option.OptionalInt
24+
require.NoError(t, shouldBeSomeInt.DecodeMsgpack(dec))
25+
assert.True(t, shouldBeSomeInt.IsSome(), "Expected IsPresent() to return true")
26+
assert.Equal(t, someInt.Unwrap(), shouldBeSomeInt.Unwrap(), "Expected Value() to return the same value")
27+
28+
emptyInt := option.NoneInt()
29+
assert.False(t, emptyInt.IsSome(), "Expected IsPresent() to return false")
30+
require.NoError(t, emptyInt.EncodeMsgpack(enc))
31+
32+
var shouldBeEmptyInt option.OptionalInt
33+
require.NoError(t, shouldBeEmptyInt.DecodeMsgpack(dec))
34+
assert.False(t, shouldBeEmptyInt.IsSome(), "Expected IsPresent() to return false")
35+
36+
}
37+
38+
func TestOptionalInt8(t *testing.T) {
39+
var buf bytes.Buffer
40+
enc := msgpack.NewEncoder(&buf)
41+
dec := msgpack.NewDecoder(&buf)
42+
43+
someInt8 := option.SomeInt8(123)
44+
assert.True(t, someInt8.IsSome(), "Expected IsPresent() to return true")
45+
require.NoError(t, someInt8.EncodeMsgpack(enc))
46+
47+
var shouldBeSomeInt8 option.OptionalInt8
48+
require.NoError(t, shouldBeSomeInt8.DecodeMsgpack(dec))
49+
assert.True(t, shouldBeSomeInt8.IsSome(), "Expected IsPresent() to return true")
50+
assert.Equal(t, someInt8.Unwrap(), shouldBeSomeInt8.Unwrap(), "Expected Value() to return the same value")
51+
52+
emptyInt8 := option.NoneInt8()
53+
assert.False(t, emptyInt8.IsSome(), "Expected IsPresent() to return false")
54+
require.NoError(t, emptyInt8.EncodeMsgpack(enc))
55+
56+
var shouldBeEmptyInt8 option.OptionalInt8
57+
require.NoError(t, shouldBeEmptyInt8.DecodeMsgpack(dec))
58+
assert.False(t, shouldBeEmptyInt8.IsSome(), "Expected IsPresent() to return false")
59+
}
60+
61+
func TestOptionalInt16(t *testing.T) {
62+
var buf bytes.Buffer
63+
enc := msgpack.NewEncoder(&buf)
64+
dec := msgpack.NewDecoder(&buf)
65+
66+
someInt16 := option.SomeInt16(123)
67+
assert.True(t, someInt16.IsSome(), "Expected IsPresent() to return true")
68+
require.NoError(t, someInt16.EncodeMsgpack(enc))
69+
70+
var shouldBeSomeInt16 option.OptionalInt16
71+
require.NoError(t, shouldBeSomeInt16.DecodeMsgpack(dec))
72+
assert.True(t, shouldBeSomeInt16.IsSome(), "Expected IsPresent() to return true")
73+
assert.Equal(t, someInt16.Unwrap(), shouldBeSomeInt16.Unwrap(), "Expected Value() to return the same value")
74+
75+
emptyInt16 := option.NoneInt16()
76+
assert.False(t, emptyInt16.IsSome(), "Expected IsPresent() to return false")
77+
require.NoError(t, emptyInt16.EncodeMsgpack(enc))
78+
79+
var shouldBeEmptyInt16 option.OptionalInt16
80+
require.NoError(t, shouldBeEmptyInt16.DecodeMsgpack(dec))
81+
assert.False(t, shouldBeEmptyInt16.IsSome(), "Expected IsPresent() to return false")
82+
}
83+
84+
func TestOptionalInt32(t *testing.T) {
85+
var buf bytes.Buffer
86+
enc := msgpack.NewEncoder(&buf)
87+
dec := msgpack.NewDecoder(&buf)
88+
89+
someInt32 := option.SomeInt32(123)
90+
assert.True(t, someInt32.IsSome(), "Expected IsPresent() to return true")
91+
require.NoError(t, someInt32.EncodeMsgpack(enc))
92+
93+
var shouldBeSomeInt32 option.OptionalInt32
94+
require.NoError(t, shouldBeSomeInt32.DecodeMsgpack(dec))
95+
assert.True(t, shouldBeSomeInt32.IsSome(), "Expected IsPresent() to return true")
96+
assert.Equal(t, someInt32.Unwrap(), shouldBeSomeInt32.Unwrap(), "Expected Value() to return the same value")
97+
98+
emptyInt32 := option.NoneInt32()
99+
assert.False(t, emptyInt32.IsSome(), "Expected IsPresent() to return false")
100+
require.NoError(t, emptyInt32.EncodeMsgpack(enc))
101+
102+
var shouldBeEmptyInt32 option.OptionalInt32
103+
require.NoError(t, shouldBeEmptyInt32.DecodeMsgpack(dec))
104+
assert.False(t, shouldBeEmptyInt32.IsSome(), "Expected IsPresent() to return false")
105+
}
106+
107+
func TestOptionalInt64(t *testing.T) {
108+
var buf bytes.Buffer
109+
enc := msgpack.NewEncoder(&buf)
110+
dec := msgpack.NewDecoder(&buf)
111+
112+
someInt64 := option.SomeInt64(123)
113+
assert.True(t, someInt64.IsSome(), "Expected IsPresent() to return true")
114+
require.NoError(t, someInt64.EncodeMsgpack(enc))
115+
116+
var shouldBeSomeInt64 option.OptionalInt64
117+
require.NoError(t, shouldBeSomeInt64.DecodeMsgpack(dec))
118+
assert.True(t, shouldBeSomeInt64.IsSome(), "Expected IsPresent() to return true")
119+
assert.Equal(t, someInt64.Unwrap(), shouldBeSomeInt64.Unwrap(), "Expected Value() to return the same value")
120+
121+
emptyInt64 := option.NoneInt64()
122+
assert.False(t, emptyInt64.IsSome(), "Expected IsPresent() to return false")
123+
require.NoError(t, emptyInt64.EncodeMsgpack(enc))
124+
125+
var shouldBeEmptyInt64 option.OptionalInt64
126+
require.NoError(t, shouldBeEmptyInt64.DecodeMsgpack(dec))
127+
assert.False(t, shouldBeEmptyInt64.IsSome(), "Expected IsPresent() to return false")
128+
}
129+
130+
func TestOptionalUint(t *testing.T) {
131+
var buf bytes.Buffer
132+
enc := msgpack.NewEncoder(&buf)
133+
dec := msgpack.NewDecoder(&buf)
134+
135+
someUint := option.SomeUint(123)
136+
assert.True(t, someUint.IsSome(), "Expected IsPresent() to return true")
137+
require.NoError(t, someUint.EncodeMsgpack(enc))
138+
139+
var shouldBeSomeUint option.OptionalUint
140+
require.NoError(t, shouldBeSomeUint.DecodeMsgpack(dec))
141+
assert.True(t, shouldBeSomeUint.IsSome(), "Expected IsPresent() to return true")
142+
assert.Equal(t, someUint.Unwrap(), shouldBeSomeUint.Unwrap(), "Expected Value() to return the same value")
143+
144+
emptyUint := option.NoneUint()
145+
assert.False(t, emptyUint.IsSome(), "Expected IsPresent() to return false")
146+
require.NoError(t, emptyUint.EncodeMsgpack(enc))
147+
148+
var shouldBeEmptyUint option.OptionalUint
149+
require.NoError(t, shouldBeEmptyUint.DecodeMsgpack(dec))
150+
assert.False(t, shouldBeEmptyUint.IsSome(), "Expected IsPresent() to return false")
151+
}
152+
153+
func TestOptionalUint8(t *testing.T) {
154+
var buf bytes.Buffer
155+
enc := msgpack.NewEncoder(&buf)
156+
dec := msgpack.NewDecoder(&buf)
157+
158+
someUint8 := option.SomeUint8(123)
159+
assert.True(t, someUint8.IsSome(), "Expected IsPresent() to return true")
160+
require.NoError(t, someUint8.EncodeMsgpack(enc))
161+
162+
var shouldBeSomeUint8 option.OptionalUint8
163+
require.NoError(t, shouldBeSomeUint8.DecodeMsgpack(dec))
164+
assert.True(t, shouldBeSomeUint8.IsSome(), "Expected IsPresent() to return true")
165+
assert.Equal(t, someUint8.Unwrap(), shouldBeSomeUint8.Unwrap(), "Expected Value() to return the same value")
166+
167+
emptyUint8 := option.NoneUint8()
168+
assert.False(t, emptyUint8.IsSome(), "Expected IsPresent() to return false")
169+
require.NoError(t, emptyUint8.EncodeMsgpack(enc))
170+
171+
var shouldBeEmptyUint8 option.OptionalUint8
172+
require.NoError(t, shouldBeEmptyUint8.DecodeMsgpack(dec))
173+
assert.False(t, shouldBeEmptyUint8.IsSome(), "Expected IsPresent() to return false")
174+
}
175+
176+
func TestOptionalUint16(t *testing.T) {
177+
var buf bytes.Buffer
178+
enc := msgpack.NewEncoder(&buf)
179+
dec := msgpack.NewDecoder(&buf)
180+
181+
someUint16 := option.SomeUint16(123)
182+
assert.True(t, someUint16.IsSome(), "Expected IsPresent() to return true")
183+
require.NoError(t, someUint16.EncodeMsgpack(enc))
184+
185+
var shouldBeSomeUint16 option.OptionalUint16
186+
require.NoError(t, shouldBeSomeUint16.DecodeMsgpack(dec))
187+
assert.True(t, shouldBeSomeUint16.IsSome(), "Expected IsPresent() to return true")
188+
assert.Equal(t, someUint16.Unwrap(), shouldBeSomeUint16.Unwrap(), "Expected Value() to return the same value")
189+
190+
emptyUint16 := option.NoneUint16()
191+
assert.False(t, emptyUint16.IsSome(), "Expected IsPresent() to return false")
192+
require.NoError(t, emptyUint16.EncodeMsgpack(enc))
193+
194+
var shouldBeEmptyUint16 option.OptionalUint16
195+
require.NoError(t, shouldBeEmptyUint16.DecodeMsgpack(dec))
196+
assert.False(t, shouldBeEmptyUint16.IsSome(), "Expected IsPresent() to return false")
197+
}
198+
199+
func TestOptionalUint32(t *testing.T) {
200+
var buf bytes.Buffer
201+
enc := msgpack.NewEncoder(&buf)
202+
dec := msgpack.NewDecoder(&buf)
203+
204+
someUint32 := option.SomeUint32(123)
205+
assert.True(t, someUint32.IsSome(), "Expected IsPresent() to return true")
206+
require.NoError(t, someUint32.EncodeMsgpack(enc))
207+
208+
var shouldBeSomeUint32 option.OptionalUint32
209+
require.NoError(t, shouldBeSomeUint32.DecodeMsgpack(dec))
210+
assert.True(t, shouldBeSomeUint32.IsSome(), "Expected IsPresent() to return true")
211+
assert.Equal(t, someUint32.Unwrap(), shouldBeSomeUint32.Unwrap(), "Expected Value() to return the same value")
212+
213+
emptyUint32 := option.NoneUint32()
214+
assert.False(t, emptyUint32.IsSome(), "Expected IsPresent() to return false")
215+
require.NoError(t, emptyUint32.EncodeMsgpack(enc))
216+
217+
var shouldBeEmptyUint32 option.OptionalUint32
218+
require.NoError(t, shouldBeEmptyUint32.DecodeMsgpack(dec))
219+
assert.False(t, shouldBeEmptyUint32.IsSome(), "Expected IsPresent() to return false")
220+
}
221+
222+
func TestOptionalUint64(t *testing.T) {
223+
var buf bytes.Buffer
224+
enc := msgpack.NewEncoder(&buf)
225+
dec := msgpack.NewDecoder(&buf)
226+
227+
someUint64 := option.SomeUint64(123)
228+
assert.True(t, someUint64.IsSome(), "Expected IsPresent() to return true")
229+
require.NoError(t, someUint64.EncodeMsgpack(enc))
230+
231+
var shouldBeSomeUint64 option.OptionalUint64
232+
require.NoError(t, shouldBeSomeUint64.DecodeMsgpack(dec))
233+
assert.True(t, shouldBeSomeUint64.IsSome(), "Expected IsPresent() to return true")
234+
assert.Equal(t, someUint64.Unwrap(), shouldBeSomeUint64.Unwrap(), "Expected Value() to return the same value")
235+
236+
emptyUint64 := option.NoneUint64()
237+
assert.False(t, emptyUint64.IsSome(), "Expected IsPresent() to return false")
238+
require.NoError(t, emptyUint64.EncodeMsgpack(enc))
239+
240+
var shouldBeEmptyUint64 option.OptionalUint64
241+
require.NoError(t, shouldBeEmptyUint64.DecodeMsgpack(dec))
242+
assert.False(t, shouldBeEmptyUint64.IsSome(), "Expected IsPresent() to return false")
243+
}

0 commit comments

Comments
 (0)