(t *testing.T)
| 24 | ) |
| 25 | |
| 26 | func TestExprHelperCopy(t *testing.T) { |
| 27 | src := common.NewStringSource( |
| 28 | `noop([1, 2, 3].map(i, Msg{first: 1 + 2, second: a.b, third: {true: true}}))`, |
| 29 | "") |
| 30 | p, err := NewParser( |
| 31 | PopulateMacroCalls(true), |
| 32 | Macros( |
| 33 | MapMacro, |
| 34 | NewGlobalMacro("noop", 1, |
| 35 | func(eh ExprHelper, target ast.Expr, args []ast.Expr) (ast.Expr, *common.Error) { |
| 36 | return eh.Copy(args[0]), nil |
| 37 | }, |
| 38 | ), |
| 39 | ), |
| 40 | ) |
| 41 | if err != nil { |
| 42 | t.Fatalf("NewParser() failed: %v", err) |
| 43 | } |
| 44 | parsed, errs := p.Parse(src) |
| 45 | if errs != nil && len(errs.GetErrors()) != 0 { |
| 46 | t.Fatalf("p.Parse(%v) failed: %v", src, errs.ToDisplayString()) |
| 47 | } |
| 48 | // id generation is consistent between runs, and in this case '27' refers to the |
| 49 | // macro expression that's the sole argument to the noop() macro. |
| 50 | macroTarget, found := parsed.SourceInfo().GetMacroCall(27) |
| 51 | if !found { |
| 52 | t.Fatal("GetMacroCall(27) failed to find call") |
| 53 | } |
| 54 | macroExpr, err := ast.ExprToProto(macroTarget) |
| 55 | if err != nil { |
| 56 | t.Fatalf("ast.ExprToProto() failed: %v", err) |
| 57 | } |
| 58 | protoExpr, err := ast.ExprToProto(parsed.Expr()) |
| 59 | if err != nil { |
| 60 | t.Fatalf("ast.ExprToProto() failed: %v", err) |
| 61 | } |
| 62 | if proto.Equal(protoExpr, macroExpr) { |
| 63 | t.Errorf("Copy() failed to provide a unique ids: %v", macroExpr) |
| 64 | } |
| 65 | } |
nothing calls this directly
no test coverage detected