-
Notifications
You must be signed in to change notification settings - Fork 26
/
combiner_test.go
48 lines (36 loc) · 1.15 KB
/
combiner_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 qb
import (
"testing"
"github.com/stretchr/testify/suite"
"github.com/stretchr/testify/assert"
)
type CombinerTestSuite struct {
suite.Suite
dialect Dialect
ctx *CompilerContext
}
func (suite *CombinerTestSuite) SetupTest() {
suite.dialect = NewDefaultDialect()
suite.ctx = NewCompilerContext(suite.dialect)
}
func (suite *CombinerTestSuite) TestCombinerAnd() {
email := Column("email", Varchar()).NotNull().Unique()
id := Column("id", Int()).NotNull()
and := And(Eq(email, "[email protected]"), NotEq(id, 1))
sql := and.Accept(suite.ctx)
binds := suite.ctx.Binds
assert.Equal(suite.T(), "(email = ? AND id != ?)", sql)
assert.Equal(suite.T(), []interface{}{"[email protected]", 1}, binds)
}
func (suite *CombinerTestSuite) TestCombinerOr() {
email := Column("email", Varchar()).NotNull().Unique()
id := Column("id", Int()).NotNull()
or := Or(Eq(email, "[email protected]"), NotEq(id, 1))
sql := or.Accept(suite.ctx)
binds := suite.ctx.Binds
assert.Equal(suite.T(), "(email = ? OR id != ?)", sql)
assert.Equal(suite.T(), []interface{}{"[email protected]", 1}, binds)
}
func TestCombinerTestSuite(t *testing.T) {
suite.Run(t, new(CombinerTestSuite))
}