Ensure an AST node can be rewritten.
(t *testing.T)
| 29 | |
| 30 | // Ensure an AST node can be rewritten. |
| 31 | func 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 | |
| 50 | func TestTypeMarshal(t *testing.T) { |
| 51 | for tp, n := range typeNames { |
nothing calls this directly
no test coverage detected