-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_test.go
69 lines (54 loc) · 1.19 KB
/
map_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
package opt_test
import (
"github.com/reiver/go-opt"
"testing"
)
func TestMap_stringToUint(t *testing.T) {
tests := []struct{
Optional opt.Optional[string]
Expected opt.Optional[int]
}{
{
Optional: opt.Nothing[string](),
Expected: opt.Nothing[int](),
},
{
Optional: opt.Something(""),
Expected: opt.Something[int](0),
},
{
Optional: opt.Something("once"),
Expected: opt.Something[int](4),
},
{
Optional: opt.Something("twice"),
Expected: opt.Something[int](5),
},
{
Optional: opt.Something("thrice"),
Expected: opt.Something[int](6),
},
{
Optional: opt.Something("fource"),
Expected: opt.Something[int](6),
},
}
for testNumber, test := range tests {
fn := func(s string) int {
return len(s)
}
mapped := opt.Map(test.Optional, fn)
{
expected := test.Expected
actual := mapped
if expected != actual {
t.Errorf("For test #%d, the actual value is not what was expected.", testNumber)
t.Logf("EXPECTED: (%T) %#v", expected, expected)
t.Logf("ACTUAL: (%T) %#v", actual, actual)
t.Logf("OPTIONAL: (%T), %#v", test.Optional, test.Optional)
/////////////////////// CONTINUE
continue
}
}
}
}