Skip to content

Commit c53507e

Browse files
authored
more tests (go-xorm#29)
1 parent b0282a4 commit c53507e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

builder_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,21 @@ func TestBuilderCond(t *testing.T) {
198198
"d BETWEEN ? AND ? OR e BETWEEN ? AND ?",
199199
[]interface{}{0, 2, 3, 4},
200200
},
201+
{
202+
Expr("a < ?", 1),
203+
"a < ?",
204+
[]interface{}{1},
205+
},
206+
{
207+
Expr("a < ?", 1).And(Eq{"b": 2}),
208+
"(a < ?) AND b=?",
209+
[]interface{}{1, 2},
210+
},
211+
{
212+
Expr("a < ?", 1).Or(Neq{"b": 2}),
213+
"(a < ?) OR b<>?",
214+
[]interface{}{1, 2},
215+
},
201216
{
202217
IsNull{"d"},
203218
"d IS NULL",
@@ -488,6 +503,11 @@ func TestBuilderCond(t *testing.T) {
488503
"NOT (a=? AND b=?)",
489504
[]interface{}{1, 2},
490505
},
506+
{
507+
Not{Neq{"a": 1, "b": 2}},
508+
"NOT (a<>? AND b<>?)",
509+
[]interface{}{1, 2},
510+
},
491511
{
492512
Not{Eq{"a": 1}.And(Eq{"b": 2})},
493513
"NOT (a=? AND b=?)",

cond_or.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ func (o condOr) WriteTo(w Writer) error {
2727
for i, cond := range o {
2828
var needQuote bool
2929
switch cond.(type) {
30-
case condAnd:
30+
case condAnd, expr:
3131
needQuote = true
3232
case Eq:
3333
needQuote = (len(cond.(Eq)) > 1)
34+
case Neq:
35+
needQuote = (len(cond.(Neq)) > 1)
3436
}
3537

3638
if needQuote {

0 commit comments

Comments
 (0)