-
Notifications
You must be signed in to change notification settings - Fork 1
/
opt_test.go
54 lines (39 loc) · 997 Bytes
/
opt_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package gg_test
import (
"testing"
"github.com/mitranim/gg"
"github.com/mitranim/gg/gtest"
)
func TestOpt_MarshalJSON(t *testing.T) {
defer gtest.Catch(t)
type Type = gg.Opt[int]
gtest.Eq(gg.JsonString(gg.Zero[Type]()), `null`)
gtest.Eq(gg.JsonString(Type{Val: 123}), `null`)
gtest.Eq(gg.JsonString(gg.OptVal(123)), `123`)
}
func TestOpt_UnmarshalJSON(t *testing.T) {
defer gtest.Catch(t)
type Type = gg.Opt[int]
gtest.Zero(gg.JsonDecodeTo[Type](`null`))
gtest.Equal(
gg.JsonDecodeTo[Type](`123`),
gg.OptVal(123),
)
}
func BenchmarkOpt_String(b *testing.B) {
val := gg.OptVal(`str`)
for ind := 0; ind < b.N; ind++ {
gg.Nop1(val.String())
}
}
func TestOpt_Scan(t *testing.T) {
defer gtest.Catch(t)
type Type = gg.Opt[float64]
var tar Type
gtest.NoErr(tar.Scan(float64(9.999999682655225e-18)))
gtest.Eq(tar.Val, 9.999999682655225e-18)
tar.Clear()
gtest.Zero(tar)
gtest.NoErr(tar.Scan(`9.999999682655225e-18`))
gtest.Eq(tar.Val, 9.999999682655225e-18)
}