-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoption_test.go
More file actions
48 lines (36 loc) · 860 Bytes
/
option_test.go
File metadata and controls
48 lines (36 loc) · 860 Bytes
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
package types
import "testing"
func TestOption(t *testing.T) {
if res := Some(123); res.IsSome() {
t.Log("the result is", res.Unwrap())
} else {
panic("result should be some")
}
if res := None[int](); res.IsNone() {
t.Log("the result is none")
} else {
panic("result should be none")
}
if res := Some(123); res.IsSome() {
t.Log("the result is", res.Unwrap())
take := res.Take()
t.Log("the result is", take.Unwrap())
t.Log("the result is", res.IsNone())
} else {
panic("result should be some")
}
res := Some(456)
t.Log("the result is", res.Unwrap())
res2 := res.Replace(789)
t.Log("the result is", res2.Unwrap())
if res.Unwrap() != 789 {
panic("result should be 789")
}
if res2.Unwrap() != 456 {
panic("result should be 456")
}
res2 = Some(789)
if res2.Unwrap() != 789 {
panic("result should be 789")
}
}