cat / 012
clone

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

UI tests: the stress benchmarks' fake terminal and color-scale sheet in an untagged file

Dami committed 49b7f26
So tests outside -tags stress draw the same frames.
commit
49b7f2640d0e2bfabd76bb81fb8b249988e71499
parent
92e5253fa14897097fc97c6f1c28f2d8bd5d5af4
author
Dami <dami.etoile@gmail.com>
kind
test risk score 0.5 of 3, Jev's estimate
2 files changed, +53 -40
Ainternal/ui/faketerm_test.go53++++++++++++++++++++++++++++++
Minternal/ui/stress_test.go40-----------------------
A internal/ui/faketerm_test.go +53 -0
@@ -0,0 +1,53 @@
1+package ui2+3+import (4+ "io"5+6+ tea "charm.land/bubbletea/v2"7+ uv "github.com/charmbracelet/ultraviolet"8+9+ "github.com/FelineStateMachine/012/internal/sheet"10+ "github.com/FelineStateMachine/012/internal/stress"11+)12+13+// The shapes and the fake terminal below are shared by the stress14+// benchmarks (stress_test.go) and the speed gate (speed_test.go), so15+// both draw the same frames.16+17+// scaled is dense-8192x26 under a 3-point color scale over all of it,18+// every visible cell a shade: what conditional formatting costs a frame.19+func scaled() *sheet.Sheet {20+ s := stress.Dense(stress.Rows, 26)21+ f, err := sheet.ParseCondFormat(`{"ranges":"A1:Z8192","scale":[{"type":"min","color":"red"},{"type":"percentile","value":"50","color":"yellow"},{"type":"max","color":"green"}]}`)22+ if err != nil || s.LoadCondFormats([]sheet.CondFormat{f}) > 0 {23+ panic(err)24+ }25+ return s26+}27+28+// fakeTerm stands in for Bubble Tea's renderer: a cell buffer the frame29+// is drawn into and a terminal renderer diffing it to io.Discard.30+type fakeTerm struct {31+ buf uv.ScreenBuffer32+ scr *uv.TerminalRenderer33+}34+35+func newFakeTerm(w, h int) *fakeTerm {36+ t := &fakeTerm{buf: uv.NewScreenBuffer(w, h), scr: uv.NewTerminalRenderer(io.Discard, nil)}37+ t.scr.Resize(w, h)38+ return t39+}40+41+func (t *fakeTerm) frame(m *Model) {42+ v := m.View()43+ t.buf.Clear()44+ uv.NewStyledString(v.Content).Draw(t.buf, t.buf.Bounds())45+ t.scr.Render(t.buf.RenderBuffer)46+ t.scr.Flush()47+}48+49+func sized(s *sheet.Sheet, w, h int) *Model {50+ m := New(s, "")51+ m.Update(tea.WindowSizeMsg{Width: w, Height: h})52+ return m53+}
M internal/ui/stress_test.go +0 -40
@@ -10,7 +10,6 @@ package ui
1010 import (1111 "context"1212 "fmt"13- "io"1413 "log/slog"1514 "path/filepath"1615 "strings"
@@ -19,7 +18,6 @@ import (
1918 2019 tea "charm.land/bubbletea/v2"2120 typesafe "github.com/FelineStateMachine/typesafe-go"22- uv "github.com/charmbracelet/ultraviolet"2321 2422 "github.com/FelineStateMachine/012/internal/jev"2523 "github.com/FelineStateMachine/012/internal/sheet"
@@ -75,44 +73,6 @@ func barred() *sheet.Sheet {
7573 return s7674 }7775 78-// scaled is dense-8192x26 under a 3-point color scale over all of it,79-// every visible cell a shade: what conditional formatting costs a frame.80-func scaled() *sheet.Sheet {81- s := stress.Dense(stress.Rows, 26)82- f, err := sheet.ParseCondFormat(`{"ranges":"A1:Z8192","scale":[{"type":"min","color":"red"},{"type":"percentile","value":"50","color":"yellow"},{"type":"max","color":"green"}]}`)83- if err != nil || s.LoadCondFormats([]sheet.CondFormat{f}) > 0 {84- panic(err)85- }86- return s87-}88-89-// fakeTerm stands in for Bubble Tea's renderer: a cell buffer the frame90-// is drawn into and a terminal renderer diffing it to io.Discard.91-type fakeTerm struct {92- buf uv.ScreenBuffer93- scr *uv.TerminalRenderer94-}95-96-func newFakeTerm(w, h int) *fakeTerm {97- t := &fakeTerm{buf: uv.NewScreenBuffer(w, h), scr: uv.NewTerminalRenderer(io.Discard, nil)}98- t.scr.Resize(w, h)99- return t100-}101-102-func (t *fakeTerm) frame(m *Model) {103- v := m.View()104- t.buf.Clear()105- uv.NewStyledString(v.Content).Draw(t.buf, t.buf.Bounds())106- t.scr.Render(t.buf.RenderBuffer)107- t.scr.Flush()108-}109-110-func sized(s *sheet.Sheet, w, h int) *Model {111- m := New(s, "")112- m.Update(tea.WindowSizeMsg{Width: w, Height: h})113- return m114-}115-11676 // BenchmarkView is View alone: 012's share of a frame.11777 func BenchmarkView(b *testing.B) {11878 for _, sh := range uiShapes() {