-
Notifications
You must be signed in to change notification settings - Fork 2
/
table_test.go
52 lines (47 loc) · 1 KB
/
table_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
package sqlparser
import (
"encoding/json"
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func TestParseCreateTable(t *testing.T) {
{
var testCases = []struct {
description string
SQL string
expect string
}{
{
description: "basc create",
SQL: `CREATE TABLE Bookstore2 (
ISBN_NO varchar(15) PRIMARY KEY NOT NULL,
SHORT_DESC varchar(100) ,
AUTHOR varchar(40) ,
PUBLISHER varchar(40) ,
ACTIVE bool DEFAULT 'true',
PRICE float
);`,
expect: `CREATE TABLE Bookstore2(
ISBN_NO varchar(15) PRIMARY KEY NOT NULL,
SHORT_DESC varchar(100),
AUTHOR varchar(40),
PUBLISHER varchar(40),
ACTIVE bool DEFAULT 'true',
PRICE float)`,
},
}
for _, testCase := range testCases {
table, err := ParseCreateTable(testCase.SQL)
if !assert.Nil(t, err) {
fmt.Printf("%v\n", testCase.SQL)
continue
}
actual := Stringify(table)
if !assert.EqualValues(t, testCase.expect, actual) {
data, _ := json.Marshal(table)
fmt.Printf("%s\n", data)
}
}
}
}