MCPcopy
hub / github.com/uber/aresdb / TestRewrite

Function TestRewrite

query/expr/ast_test.go:31–48  ·  view source on GitHub ↗

Ensure an AST node can be rewritten.

(t *testing.T)

Source from the content-addressed store, hash-verified

29
30// Ensure an AST node can be rewritten.
31func TestRewrite(t *testing.T) {
32 expression, _ := ParseExpr(`time > 1 OR foo = 2`)
33
34 // Flip LHS & RHS in all binary expressions.
35 act := RewriteFunc(expression, func(e Expr) Expr {
36 switch e := e.(type) {
37 case *BinaryExpr:
38 return &BinaryExpr{Op: e.Op, LHS: e.RHS, RHS: e.LHS}
39 default:
40 return e
41 }
42 })
43
44 // Verify that everything is flipped.
45 if act := act.String(); act != `2 = foo OR 1 > time` {
46 t.Fatalf("unexpected result: %s", act)
47 }
48}
49
50func TestTypeMarshal(t *testing.T) {
51 for tp, n := range typeNames {

Callers

nothing calls this directly

Calls 4

ParseExprFunction · 0.85
RewriteFuncFunction · 0.85
StringMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected