Merge pull request #844 from travisturner/bug-fix-condition-string

Don't include an equal sign in the string representation of a Condition
This commit is contained in:
Travis Turner 2017-09-27 11:14:56 -05:00 committed by GitHub
commit 1fb540f40b
2 changed files with 20 additions and 1 deletions

View file

@ -161,7 +161,14 @@ func (c *Call) String() string {
if i > 0 {
buf.WriteString(", ")
}
fmt.Fprintf(&buf, "%v=%s", key, FormatValue(c.Args[key]))
// If the Arg value is a Condition, then don't include
// the equal sign in the string representation.
switch v := c.Args[key].(type) {
case *Condition:
fmt.Fprintf(&buf, "%v %s", key, v.String())
default:
fmt.Fprintf(&buf, "%v=%s", key, FormatValue(v))
}
}
// Write closing.

View file

@ -29,6 +29,18 @@ func TestCall_String(t *testing.T) {
t.Fatalf("unexpected string: %s", s)
}
})
t.Run("With Args", func(t *testing.T) {
c := &pql.Call{
Name: "Range",
Args: map[string]interface{}{
"frame": "f",
"field0": &pql.Condition{Op: pql.GTE, Value: 10},
},
}
if s := c.String(); s != `Range(field0 >= 10, frame="f")` {
t.Fatalf("unexpected string: %s", s)
}
})
}
// Ensure condition can handle values for BETWEEN operator.