dal/pkg/builder/convert_find_test.go
Anton Nesterov d644ef077e
[ref] move to builder pkg
Signed-off-by: Anton Nesterov <anton@demiurg.io>
2024-08-09 17:00:52 +02:00

74 lines
1.2 KiB
Go

package builder
import (
"testing"
)
func TestConvertFind(t *testing.T) {
find := Find{
"impl": "1",
"exp": Is{
"$gt": 1,
},
}
ctx := SQLiteContext{
TableAlias: "t",
}
result := CovertFind(ctx, find)
if result == `t.exp > 1 AND t.impl = '1'` {
return
}
if result == `t.impl = '1' AND t.exp > 1` {
return
}
t.Errorf(`Expected "t.impl = '1' AND t.exp = 1", got %s`, result)
}
func TestConvertFindAnd(t *testing.T) {
find := Find{
"$and": Find{
"a": Is{
"$gt": 1,
},
"b": Is{
"$lt": 10,
},
},
}
ctx := SQLiteContext{
TableAlias: "t",
}
result := CovertFind(ctx, find)
if result == `(t.a > 1 AND t.b < 10)` {
return
}
if result == `(t.b < 10 AND t.a > 1)` {
return
}
t.Errorf(`Expected "(t.b < 10 AND t.a > 1)", got %s`, result)
}
func TestConvertFindOr(t *testing.T) {
find := Query{
"$or": Query{
"a": Is{
"$gt": 1,
},
"b": Is{
"$lt": 10,
},
},
}
ctx := SQLiteContext{
TableAlias: "t",
}
result := CovertFind(ctx, find)
if result == `(t.a > 1 OR t.b < 10)` {
return
}
if result == `(t.b < 10 OR t.a > 1)` {
return
}
t.Errorf(`Expected "(t.b < 10 OR t.a > 1)", got %s`, result)
}