Skip to content
Myr

screen_test.go

This file

Path

screen_test.go

207 lines · 3.9 KiB · Go

Last changed by

fix: prevent data race with cursedRenderer.onMouse (#1691)Liam Stanleybefore adoptionc60f0c5

History of this file

Take it

The walk stopped after 200 commits: lines older than 3dfbcd9 point at it.

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 1–4why, one step back
1package tea
23import (4 "bytes"

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 5why, one step back
5 "image/color"

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 6why, one step back
6 "testing"

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 7–9why, one step back
7
8 "github.com/charmbracelet/colorprofile"9 "github.com/charmbracelet/x/exp/golden"

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 10–11why, one step back
10)
11

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 12–61why, one step back
12type testViewOpts struct {
13 altScreen bool14 mouseMode MouseMode15 showCursor bool16 disableBp bool17 keyReleases bool18 bgColor color.Color19}2021func testViewOptsCmds(opts ...testViewOpts) []Cmd {22 cmds := make([]Cmd, len(opts))23 for i, o := range opts {24 o := o25 cmds[i] = func() Msg {26 return o27 }28 }29 return cmds30}3132type testViewModel struct {33 *testModel34 opts testViewOpts35}3637func (m *testViewModel) Update(msg Msg) (Model, Cmd) {38 switch msg := msg.(type) {39 case testViewOpts:40 m.opts = msg41 return m, nil42 }43 tm, cmd := m.testModel.Update(msg)44 m.testModel = tm.(*testModel)45 return m, cmd46}4748func (m *testViewModel) View() View {49 v := m.testModel.View()50 v.AltScreen = m.opts.altScreen51 v.MouseMode = m.opts.mouseMode52 v.DisableBracketedPasteMode = m.opts.disableBp53 v.KeyboardEnhancements.ReportEventTypes = m.opts.keyReleases54 v.BackgroundColor = m.opts.bgColor55 if m.opts.showCursor {56 v.Cursor = NewCursor(0, 0)57 }58 return v59}6061func TestViewModel(t *testing.T) {

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 62why, one step back
62 tests := []struct {

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 63–64why, one step back
63 name string
64 opts []testViewOpts

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 65–66why, one step back
65 }{
66 {

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 67–71why, one step back
67 name: "altscreen",
68 opts: []testViewOpts{69 {altScreen: true},70 {altScreen: false},71 },

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 72–73why, one step back
72 },
73 {

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 74–77why, one step back
74 name: "altscreen_autoexit",
75 opts: []testViewOpts{76 {altScreen: true},77 },

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 78–79why, one step back
78 },
79 {

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 80–83why, one step back
80 name: "mouse_cellmotion",
81 opts: []testViewOpts{82 {mouseMode: MouseModeCellMotion},83 },

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 84–85why, one step back
84 },
85 {

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 86–89why, one step back
86 name: "mouse_allmotion",
87 opts: []testViewOpts{88 {mouseMode: MouseModeAllMotion},89 },

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 90–91why, one step back
90 },
91 {

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 92–96why, one step back
92 name: "mouse_disable",
93 opts: []testViewOpts{94 {mouseMode: MouseModeAllMotion},95 {mouseMode: MouseModeNone},96 },

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 97–98why, one step back
97 },
98 {

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 99–102why, one step back
99 name: "cursor_hide",
100 opts: []testViewOpts{101 {},102 },

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 103–104why, one step back
103 },
104 {

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 105–109why, one step back
105 name: "cursor_hideshow",
106 opts: []testViewOpts{107 {showCursor: false},108 {showCursor: true},109 },

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 110–111why, one step back
110 },
111 {

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 112–116why, one step back
112 name: "bp_stop_start",
113 opts: []testViewOpts{114 {disableBp: true},115 {disableBp: false},116 },

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 117–118why, one step back
117 },
118 {

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 119–123why, one step back
119 name: "kitty_stop_startreleases",
120 opts: []testViewOpts{121 {},122 {keyReleases: true},123 },

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 124why, one step back
124 },

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 125–130why, one step back
125 {
126 name: "bg_set_color",127 opts: []testViewOpts{128 {bgColor: color.RGBA{255, 255, 255, 255}},129 },130 },

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 131–134why, one step back
131 }
132133 for _, test := range tests {134 t.Run(test.name, func(t *testing.T) {

fix: prevent data race with cursedRenderer.onMouse (#1691)Liam Stanleybefore adoptionc60f0c5

line 135why, one step back
135 t.Parallel()

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 136–138why, one step back
136 var buf bytes.Buffer
137 var in bytes.Buffer138

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 139–149why, one step back
139 m := &testViewModel{testModel: &testModel{}}
140 p := NewProgram(m,141 // Set the initial window size for the program.142 WithWindowSize(80, 24),143 // Use ANSI256 to increase test coverage.144 WithColorProfile(colorprofile.ANSI256),145 // always use xterm and 256 colors for tests146 WithEnvironment([]string{"TERM=xterm-256color"}),147 WithInput(&in),148 WithOutput(&buf),149 )

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 150why, one step back
150

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 151why, one step back
151 go p.Send(append(sequenceMsg(testViewOptsCmds(test.opts...)), Quit))

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 152–155why, one step back
152
153 if _, err := p.Run(); err != nil {154 t.Fatal(err)155 }

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 156–159why, one step back
156 golden.RequireEqual(t, buf.Bytes())
157 })158 }159}

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 160why, one step back
160

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 161–182why, one step back
161func TestClearMsg(t *testing.T) {
162 type test struct {163 name string164 cmds sequenceMsg165 }166 tests := []test{167 {168 name: "clear_screen",169 cmds: []Cmd{ClearScreen},170 },171 {172 name: "read_set_clipboard",173 cmds: []Cmd{ReadClipboard, SetClipboard("success")},174 },175 {176 name: "bg_fg_cur_color",177 cmds: []Cmd{RequestForegroundColor, RequestBackgroundColor, RequestCursorColor},178 },179 }180181 for _, test := range tests {182 t.Run(test.name, func(t *testing.T) {

fix: prevent data race with cursedRenderer.onMouse (#1691)Liam Stanleybefore adoptionc60f0c5

line 183why, one step back
183 t.Parallel()

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 184–202why, one step back
184 var buf bytes.Buffer
185 var in bytes.Buffer186187 m := &testModel{}188 p := NewProgram(m,189 // Set the initial window size for the program.190 WithWindowSize(80, 24),191 // Use ANSI256 to increase test coverage.192 WithColorProfile(colorprofile.ANSI256),193 // always use xterm and 256 colors for tests194 WithEnvironment([]string{"TERM=xterm-256color"}),195 WithInput(&in),196 WithOutput(&buf),197 )198199 go p.Send(append(test.cmds, Quit))200201 if _, err := p.Run(); err != nil {202 t.Fatal(err)

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

line 203why, one step back
203 }

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 204why, one step back
204 golden.RequireEqual(t, buf.Bytes())

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 205–207why, one step back
205 })
206 }207}