-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptional_test.go
47 lines (43 loc) · 986 Bytes
/
optional_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
package optional
import (
"github.com/ThisIsClark/go-optional"
"testing"
)
func TestOptional_Get(t *testing.T) {
intData := 1
op := optional.Optionalof(intData)
intResData, ok := op.Get().(int)
if !ok {
t.Error("Not a int")
}
if intResData != 1 {
t.Error("want a int 1, got ", intResData)
}
stringData := "TestString"
op = optional.Optionalof(stringData)
stringResData, ok := op.Get().(string)
if !ok {
t.Error("Not a string")
}
if stringResData != "TestString" {
t.Error("want a string \"TestString\", got ", stringResData)
}
}
func TestOptional_IsPresent(t *testing.T) {
intData := 1
op := optional.Optionalof(intData)
if op.IsPresent() != true {
t.Error("op should be present")
}
op = optional.OptionalEmpty()
if op.IsPresent() != false {
t.Error("op should be not present")
}
}
func TestOptional_Equals(t *testing.T) {
intData := 1
op := optional.Optionalof(intData)
if !op.Equals(intData) {
t.Error("op should be equal to intData")
}
}