forked from slicebit/qb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
statement_test.go
50 lines (38 loc) · 1.31 KB
/
statement_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
package qb
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestStatement(t *testing.T) {
statement := Statement()
statement.AddSQLClause("SELECT name")
statement.AddSQLClause("FROM user")
statement.AddSQLClause("WHERE id = ?")
statement.AddBinding(5)
assert.Equal(t, []string{"SELECT name", "FROM user", "WHERE id = ?"}, statement.SQLClauses())
assert.Equal(t, []interface{}{5}, statement.Bindings())
assert.Equal(t, "SELECT name\nFROM user\nWHERE id = ?;", statement.SQL())
}
func TestStatementRaw(t *testing.T) {
statement := Statement()
sql := `
SELECT name
FROM user
WHERE id = ?;
`
statement.Text(sql)
assert.Equal(t, []string{"SELECT name", "FROM user", "WHERE id = ?"}, statement.SQLClauses())
assert.Equal(t, "SELECT name\nFROM user\nWHERE id = ?;", statement.SQL())
}
func TestStatementWithCustomDelimiter(t *testing.T) {
statement := Statement()
assert.Equal(t, "", statement.SQL())
statement.SetDelimiter(" ")
statement.AddSQLClause("SELECT name")
statement.AddSQLClause("FROM user")
statement.AddSQLClause("WHERE id = ?")
statement.AddBinding(5)
assert.Equal(t, []string{"SELECT name", "FROM user", "WHERE id = ?"}, statement.SQLClauses())
assert.Equal(t, []interface{}{5}, statement.Bindings())
assert.Equal(t, "SELECT name FROM user WHERE id = ?;", statement.SQL())
}