1package sheet23import (4 "strings"5 "testing"6)78// The hooks pair up like parentheses, a recalculation holding the pivot9// refreshes it causes, and get the workbook's trace back.10func TestTelemetryHooksNest(t *testing.T) {11 w := sales(t)12 newPivot(t, w, func(p *Pivot) {13 p.Rows = []PivotGroup{{Col: 0}}14 p.Values = []PivotValue{{Col: 3, Summarize: SumBy}}15 })16 trace := new(int)17 w.SetTrace(trace)18 var got []string19 var traces []any20 OnBegin = func(tr any, op string) { got, traces = append(got, "("+op), append(traces, tr) }21 OnRecalc = func(tr any, _ RecalcInfo) { got, traces = append(got, "recalc)"), append(traces, tr) }22 OnPivot = func(tr any, _ PivotInfo) { got, traces = append(got, "pivot)"), append(traces, tr) }23 defer func() { OnBegin, OnRecalc, OnPivot = nil, nil, nil }()24 w.Lookup("Sales").Set(at("D2"), "100")25 want := "(recalc (pivot pivot) (recalc recalc) recalc)"26 if s := strings.Join(got, " "); s != want {27 t.Errorf("hooks ran %s, want %s", s, want)28 }29 for _, tr := range traces {30 if tr != trace {31 t.Errorf("hook got trace %v, want the workbook's", tr)32 }33 }34}