-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_test.go
More file actions
73 lines (64 loc) · 1.56 KB
/
Copy pathparse_test.go
File metadata and controls
73 lines (64 loc) · 1.56 KB
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
package parser
import (
"miniSQL/src/Interpreter/types"
"strconv"
"strings"
"testing"
)
var sql_strings = []string{
"create table cxz(" +
"afsdfsad int unique," +
"what char(30) not null," +
"primary key (what)" +
");",
"select a,b,c,d,e,f,g from cxz where a=123 and b=456 or c=234;",
}
var sql_CreateTable = "create table cxz(" +
"afsdfsad int unique," +
"what char(30) not null," +
"primary key (what)" +
");"
var sql_CreateDatabase = "create database cxz"
func TestCreateTable(t *testing.T) {
ch := make(chan types.DStatements)
go func() {
io := strings.NewReader(sql_CreateTable) // 组装io
Parse(io, ch)
}()
data := <-ch
cts := data.(types.CreateTableStatement)
t.Log(data.GetOperationName())
t.Log("要创建的表为:" + cts.TableName)
keys := ""
for key, attr := range cts.ColumnsMap {
attrDetails := ""
attrDetails += "(类型为:" + strconv.Itoa(attr.Type.TypeTag)
if attr.Unique {
attrDetails += ", 唯一"
}
if attr.NotNull {
attrDetails += ", 非空"
}
attrDetails += ")"
keys += " " + key + attrDetails
}
t.Log("加入的键为:" + keys)
primaryKey := ""
for _, key := range cts.PrimaryKeys {
primaryKey += key.Name + " "
}
t.Log("主键为:" + primaryKey)
t.Errorf("\n")
}
func TestCreateDatabaseStatement(t *testing.T) {
ch := make(chan types.DStatements)
go func() {
io := strings.NewReader(sql_CreateDatabase) // 组装io
Parse(io, ch)
}()
data := <-ch
cts := data.(types.CreateDatabaseStatement)
t.Log(data.GetOperationName())
t.Log("要创建的数据库为:" + cts.DatabaseId)
t.Errorf("\n")
}