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 / follow_test.go
follow_test.go 2.4K
1package e2e23import (4 "fmt"5 "os"6 "path/filepath"7 "strings"8 "testing"9)1011// appendText adds text to the end of a file, as a program logging to it12// does.13func appendText(t *testing.T, name, text string) {14 t.Helper()15 f, err := os.OpenFile(name, os.O_APPEND|os.O_WRONLY, 0)16 if err != nil {17 t.Fatal(err)18 }19 defer f.Close()20 if _, err := f.WriteString(text); err != nil {21 t.Fatal(err)22 }23}2425// linkTable links name at the active cell through the palette, keeping26// every row.27func (s *session) linkTable(name string) {28 s.t.Helper()29 s.linkTableAsk(name)30 s.keys("<enter>")31}3233func TestFollowFileAsItGrows(t *testing.T) {34 t.Parallel()35 dir := t.TempDir()36 log := filepath.Join(dir, "app.csv")37 writeText(t, log, "level,ms\ninfo,12\n")38 s := start(t, dir)39 s.keys("<f5>", "D1", "<enter>", "=SUM(B:B)", "<enter>")40 s.keys("<f5>", "A1", "<enter>")41 s.linkTable("app.csv")42 s.waitFor("info")43 s.waitFor("Sheet1 ●")4445 // Rows appended while 012 follows the file come in, a partial line46 // once it's whole, and the formula over them recalculates.47 for i := range 5 {48 appendText(t, log, fmt.Sprintf("warn,%d\n", 100+i))49 }50 appendText(t, log, "error,")51 s.waitFor("104")52 s.eventually("the sum of the rows", func() bool { return strings.Contains(s.line(4), "522") })53 if strings.Contains(s.screen(), "error") {54 t.Fatalf("a partial line was read:\n%s", s.screen())55 }56 appendText(t, log, "7\n")57 s.waitFor("error")58 s.eventually("the sum with the last row", func() bool { return strings.Contains(s.line(4), "529") })5960 // The context line says what the region is doing.61 s.keys("<f5>", "A3", "<enter>")62 s.waitFor("● Following app.csv 7 rows")6364 // Truncated and written again, it's read from the start.65 writeText(t, log, "level,ms\nreset,1\n")66 s.waitFor("reset")67 s.eventually("the old rows gone", func() bool { return !strings.Contains(s.screen(), "104") })6869 // Paused, it waits; unlinked, the values stay as they are.70 s.keys("<ctrl+k>", "Follow", "<enter>")71 s.waitFor("Paused following app.csv")72 appendText(t, log, "late,2\n")73 s.keys("<up>") // A2, in the region74 s.waitFor("‖ Paused app.csv")75 if strings.Contains(s.screen(), "late") {76 t.Fatalf("a paused region read on:\n%s", s.screen())77 }78 s.keys("<ctrl+k>", "Unlink", "<enter>")79 s.waitFor("Unlinked app.csv")80 s.waitFor("Sheet1 ")81 if strings.Contains(s.line(29), "●") {82 t.Errorf("tab still marked: %q", s.line(29))83 }84}