-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathin_test.go
More file actions
85 lines (76 loc) · 1.73 KB
/
Copy pathin_test.go
File metadata and controls
85 lines (76 loc) · 1.73 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
74
75
76
77
78
79
80
81
82
83
84
85
package gosql
import (
"reflect"
"strings"
"testing"
)
type testData struct {
title string
cmd string
args []interface{}
expectCmd string
expectArgs []interface{}
}
func TestIn(t *testing.T) {
t.Log(InToSql("select * from a where a not in (?)", []int{}))
}
func TestString(t *testing.T) {
a := "select * from xxx where id=? and a in (?) and b in (?) and name=?"
args := []interface{}{
6666,
[]string{"1", "2", "4", "5", "6", "7", "8", "89", "3", "4"},
[]int64{2},
"cander",
}
cmd, args, err := makeArgs(a, args...)
if err != nil {
t.Log(err)
}
t.Log(cmd)
t.Log(args)
}
func TestInArgs(t *testing.T) {
td := []testData{
{
title: "参数都有的 测试前后都有条件的",
cmd: "select * from xxx where id=? and a in (?) and b in (?) and name=?",
args: []interface{}{
6666,
[]string{"1", "2", "4", "5", "6", "7", "8", "89", "3", "4"},
[]string{},
"cander",
},
expectCmd: "select * from xxx where id=? and a in (?,?,?,?,?,?,?,?,?,?) and name=?",
expectArgs: []interface{}{6666, "1", "2", "4", "5", "6", "7", "8", "89", "3", "4", "cander"},
},
}
for _, v := range td {
run(t, v)
}
}
func run(t *testing.T, td testData) {
cmd, args, err := makeArgs(td.cmd, td.args...)
if err != nil {
t.Fatal(err)
}
t.Log(cmd)
t.Log(args)
if strings.Trim(cmd, " ") == td.expectCmd {
} else {
t.Log("title", td.title)
t.Log("cmd failed")
}
if reflect.DeepEqual(args, td.expectArgs) {
} else {
t.Log("title", td.title)
t.Log("args failed")
}
}
// func TestReplace(t *testing.T) {
// // 讲索引为什么的?。 替换成n个
// am, err := replace("select * from xxx where id=? and a in (?)", 1, 10)
// if err != nil {
// t.Fatal(err)
// }
// t.Log(am)
// }