From 51ca778d778f00a773dd7753a31743698fccefa0 Mon Sep 17 00:00:00 2001 From: Travis Date: Sun, 17 Sep 2017 00:32:22 -0500 Subject: [PATCH] Don't include an equal sign in the string representation of a Condition --- pql/ast.go | 9 ++++++++- pql/ast_test.go | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pql/ast.go b/pql/ast.go index 48e5f1771..a2b0501f0 100644 --- a/pql/ast.go +++ b/pql/ast.go @@ -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. diff --git a/pql/ast_test.go b/pql/ast_test.go index 2b8519571..297b63700 100644 --- a/pql/ast_test.go +++ b/pql/ast_test.go @@ -28,6 +28,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 call can be converted into a string.