-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvar_test.go
84 lines (74 loc) · 1.69 KB
/
var_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package gisp
import (
"testing"
)
func TestOptionSet(t *testing.T) {
var slot = DefOption(INT)
slot.Set(Int(10))
t.Logf("create a new var %v slot as %v", slot.Type(), slot.Get())
}
func TestOptionSetNil(t *testing.T) {
var slot = DefOption(INT)
slot.Set(nil)
t.Logf("create a new var %v slot as %v", slot.Type(), slot.Get())
}
func TestOptionGetNil(t *testing.T) {
var slot = DefOption(INT)
val := slot.Get()
if val != nil {
t.Fatalf("except nil but %v", val)
}
}
func TestOptionGetNilType(t *testing.T) {
var slot = DefOption(INT)
typ := slot.Type()
if typ != INT {
t.Fatalf("except INT type but %v", typ)
}
}
func TestOptionSetValid(t *testing.T) {
defer func() {
if re := recover(); re == nil {
t.Fatal("excpet a panic when set a int to a float value")
}
}()
var slot = DefOption(FLOAT)
slot.Set(Int(34))
}
func TestStrictSet(t *testing.T) {
var slot = DefStrict(INT)
slot.Set(Int(10))
t.Logf("create a new var %v slot as %v", slot.Type(), slot.Get())
}
func TestStrictSetNil(t *testing.T) {
defer func() {
if re := recover(); re == nil {
t.Fatal("excpet a panic when set nil to a strict value not pointer")
}
}()
var slot = DefStrict(INT)
slot.Set(nil)
}
func TestStrictGetNil(t *testing.T) {
var slot = DefStrict(INT)
val := slot.Get()
if val == nil {
t.Fatal("except zero value when init but nil")
}
}
func TestStrictGetNilType(t *testing.T) {
var slot = DefStrict(INT)
typ := slot.Type()
if typ != INT {
t.Fatalf("except INT type but %v", typ)
}
}
func TestStrictSetValid(t *testing.T) {
defer func() {
if re := recover(); re == nil {
t.Fatal("excpet a panic when set a int to a float value")
}
}()
var slot = DefStrict(FLOAT)
slot.Set(Int(34))
}