MCPcopy
hub / github.com/mum4k/termdash / TestCanvas

Function TestCanvas

private/canvas/canvas_test.go:104–541  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

102}
103
104func TestCanvas(t *testing.T) {
105 tests := []struct {
106 desc string
107 canvas image.Rectangle
108 ops func(*Canvas) error
109 want func(size image.Point) (*faketerm.Terminal, error)
110 wantErr bool
111 }{
112 {
113 desc: "SetCellOpts fails on a point outside of the canvas",
114 canvas: image.Rect(0, 0, 1, 1),
115 ops: func(cvs *Canvas) error {
116 return cvs.SetCellOpts(image.Point{1, 1})
117 },
118 wantErr: true,
119 },
120 {
121 desc: "SetCellOpts sets options on a cell with no options",
122 canvas: image.Rect(0, 0, 2, 2),
123 ops: func(cvs *Canvas) error {
124 return cvs.SetCellOpts(image.Point{0, 1}, cell.FgColor(cell.ColorRed), cell.BgColor(cell.ColorBlue))
125 },
126 want: func(size image.Point) (*faketerm.Terminal, error) {
127 ft := faketerm.MustNew(size)
128 cvs, err := New(ft.Area())
129 if err != nil {
130 return nil, err
131 }
132
133 c, err := cvs.Cell(image.Point{0, 1})
134 if err != nil {
135 return nil, err
136 }
137 if _, err := cvs.SetCell(image.Point{0, 1}, c.Rune, cell.FgColor(cell.ColorRed), cell.BgColor(cell.ColorBlue)); err != nil {
138 return nil, err
139 }
140
141 if err := cvs.Apply(ft); err != nil {
142 return nil, err
143 }
144 return ft, nil
145 },
146 },
147 {
148 desc: "SetCellOpts preserves cell rune",
149 canvas: image.Rect(0, 0, 2, 2),
150 ops: func(cvs *Canvas) error {
151 if _, err := cvs.SetCell(image.Point{0, 1}, 'X'); err != nil {
152 return err
153 }
154 return cvs.SetCellOpts(image.Point{0, 1}, cell.FgColor(cell.ColorRed), cell.BgColor(cell.ColorBlue))
155 },
156 want: func(size image.Point) (*faketerm.Terminal, error) {
157 ft := faketerm.MustNew(size)
158 cvs, err := New(ft.Area())
159 if err != nil {
160 return nil, err
161 }

Callers

nothing calls this directly

Calls 15

FgColorFunction · 0.92
BgColorFunction · 0.92
MustNewFunction · 0.92
NewFunction · 0.92
DiffFunction · 0.92
CellMethod · 0.80
SetAreaCellsMethod · 0.80
RunMethod · 0.80
NewFunction · 0.70
SetCellMethod · 0.65
SizeMethod · 0.65
SetCellOptsMethod · 0.45

Tested by

no test coverage detected