-
Notifications
You must be signed in to change notification settings - Fork 208
/
expressions_test.go
190 lines (146 loc) · 5.79 KB
/
expressions_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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package goqu_test
import (
"testing"
"github.com/doug-martin/goqu/v9"
"github.com/doug-martin/goqu/v9/exp"
"github.com/stretchr/testify/suite"
)
type (
goquExpressionsSuite struct {
suite.Suite
}
)
func (ges *goquExpressionsSuite) TestCast() {
ges.Equal(exp.NewCastExpression(goqu.C("test"), "string"), goqu.Cast(goqu.C("test"), "string"))
}
func (ges *goquExpressionsSuite) TestDoNothing() {
ges.Equal(exp.NewDoNothingConflictExpression(), goqu.DoNothing())
}
func (ges *goquExpressionsSuite) TestDoUpdate() {
ges.Equal(exp.NewDoUpdateConflictExpression("test", goqu.Record{"a": "b"}), goqu.DoUpdate("test", goqu.Record{"a": "b"}))
}
func (ges *goquExpressionsSuite) TestOr() {
e1 := goqu.C("a").Eq("b")
e2 := goqu.C("b").Eq(2)
ges.Equal(exp.NewExpressionList(exp.OrType, e1, e2), goqu.Or(e1, e2))
}
func (ges *goquExpressionsSuite) TestAnd() {
e1 := goqu.C("a").Eq("b")
e2 := goqu.C("b").Eq(2)
ges.Equal(exp.NewExpressionList(exp.AndType, e1, e2), goqu.And(e1, e2))
}
func (ges *goquExpressionsSuite) TestFunc() {
ges.Equal(exp.NewSQLFunctionExpression("count", goqu.L("*")), goqu.Func("count", goqu.L("*")))
}
func (ges *goquExpressionsSuite) TestDISTINCT() {
ges.Equal(exp.NewSQLFunctionExpression("DISTINCT", goqu.I("col")), goqu.DISTINCT("col"))
}
func (ges *goquExpressionsSuite) TestCOUNT() {
ges.Equal(exp.NewSQLFunctionExpression("COUNT", goqu.I("col")), goqu.COUNT("col"))
}
func (ges *goquExpressionsSuite) TestMIN() {
ges.Equal(exp.NewSQLFunctionExpression("MIN", goqu.I("col")), goqu.MIN("col"))
}
func (ges *goquExpressionsSuite) TestMAX() {
ges.Equal(exp.NewSQLFunctionExpression("MAX", goqu.I("col")), goqu.MAX("col"))
}
func (ges *goquExpressionsSuite) TestAVG() {
ges.Equal(exp.NewSQLFunctionExpression("AVG", goqu.I("col")), goqu.AVG("col"))
}
func (ges *goquExpressionsSuite) TestFIRST() {
ges.Equal(exp.NewSQLFunctionExpression("FIRST", goqu.I("col")), goqu.FIRST("col"))
}
func (ges *goquExpressionsSuite) TestLAST() {
ges.Equal(exp.NewSQLFunctionExpression("LAST", goqu.I("col")), goqu.LAST("col"))
}
func (ges *goquExpressionsSuite) TestSUM() {
ges.Equal(exp.NewSQLFunctionExpression("SUM", goqu.I("col")), goqu.SUM("col"))
}
func (ges *goquExpressionsSuite) TestCOALESCE() {
ges.Equal(exp.NewSQLFunctionExpression("COALESCE", goqu.I("col"), nil), goqu.COALESCE(goqu.I("col"), nil))
}
func (ges *goquExpressionsSuite) TestROW_NUMBER() {
ges.Equal(exp.NewSQLFunctionExpression("ROW_NUMBER"), goqu.ROW_NUMBER())
}
func (ges *goquExpressionsSuite) TestRANK() {
ges.Equal(exp.NewSQLFunctionExpression("RANK"), goqu.RANK())
}
func (ges *goquExpressionsSuite) TestDENSE_RANK() {
ges.Equal(exp.NewSQLFunctionExpression("DENSE_RANK"), goqu.DENSE_RANK())
}
func (ges *goquExpressionsSuite) TestPERCENT_RANK() {
ges.Equal(exp.NewSQLFunctionExpression("PERCENT_RANK"), goqu.PERCENT_RANK())
}
func (ges *goquExpressionsSuite) TestCUME_DIST() {
ges.Equal(exp.NewSQLFunctionExpression("CUME_DIST"), goqu.CUME_DIST())
}
func (ges *goquExpressionsSuite) TestNTILE() {
ges.Equal(exp.NewSQLFunctionExpression("NTILE", 1), goqu.NTILE(1))
}
func (ges *goquExpressionsSuite) TestFIRST_VALUE() {
ges.Equal(exp.NewSQLFunctionExpression("FIRST_VALUE", goqu.I("col")), goqu.FIRST_VALUE("col"))
}
func (ges *goquExpressionsSuite) TestLAST_VALUE() {
ges.Equal(exp.NewSQLFunctionExpression("LAST_VALUE", goqu.I("col")), goqu.LAST_VALUE("col"))
}
func (ges *goquExpressionsSuite) TestNTH_VALUE() {
ges.Equal(exp.NewSQLFunctionExpression("NTH_VALUE", goqu.I("col"), 1), goqu.NTH_VALUE("col", 1))
ges.Equal(exp.NewSQLFunctionExpression("NTH_VALUE", goqu.I("col"), 1), goqu.NTH_VALUE(goqu.C("col"), 1))
}
func (ges *goquExpressionsSuite) TestI() {
ges.Equal(exp.NewIdentifierExpression("s", "t", "c"), goqu.I("s.t.c"))
}
func (ges *goquExpressionsSuite) TestC() {
ges.Equal(exp.NewIdentifierExpression("", "", "c"), goqu.C("c"))
}
func (ges *goquExpressionsSuite) TestS() {
ges.Equal(exp.NewIdentifierExpression("s", "", ""), goqu.S("s"))
}
func (ges *goquExpressionsSuite) TestT() {
ges.Equal(exp.NewIdentifierExpression("", "t", ""), goqu.T("t"))
}
func (ges *goquExpressionsSuite) TestW() {
ges.Equal(exp.NewWindowExpression(nil, nil, nil, nil), goqu.W())
ges.Equal(exp.NewWindowExpression(goqu.I("a"), nil, nil, nil), goqu.W("a"))
ges.Equal(exp.NewWindowExpression(goqu.I("a"), goqu.I("b"), nil, nil), goqu.W("a", "b"))
ges.Equal(exp.NewWindowExpression(goqu.I("a"), goqu.I("b"), nil, nil), goqu.W("a", "b", "c"))
}
func (ges *goquExpressionsSuite) TestOn() {
ges.Equal(exp.NewJoinOnCondition(goqu.Ex{"a": "b"}), goqu.On(goqu.Ex{"a": "b"}))
}
func (ges *goquExpressionsSuite) TestUsing() {
ges.Equal(exp.NewJoinUsingCondition("a", "b"), goqu.Using("a", "b"))
}
func (ges *goquExpressionsSuite) TestL() {
ges.Equal(exp.NewLiteralExpression("? + ?", 1, 2), goqu.L("? + ?", 1, 2))
}
func (ges *goquExpressionsSuite) TestLiteral() {
ges.Equal(exp.NewLiteralExpression("? + ?", 1, 2), goqu.Literal("? + ?", 1, 2))
}
func (ges *goquExpressionsSuite) TestV() {
ges.Equal(exp.NewLiteralExpression("?", "a"), goqu.V("a"))
}
func (ges *goquExpressionsSuite) TestRange() {
ges.Equal(exp.NewRangeVal("a", "b"), goqu.Range("a", "b"))
}
func (ges *goquExpressionsSuite) TestStar() {
ges.Equal(exp.NewLiteralExpression("*"), goqu.Star())
}
func (ges *goquExpressionsSuite) TestDefault() {
ges.Equal(exp.Default(), goqu.Default())
}
func (ges *goquExpressionsSuite) TestLateral() {
ds := goqu.From("test")
ges.Equal(exp.NewLateralExpression(ds), goqu.Lateral(ds))
}
func (ges *goquExpressionsSuite) TestAny() {
ds := goqu.From("test").Select("id")
ges.Equal(exp.NewSQLFunctionExpression("ANY ", ds), goqu.Any(ds))
}
func (ges *goquExpressionsSuite) TestAll() {
ds := goqu.From("test").Select("id")
ges.Equal(exp.NewSQLFunctionExpression("ALL ", ds), goqu.All(ds))
}
func TestGoquExpressions(t *testing.T) {
suite.Run(t, new(goquExpressionsSuite))
}