(t *testing.T)
| 1778 | } |
| 1779 | |
| 1780 | func TestParseWithMacroTracking(t *testing.T) { |
| 1781 | env := testEnv(t, EnableMacroCallTracking()) |
| 1782 | ast, iss := env.Parse("has(a.b) && a.b.exists(c, c < 10)") |
| 1783 | if iss.Err() != nil { |
| 1784 | t.Fatalf("e.Parse() failed: %v", iss.Err()) |
| 1785 | } |
| 1786 | pe, err := AstToParsedExpr(ast) |
| 1787 | if err != nil { |
| 1788 | t.Fatalf("AstToParsedExpr(%v) failed: %v", ast, err) |
| 1789 | } |
| 1790 | macroCalls := pe.GetSourceInfo().GetMacroCalls() |
| 1791 | if len(macroCalls) != 2 { |
| 1792 | t.Errorf("got %d macro calls, wanted 2", len(macroCalls)) |
| 1793 | } |
| 1794 | callsFound := map[string]bool{"has": false, "exists": false} |
| 1795 | for _, expr := range macroCalls { |
| 1796 | f := expr.GetCallExpr().GetFunction() |
| 1797 | _, found := callsFound[f] |
| 1798 | if !found { |
| 1799 | t.Errorf("Unexpected macro call: %v", expr) |
| 1800 | } |
| 1801 | callsFound[f] = true |
| 1802 | } |
| 1803 | callsWanted := map[string]bool{"has": true, "exists": true} |
| 1804 | if !reflect.DeepEqual(callsFound, callsWanted) { |
| 1805 | t.Errorf("Tracked calls %v, but wanted %v", callsFound, callsWanted) |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | func TestParseAndCheckConcurrently(t *testing.T) { |
| 1810 | env := testEnv(t, |
nothing calls this directly
no test coverage detected