cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

main
012 / internal / sheet / randedit_sources_test.go
randedit_sources_test.go 1.7K
1package sheet23import "fmt"45// Linked sources among the random edits (randedit_test.go): linked,6// ordered, their tabs renamed and deleted, and formulas reading them,7// so the tabs, their order in the file and the formulas naming them8// meet every other edit. Nothing answers the workbook's questions about9// them, as a file opened without a host: what reads them stays Loading…10// through undo, redo and reopening alike.1112func init() { randEdits = append(randEdits, (*randBook).editSource) }1314// randSources are the names the edits give sources.15var randSources = []string{"big", "huge"}1617func (r *randBook) editSource(e *edits) string {18 w := r.wb19 name := randSources[e.n(len(randSources))]20 switch e.n(5) {21 case 0:22 _, err := w.AddSource(name, LinkSource{Path: name + ".parquet"}, r.sheet(e))23 return fmt.Sprintf("link source %s (%v)", name, err)24 case 1:25 o := &SourceOrder{}26 if e.n(2) == 0 {27 o.Sort = []SourceSort{{Col: e.n(3), Desc: e.n(2) == 0}}28 }29 if e.n(2) == 0 {30 o.Filter = []SourceFilter{{Col: e.n(3), Cond: Condition{Op: CondGreater, Arg: fmt.Sprint(e.n(9))}}}31 }32 err := w.SetSourceOrder(name, o)33 return fmt.Sprintf("order %s %+v (%v)", name, o, err)34 case 2:35 info, ok := w.LookupSource(name)36 if !ok {37 return "no source " + name38 }39 err := w.DeleteSheet(info.Sheet)40 return fmt.Sprintf("delete source %s (%v)", name, err)41 }42 s, a := r.sheet(e), e.addr()43 in := []string{44 "=SUM(" + name + "[amount])", `=COUNTIF(` + name + `[region],"x")`, "=ROWS(nu." + name + ")",45 "=" + name + "!B3", "=IFERROR(XLOOKUP(1," + name + "[id]," + name + "[amount]),0)",46 }[e.n(5)]47 err := s.Set(a, in)48 return fmt.Sprintf("%s!%s = %q (%v)", s.name, a, in, err)49}