-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption_test.go
48 lines (40 loc) · 980 Bytes
/
option_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
package fluent
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_OptionFromReference_Empty(t *testing.T) {
var val *string
option := OfNillable(val)
assert.False(t, option.IsPresent())
}
func Test_OptionFromReference_Present(t *testing.T) {
val := "test"
option := OfNillable(&val)
assert.True(t, option.IsPresent())
}
func Test_MapOption_Present(t *testing.T) {
o := Present("a")
var called *bool
called = new(bool)
*called = false
actual := MapOption(o, func(str string) int {
*called = true
return len(str)
})
assert.True(t, actual.IsPresent(), "present")
assert.True(t, *called, "mapper called")
assert.Equal(t, 1, actual.Get())
}
func Test_MapOption_Empty(t *testing.T) {
o := Empty[string]()
var called *bool
called = new(bool)
*called = false
actual := MapOption(o, func(str string) int {
*called = true
return len(str)
})
assert.False(t, actual.IsPresent(), "present")
assert.False(t, *called, "mapper called")
}