-
Notifications
You must be signed in to change notification settings - Fork 0
/
cond_test.go
68 lines (64 loc) · 1.92 KB
/
cond_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
60
61
62
63
64
65
66
67
68
// Copyright 2018 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package builder
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestCond_NotIn(t *testing.T) {
t.Run("normal", func(t *testing.T) {
cond := NotIn("test", 1, 2, 2, 3, 4, 4, 4)
buf := NewWriter()
err := cond.WriteTo(buf)
assert.NoError(t, err)
assert.Equal(t, "test NOT IN (?,?,?,?)", buf.String())
assert.Len(t, buf.args, 4)
assert.Equal(t, []interface{}{1, 2, 3, 4}, buf.args)
})
t.Run("slice", func(t *testing.T) {
cond := NotIn("test", []int{1, 2, 2, 3, 4, 4, 4})
buf := NewWriter()
err := cond.WriteTo(buf)
assert.NoError(t, err)
assert.Equal(t, "test NOT IN (?,?,?,?)", buf.String())
assert.Len(t, buf.args, 4)
assert.Equal(t, []interface{}{1, 2, 3, 4}, buf.args)
})
t.Run("blank", func(t *testing.T) {
cond := NotIn("test")
buf := NewWriter()
err := cond.WriteTo(buf)
// The "error" is written to the bytes buffer
assert.NoError(t, err)
assert.Equal(t, "0=0", buf.String())
})
}
func TestCond_In(t *testing.T) {
t.Run("normal", func(t *testing.T) {
cond := In("test", 1, 2, 2, 3, 4, 4, 4)
buf := NewWriter()
err := cond.WriteTo(buf)
assert.NoError(t, err)
assert.Equal(t, "test IN (?,?,?,?)", buf.String())
assert.Len(t, buf.args, 4)
assert.Equal(t, []interface{}{1, 2, 3, 4}, buf.args)
})
t.Run("slice", func(t *testing.T) {
cond := In("test", []int{1, 2, 2, 3, 4, 4, 4})
buf := NewWriter()
err := cond.WriteTo(buf)
assert.NoError(t, err)
assert.Equal(t, "test IN (?,?,?,?)", buf.String())
assert.Len(t, buf.args, 4)
assert.Equal(t, []interface{}{1, 2, 3, 4}, buf.args)
})
t.Run("blank", func(t *testing.T) {
cond := In("test")
buf := NewWriter()
err := cond.WriteTo(buf)
// The "error" is written to the bytes buffer
assert.NoError(t, err)
assert.Equal(t, "0=1", buf.String())
})
}