-
Notifications
You must be signed in to change notification settings - Fork 235
/
cond_test.go
51 lines (36 loc) · 834 Bytes
/
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
package db
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCond(t *testing.T) {
t.Run("Base", func(t *testing.T) {
var c Cond
c = Cond{}
assert.True(t, c.Empty())
c = Cond{"id": 1}
assert.False(t, c.Empty())
})
t.Run("And", func(t *testing.T) {
var a *AndExpr
a = And()
assert.True(t, a.Empty())
_ = a.And(Cond{"id": 1})
assert.True(t, a.Empty(), "conditions are immutable")
a = a.And(Cond{"name": "Ana"})
assert.False(t, a.Empty())
a = a.And().And()
assert.False(t, a.Empty())
})
t.Run("Or", func(t *testing.T) {
var a *OrExpr
a = Or()
assert.True(t, a.Empty())
_ = a.Or(Cond{"id": 1})
assert.True(t, a.Empty(), "conditions are immutable")
a = a.Or(Cond{"name": "Ana"})
assert.False(t, a.Empty())
a = a.Or().Or()
assert.False(t, a.Empty())
})
}