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 / e2e / share_test.go
share_test.go 1.9K
1package e2e23import (4 "os"5 "path/filepath"6 "strings"7 "testing"8)910// Two people reach one 012 serve with the system's ssh client, each in11// a terminal of their own, and open the same file: what one types the12// other sees, each sees where the other is, undo takes back only one's13// own change, the first to quit leaves without being asked, and the one14// left saves the file.15func TestServeSharesAFile(t *testing.T) {16 t.Parallel()17 top := t.TempDir()18 served := filepath.Join(top, "served")19 os.Mkdir(served, 0o755)20 sshPath, args := serveSSH(t, top, served)21 args = append(args, "plan.012")2223 ann := startWith(t, options{dir: top, program: sshPath}, asUser("ann", args)...)24 ann.waitFor("plan.012")25 bob := startWith(t, options{dir: top, program: sshPath}, asUser("bob", args)...)26 bob.waitFor("Sharing plan.012 with ann")27 ann.waitFor(" bob ") // on ann's status line2829 ann.keys("rent", "<enter>")30 bob.waitForLine(gridRow1, " 1 â–˜rent") // marked: ann just changed it31 bob.keys("<right>", "<down>", "450", "<enter>")32 ann.waitFor("450")33 // Bob's pointer is on B3 now: his initial is on row 3's header.34 ann.eventually("bob's initial on row 3", func() bool { return strings.HasPrefix(ann.line(gridRow1+2), "b 3") })3536 // Ann's undo takes back her entry, not bob's.37 ann.keys("<ctrl+z>")38 bob.eventually("ann's undo", func() bool { return !strings.Contains(bob.screen(), "rent") })39 if !strings.Contains(bob.screen(), "450") {40 t.Fatalf("ann's undo took back bob's entry:\n%s", bob.screen())41 }4243 bob.keys("<ctrl+q>") // ann still has it: no question44 bob.waitExit()45 ann.eventually("bob gone from the status line", func() bool { return !strings.Contains(ann.line(int(ann.rows)-1), " bob ") })46 ann.keys("<ctrl+s>")47 ann.eventually("plan.012 saved", func() bool {48 data, err := os.ReadFile(filepath.Join(served, "plan.012"))49 return err == nil && strings.Contains(string(data), "450")50 })51 ann.keys("<ctrl+q>")52 ann.waitExit()53}