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 / linecopy_test.go
linecopy_test.go 2.5K
1package ui23import (4 "testing"56 "src.rest/cat/012/internal/sheet"7)89// Vim's yy and dd copy whole rows, so p and P carry their row formats,10// as a whole-row paste does: the pasted row is bold far past its data.11func TestVimPutCarriesRowFormats(t *testing.T) {12 m := vimModel(t)13 press(t, m, "2G", "<shift+space>")14 m.runCommand("format.bold")15 press(t, m, "<esc>", "yy", "G", "p")16 far := sheet.Addr{Col: 400, Row: 6} // row 7, the pasted one17 if input(m, "A7") != "A2" || !m.sheet.CellStyle(far).Bold {18 t.Fatalf("p: A7 %q, row 7 bold %v", input(m, "A7"), m.sheet.CellStyle(far).Bold)19 }20 if m.sheet.CellStyle(sheet.Addr{Col: 400, Row: 5}).Bold {21 t.Error("row 6 turned bold")22 }23 press(t, m, "u")24 if m.sheet.CellStyle(far).Bold {25 t.Error("undo left row 7 bold")26 }27 // dd then P: the row format moves with the row.28 press(t, m, "2G", "dd", "gg", "P")29 if input(m, "A1") != "A2" || !m.sheet.CellStyle(sheet.Addr{Col: 400}).Bold || m.sheet.CellStyle(sheet.Addr{Col: 400, Row: 1}).Bold {30 t.Errorf("dd P: A1 %q, row 1 bold %v, row 2 bold %v", input(m, "A1"),31 m.sheet.CellStyle(sheet.Addr{Col: 400}).Bold, m.sheet.CellStyle(sheet.Addr{Col: 400, Row: 1}).Bold)32 }33}3435// Copying a whole column and pasting it at the top of another carries36// its column format; cutting one moves it, one undo step each.37func TestCopyColumnCarriesItsFormat(t *testing.T) {38 m := newModel()39 press(t, m, "<right>", "5", "<enter>", "<up>", "<ctrl+space>")40 m.runCommand("format.currency")41 press(t, m, "<ctrl+c>", "<esc>", "<right>", "<right>", "<ctrl+v>")42 if got := line(m, 2); got != "Pasted 1 column at D:D" {43 t.Errorf("context line %q", got)44 }45 if f := m.sheet.DisplayFormat(sheet.Addr{Col: 3, Row: 500}); f.Kind != sheet.FmtCurrency {46 t.Errorf("D501 shows %v, want column B's currency", f.Kind)47 }48 press(t, m, "<ctrl+z>")49 if f := m.sheet.DisplayFormat(sheet.Addr{Col: 3, Row: 500}); !f.IsZero() {50 t.Errorf("after undo D501 shows %v", f.Kind)51 }5253 // Cut column B and paste it at F1: its format goes along.54 press(t, m, "<ctrl+home>", "<right>", "<ctrl+space>", "<ctrl+x>")55 m.clearSelection()56 m.cur = sheet.Addr{Col: 5}57 press(t, m, "<ctrl+v>")58 if got := line(m, 2); got != "Moved B:B to F:F" {59 t.Errorf("context line %q", got)60 }61 if input(m, "F1") != "5" || m.sheet.DisplayFormat(sheet.Addr{Col: 5, Row: 9}).Kind != sheet.FmtCurrency ||62 !m.sheet.DisplayFormat(sheet.Addr{Col: 1, Row: 9}).IsZero() {63 t.Errorf("F1 %q, F10 %v, B10 %v", input(m, "F1"), m.sheet.DisplayFormat(sheet.Addr{Col: 5, Row: 9}).Kind,64 m.sheet.DisplayFormat(sheet.Addr{Col: 1, Row: 9}).Kind)65 }66}