cat / 012
clone

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

cat/module-path
012 / internal / ui / undocost_test.go
undocost_test.go 1.5K
1package ui23import (4 "strings"5 "testing"67 "src.rest/cat/012/internal/sheet"8 "src.rest/cat/012/internal/ui/choicebar"9)1011// A change whose undo step would pass the ceiling asks first: Esc backs12// out, Enter runs it without undo and forgets the history.13func TestUndoCostAsks(t *testing.T) {14 defer func(n int64) { maxStepBytes = n }(maxStepBytes)15 maxStepBytes = 10016 m := newModel()17 press(t, m, "1", "<enter>", "2", "<enter>", "3", "<enter>", "4", "<enter>", "5", "<enter>", "6", "<enter>", "7", "<enter>")18 press(t, m, "<up>", "<shift+up>", "<shift+up>", "<shift+up>", "<shift+up>", "<shift+up>", "<shift+up>")19 m.runCommand("clear")20 l := line(m, contextLine)21 if _, ok := m.overlay.(*choicebar.Bar); !ok || !strings.Contains(l, "This can't be undone: it would take 0 MB of undo history.") {22 t.Fatalf("clear didn't ask: %q", l)23 }24 press(t, m, "<esc>")25 if m.sheet.Value(addr("A1")).Num != 1 || !m.sheet.CanUndo() {26 t.Fatalf("Esc went on: A1 %v", m.sheet.Value(addr("A1")))27 }28 m.runCommand("clear")29 press(t, m, "<enter>")30 if m.sheet.Value(addr("A1")).Kind != sheet.Empty || m.sheet.CanUndo() || !m.changed {31 t.Fatalf("after Enter: A1 %v, can undo %v, changed %v", m.sheet.Value(addr("A1")), m.sheet.CanUndo(), m.changed)32 }33 // Under the ceiling nothing asks.34 maxStepBytes = sheet.MaxStepBytes35 press(t, m, "8", "<enter>", "<up>")36 m.runCommand("clear")37 if m.overlay != nil || m.sheet.Value(addr("A1")).Kind != sheet.Empty || !m.sheet.CanUndo() {38 t.Errorf("small clear: overlay %T, A1 %v", m.overlay, m.sheet.Value(addr("A1")))39 }40}