-
Notifications
You must be signed in to change notification settings - Fork 3
/
logic_test.go
47 lines (39 loc) · 1.38 KB
/
logic_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 gocast
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestLogic(t *testing.T) {
t.Run("Or", func(t *testing.T) {
assert.Equal(t, 1, Or(1, 2, 3))
assert.Equal(t, 2, Or[any](nil, 2, 3))
assert.Equal(t, 3, Or[any](nil, nil, 3))
assert.Equal(t, "a", Or[any](nil, nil, "a"))
assert.Equal(t, "a", Or[any](nil, "a", nil))
assert.Equal(t, "a", Or[any]("a", nil, nil))
assert.Equal(t, "a", Or[any]("a", "b", nil))
assert.Equal(t, "a", Or[any]("a", nil, "b"))
assert.Equal(t, "a", Or[any](nil, "a", "b"))
assert.Equal(t, 2, Or[any](0, 2, 3))
assert.Equal(t, 3, Or[any](0, 0, 3))
assert.Equal(t, "a", Or[any]("", 0, "a"))
assert.Equal(t, "a", Or[any]("", "a", 0))
assert.Equal(t, "a", Or[any]("a", 0, nil))
assert.Equal(t, 2, Or(0, 2, 3))
assert.Equal(t, "a", Or("", "a", "c"))
assert.Equal(t, "a", Or("", "a", "c"))
assert.Equal(t, "a", Or("a", "", "c"))
})
t.Run("IfThen", func(t *testing.T) {
assert.Equal(t, 1, IfThen(true, 1, 2))
assert.Equal(t, 2, IfThen(false, 1, 2))
})
t.Run("IfThenExec", func(t *testing.T) {
assert.Equal(t, 1, IfThenExec(true, func() any { return 1 }, func() any { return 2 }))
assert.Equal(t, 2, IfThenExec(false, func() any { return 1 }, func() any { return 2 }))
})
t.Run("PtrAsValue", func(t *testing.T) {
assert.Equal(t, 1, PtrAsValue(&[]int{1}[0], 2))
assert.Equal(t, 2, PtrAsValue((*int)(nil), 2))
})
}