cat / 012
clone

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

main
012 / e2e / tables_test.go
tables_test.go 1.8K
1package e2e23import (4 "strings"5 "testing"6)78// A table made from the data around the cursor is read by column name,9// grows as rows are typed below it, renames its column in formulas when10// its header changes, and is saved with the file.11func TestTables(t *testing.T) {12 t.Parallel()13 dir := t.TempDir()14 writeTable(t, dir, "stock.012", 4) // Item, Qty over A1:B5; Qty 1 2 3 015 s := start(t, dir, "stock.012")1617 s.keys("<down>", "<ctrl+alt+t>")18 s.waitFor("Name for the table of A1:B5: Table1")19 s.keys("Stock", "<enter>")20 s.waitFor("Stock is a table: read it by column in formulas, e.g. =SUM(Stock[Qty])")2122 // Suggestions offer the table, then its columns.23 s.keys("<esc>", "<ctrl+home>", "<right>", "<right>", "<right>", "=SUM(st")24 s.waitFor("table, A1:B5")25 s.keys("<tab>", "[q")26 s.waitFor("Stock[Item, Qty]")27 s.keys("<tab>", ")", "<enter>")28 s.keys("<up>")29 s.waitForBar("D1", "=SUM(Stock[Qty])")30 s.waitFor("6")3132 // A row typed just below joins the table.33 s.keys("<ctrl+home>", "<ctrl+down>", "<down>", "Row 5", "<tab>", "10", "<enter>")34 s.keys("<ctrl+home>", "<right>", "<right>", "<right>")35 s.waitForBar("D1", "=SUM(Stock[Qty])")36 s.eventually("the sum reads the new row", func() bool { return strings.Contains(s.line(gridRow1), "16") })3738 // Renaming the header renames the column in the formula.39 s.keys("<left>", "<left>", "Count", "<enter>")40 s.keys("<up>", "<right>", "<right>")41 s.waitForBar("D1", "=SUM(Stock[Count])")42 s.keys("<left>", "<left>", "<down>")43 s.waitFor("Table Stock, column Count: Stock[Count] in formulas")4445 // The table and its formula survive saving and opening again.46 s.keys("<ctrl+s>")47 s.eventually("saved", func() bool { return !strings.Contains(s.line(29), "modified") })48 s2 := start(t, dir, "stock.012")49 s2.keys("<right>", "<down>")50 s2.waitFor("Table Stock, column Count")51 s2.waitFor("16")52}