1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 00:22:41 +08:00
This commit is contained in:
2022-11-09 17:21:30 +08:00
parent 9203c3719f
commit d49c02924c
6 changed files with 146 additions and 85 deletions

View File

@ -1,9 +1,31 @@
package expr
import "testing"
import (
"testing"
func TestIf(t *testing.T) {
"github.com/stretchr/testify/assert"
)
func TestTernary(t *testing.T) {
v1 := 10
v2 := 4
t.Log(If(v1 > v2, v1, v2))
t.Log(Ternary(v1 > v2, v1, v2))
}
func TestIf(t *testing.T) {
is := assert.New(t)
is.Equal(1, If(true, 1).ElseIf(false, 2).Else(3))
is.Equal(1, If(true, 1).ElseIf(true, 2).Else(3))
is.Equal(2, If(false, 1).ElseIf(true, 2).Else(3))
is.Equal(3, If(false, 1).ElseIf(false, 2).Else(3))
}
func TestSwitch(t *testing.T) {
is := assert.New(t)
is.Equal(1, Switch[int, int](42).Case(42, 1).Case(1, 2).Default(3))
is.Equal(1, Switch[int, int](42).Case(42, 1).Case(42, 2).Default(3))
is.Equal(1, Switch[int, int](42).Case(1, 1).Case(42, 2).Default(3))
is.Equal(1, Switch[int, int](42).Case(1, 1).Case(1, 2).Default(3))
}