Merge pull request #275 from travisturner/serialize-null

serialize null operation (!= null)
This commit is contained in:
Matthew Jaffee 2020-04-09 21:25:05 -05:00 committed by GitHub
commit 179cab91e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 10 deletions

View file

@ -795,7 +795,7 @@ type Condition struct {
// String returns the string representation of the condition.
func (cond *Condition) String() string {
return fmt.Sprintf("%s %s", cond.Op.String(), formatValue(cond.Value))
return fmt.Sprintf("%s%s", cond.Op.String(), formatValue(cond.Value))
}
// StringWithSubj returns the string representation of the condition
@ -926,6 +926,8 @@ func (cond *Condition) StringSliceValue() ([]string, bool) {
func formatValue(v interface{}) string {
switch v := v.(type) {
case nil:
return "null"
case string:
return fmt.Sprintf("%q", v)
case []interface{}:

View file

@ -36,7 +36,7 @@ func TestCall_String(t *testing.T) {
"field0": &pql.Condition{Op: pql.GTE, Value: 10},
},
}
if s := c.String(); s != `Range(field0>= 10, other="f")` {
if s := c.String(); s != `Range(field0>=10, other="f")` {
t.Fatalf("unexpected string: %s", s)
}
})
@ -44,18 +44,20 @@ func TestCall_String(t *testing.T) {
// Ensure condition string with subject is correct.
func TestCondition_StringWithSubj(t *testing.T) {
op := pql.BETWEEN
subj := "subj"
for _, tt := range []struct {
val []interface{}
op pql.Token
val interface{}
exp string
}{
{[]interface{}{int64(4), int64(8)}, "4<=subj<=8"},
{[]interface{}{uint64(5), uint64(9)}, "5<=subj<=9"},
{[]interface{}{pql.Decimal{Value: -401, Scale: 2}, pql.Decimal{Value: 802, Scale: 1}}, "-4.01<=subj<=80.2"},
{pql.BETWEEN, []interface{}{int64(4), int64(8)}, "4<=subj<=8"},
{pql.BETWEEN, []interface{}{uint64(5), uint64(9)}, "5<=subj<=9"},
{pql.BETWEEN, []interface{}{pql.Decimal{Value: -401, Scale: 2}, pql.Decimal{Value: 802, Scale: 1}}, "-4.01<=subj<=80.2"},
{pql.EQ, nil, "subj==null"},
{pql.NEQ, nil, "subj!=null"},
} {
c := &pql.Condition{
Op: op,
Op: tt.op,
Value: tt.val,
}
if sws := c.StringWithSubj(subj); sws != tt.exp {

View file

@ -46,7 +46,7 @@ SetBit(Union(Zitmap(row==4), Intersect(Qitmap(blah>4), Ritmap(field="http://zoo9
if err != nil {
t.Fatalf("should have parsed: %v", err)
}
if q.String() != `TopN(Bitmap(id== "other"), _field="blah", field="f", n=0)` {
if q.String() != `TopN(Bitmap(id=="other"), _field="blah", field="f", n=0)` {
t.Fatalf("Failed, got: %s", q)
}
@ -59,7 +59,7 @@ SetBit(Union(Zitmap(row==4), Intersect(Qitmap(blah>4), Ritmap(field="http://zoo9
if err != nil {
t.Fatalf("should have parsed: %v", err)
}
if q.String() != `Bitmap(did== "other", row=4)` {
if q.String() != `Bitmap(did=="other", row=4)` {
t.Fatalf("got %s", q)
}