forked from slicebit/qb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
type_test.go
49 lines (40 loc) · 2 KB
/
type_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
package qb
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"testing"
)
type TypeTestSuite struct {
suite.Suite
}
func (suite *TypeTestSuite) TestTypes() {
dialect := NewDialect("")
precisionType := Type("FLOAT").Precision(2, 5)
assert.Equal(suite.T(), "FLOAT(2, 5)", dialect.CompileType(precisionType))
assert.Equal(suite.T(), "CHAR", dialect.CompileType(Char()))
assert.Equal(suite.T(), "VARCHAR(255)", dialect.CompileType(Varchar()))
assert.Equal(suite.T(), "TEXT", dialect.CompileType(Text()))
assert.Equal(suite.T(), "INT", dialect.CompileType(Int()))
assert.Equal(suite.T(), "SMALLINT", dialect.CompileType(SmallInt()))
assert.Equal(suite.T(), "BIGINT", dialect.CompileType(BigInt()))
assert.Equal(suite.T(), "NUMERIC(2, 5)", dialect.CompileType(Numeric().Precision(2, 5)))
assert.Equal(suite.T(), "DECIMAL", dialect.CompileType(Decimal()))
assert.Equal(suite.T(), "FLOAT", dialect.CompileType(Float()))
assert.Equal(suite.T(), "BOOLEAN", dialect.CompileType(Boolean()))
assert.Equal(suite.T(), "TIMESTAMP", dialect.CompileType(Timestamp()))
assert.Equal(suite.T(), "BLOB", dialect.CompileType(Blob()))
assert.Equal(suite.T(), "UUID", dialect.CompileType(UUID()))
}
func (suite *TypeTestSuite) TestUnsigned() {
assert.Equal(suite.T(), "BIGINT", DefaultCompileType(BigInt().Signed(), true))
assert.Equal(suite.T(), "BIGINT UNSIGNED", DefaultCompileType(BigInt().Unsigned(), true))
assert.Equal(suite.T(), "NUMERIC(2, 5) UNSIGNED", DefaultCompileType(Numeric().Precision(2, 5).Unsigned(), true))
assert.Equal(suite.T(), "INT", DefaultCompileType(Int().Signed(), false))
assert.Equal(suite.T(), "SMALLINT", DefaultCompileType(TinyInt().Unsigned(), false))
assert.Equal(suite.T(), "INT", DefaultCompileType(SmallInt().Unsigned(), false))
assert.Equal(suite.T(), "BIGINT", DefaultCompileType(Int().Unsigned(), false))
assert.Equal(suite.T(), "BIGINT", DefaultCompileType(BigInt().Unsigned(), false))
}
func TestTypeTestSuite(t *testing.T) {
suite.Run(t, new(TypeTestSuite))
}