forked from doug-martin/goqu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcase_test.go
99 lines (77 loc) · 2.26 KB
/
case_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package exp_test
import (
"testing"
"github.com/doug-martin/goqu/v9/exp"
"github.com/stretchr/testify/suite"
)
type caseExpressionSuite struct {
suite.Suite
}
func TestCaseExpressionSuite(t *testing.T) {
suite.Run(t, &caseExpressionSuite{})
}
func (ces *caseExpressionSuite) TestClone() {
ce := exp.NewCaseExpression()
ces.Equal(ce, ce.Clone())
}
func (ces *caseExpressionSuite) TestExpression() {
ce := exp.NewCaseExpression()
ces.Equal(ce, ce.Expression())
}
func (ces *caseExpressionSuite) TestAs() {
ce := exp.NewCaseExpression()
ces.Equal(exp.NewAliasExpression(ce, "a"), ce.As("a"))
}
func (ces *caseExpressionSuite) TestValue() {
ce := exp.NewCaseExpression()
ces.Nil(ce.GetValue())
ce = exp.NewCaseExpression().Value(exp.NewIdentifierExpression("", "", "a"))
ces.Equal(exp.NewIdentifierExpression("", "", "a"), ce.GetValue())
}
func (ces *caseExpressionSuite) TestWhen() {
condition1 := exp.NewIdentifierExpression("", "", "a").Eq(10)
condition2 := exp.NewIdentifierExpression("", "", "b").Eq(20)
ce := exp.NewCaseExpression()
ces.Equal([]exp.CaseWhen{
exp.NewCaseWhen(condition1, "a"),
exp.NewCaseWhen(condition2, "b"),
}, ce.When(condition1, "a").When(condition2, "b").GetWhens())
ces.Empty(ce.GetWhens())
}
func (ces *caseExpressionSuite) TestElse() {
ce := exp.NewCaseExpression()
ces.Equal(exp.NewCaseElse("a"), ce.Else("a").GetElse())
ces.Nil(ce.GetElse())
}
func (ces *caseExpressionSuite) TestAsc() {
ce := exp.NewCaseExpression()
ces.Equal(exp.NewOrderedExpression(ce, exp.AscDir, exp.NoNullsSortType), ce.Asc())
}
func (ces *caseExpressionSuite) TestDesc() {
ce := exp.NewCaseExpression()
ces.Equal(exp.NewOrderedExpression(ce, exp.DescSortDir, exp.NoNullsSortType), ce.Desc())
}
type caseWhenSuite struct {
suite.Suite
}
func TestCaseWhenSuite(t *testing.T) {
suite.Run(t, &caseWhenSuite{})
}
func (cws *caseWhenSuite) TestCondition() {
ce := exp.NewCaseWhen(true, false)
cws.Equal(true, ce.Condition())
}
func (cws *caseWhenSuite) TestResult() {
ce := exp.NewCaseWhen(true, false)
cws.Equal(false, ce.Result())
}
type caseElseSuite struct {
suite.Suite
}
func TestCaseElseSuite(t *testing.T) {
suite.Run(t, &caseElseSuite{})
}
func (ces *caseElseSuite) TestResult() {
ce := exp.NewCaseElse(false)
ces.Equal(false, ce.Result())
}