forked from huandu/go-sqlbuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modifiers_test.go
59 lines (49 loc) · 1.21 KB
/
modifiers_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
53
54
55
56
57
58
59
// Copyright 2018 Huan Du. All rights reserved.
// Licensed under the MIT license that can be found in the LICENSE file.
package sqlbuilder
import (
"reflect"
"testing"
)
func TestEscape(t *testing.T) {
cases := map[string]string{
"foo": "foo",
"$foo": "$$foo",
"$$$": "$$$$$$",
}
var inputs, expects []string
for s, expected := range cases {
inputs = append(inputs, s)
expects = append(expects, expected)
if actual := Escape(s); actual != expected {
t.Fatalf("invalid escape result. [expected:%v] [actual:%v]", expected, actual)
}
}
actuals := EscapeAll(inputs...)
if !reflect.DeepEqual(expects, actuals) {
t.Fatalf("invalid escape result. [expected:%v] [actual:%v]", expects, actuals)
}
}
func TestFlatten(t *testing.T) {
cases := [][2]interface{}{
{
"foo",
[]interface{}{"foo"},
},
{
[]int{1, 2, 3},
[]interface{}{1, 2, 3},
},
{
[]interface{}{"abc", []int{1, 2, 3}, [3]string{"def", "ghi"}},
[]interface{}{"abc", 1, 2, 3, "def", "ghi", ""},
},
}
for _, c := range cases {
input, expected := c[0], c[1]
actual := Flatten(input)
if !reflect.DeepEqual(expected, actual) {
t.Fatalf("invalid flatten result. [expected:%v] [actual:%v]", expected, actual)
}
}
}