| 1 | + | // Copyright 2019 Google Inc. |
| 2 | + | // |
| 3 | + | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + | // you may not use this file except in compliance with the License. |
| 5 | + | // You may obtain a copy of the License at |
| 6 | + | // |
| 7 | + | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + | // |
| 9 | + | // Unless required by applicable law or agreed to in writing, software |
| 10 | + | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + | // See the License for the specific language governing permissions and |
| 13 | + | // limitations under the License. |
| 14 | + | |
| 15 | + | package segment |
| 16 | + | |
| 17 | + | import ( |
| 18 | + | "fmt" |
| 19 | + | "image" |
| 20 | + | "testing" |
| 21 | + | |
| 22 | + | "github.com/mum4k/termdash/area" |
| 23 | + | "github.com/mum4k/termdash/canvas/braille" |
| 24 | + | "github.com/mum4k/termdash/canvas/braille/testbraille" |
| 25 | + | "github.com/mum4k/termdash/cell" |
| 26 | + | "github.com/mum4k/termdash/draw" |
| 27 | + | "github.com/mum4k/termdash/draw/testdraw" |
| 28 | + | "github.com/mum4k/termdash/terminal/faketerm" |
| 29 | + | ) |
| 30 | + | |
| 31 | + | func TestHV(t *testing.T) { |
| 32 | + | tests := []struct { |
| 33 | + | desc string |
| 34 | + | opts []Option |
| 35 | + | cellCanvas image.Rectangle // Canvas in cells that will be converted to braille canvas for drawing. |
| 36 | + | ar image.Rectangle |
| 37 | + | st Type |
| 38 | + | want func(size image.Point) *faketerm.Terminal |
| 39 | + | wantErr bool |
| 40 | + | }{ |
| 41 | + | { |
| 42 | + | desc: "fails on area with negative Min.X", |
| 43 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 44 | + | ar: image.Rect(-1, 0, 1, 1), |
| 45 | + | st: Horizontal, |
| 46 | + | wantErr: true, |
| 47 | + | }, |
| 48 | + | { |
| 49 | + | desc: "fails on area with negative Min.Y", |
| 50 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 51 | + | ar: image.Rect(0, -1, 1, 1), |
| 52 | + | st: Horizontal, |
| 53 | + | wantErr: true, |
| 54 | + | }, |
| 55 | + | { |
| 56 | + | desc: "fails on area with negative Max.X", |
| 57 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 58 | + | ar: image.Rectangle{image.Point{0, 0}, image.Point{-1, 1}}, |
| 59 | + | st: Horizontal, |
| 60 | + | wantErr: true, |
| 61 | + | }, |
| 62 | + | { |
| 63 | + | desc: "fails on area with negative Max.Y", |
| 64 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 65 | + | ar: image.Rectangle{image.Point{0, 0}, image.Point{1, -1}}, |
| 66 | + | st: Horizontal, |
| 67 | + | wantErr: true, |
| 68 | + | }, |
| 69 | + | { |
| 70 | + | desc: "fails on area with zero Dx()", |
| 71 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 72 | + | ar: image.Rect(0, 0, 0, 1), |
| 73 | + | st: Horizontal, |
| 74 | + | wantErr: true, |
| 75 | + | }, |
| 76 | + | { |
| 77 | + | desc: "fails on area with zero Dy()", |
| 78 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 79 | + | ar: image.Rect(0, 0, 1, 0), |
| 80 | + | st: Horizontal, |
| 81 | + | wantErr: true, |
| 82 | + | }, |
| 83 | + | { |
| 84 | + | desc: "fails on unsupported segment type (too small)", |
| 85 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 86 | + | ar: image.Rect(0, 0, 2, 2), |
| 87 | + | st: Type(0), |
| 88 | + | wantErr: true, |
| 89 | + | }, |
| 90 | + | { |
| 91 | + | desc: "fails on unsupported segment type (too large)", |
| 92 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 93 | + | ar: image.Rect(0, 0, 2, 2), |
| 94 | + | st: Type(int(Vertical) + 1), |
| 95 | + | wantErr: true, |
| 96 | + | }, |
| 97 | + | { |
| 98 | + | desc: "fails on area larger than the canvas", |
| 99 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 100 | + | ar: image.Rect(0, 0, 3, 1), |
| 101 | + | st: Horizontal, |
| 102 | + | wantErr: true, |
| 103 | + | }, |
| 104 | + | { |
| 105 | + | desc: "sets cell options", |
| 106 | + | opts: []Option{ |
| 107 | + | CellOpts( |
| 108 | + | cell.FgColor(cell.ColorRed), |
| 109 | + | cell.BgColor(cell.ColorGreen), |
| 110 | + | ), |
| 111 | + | }, |
| 112 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 113 | + | ar: image.Rect(0, 0, 1, 1), |
| 114 | + | st: Horizontal, |
| 115 | + | want: func(size image.Point) *faketerm.Terminal { |
| 116 | + | ft := faketerm.MustNew(size) |
| 117 | + | bc := testbraille.MustNew(ft.Area()) |
| 118 | + | |
| 119 | + | testbraille.MustSetPixel(bc, image.Point{0, 0}, cell.FgColor(cell.ColorRed), cell.BgColor(cell.ColorGreen)) |
| 120 | + | testbraille.MustApply(bc, ft) |
| 121 | + | return ft |
| 122 | + | }, |
| 123 | + | }, |
| 124 | + | { |
| 125 | + | desc: "horizontal, segment 1x1", |
| 126 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 127 | + | ar: image.Rect(0, 0, 1, 1), |
| 128 | + | st: Horizontal, |
| 129 | + | want: func(size image.Point) *faketerm.Terminal { |
| 130 | + | ft := faketerm.MustNew(size) |
| 131 | + | bc := testbraille.MustNew(ft.Area()) |
| 132 | + | |
| 133 | + | testbraille.MustSetPixel(bc, image.Point{0, 0}) |
| 134 | + | testbraille.MustApply(bc, ft) |
| 135 | + | return ft |
| 136 | + | }, |
| 137 | + | }, |
| 138 | + | { |
| 139 | + | desc: "horizontal, segment 1x2", |
| 140 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 141 | + | ar: image.Rect(0, 0, 1, 2), |
| 142 | + | st: Horizontal, |
| 143 | + | want: func(size image.Point) *faketerm.Terminal { |
| 144 | + | ft := faketerm.MustNew(size) |
| 145 | + | bc := testbraille.MustNew(ft.Area()) |
| 146 | + | |
| 147 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{0, 0}) |
| 148 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{0, 1}) |
| 149 | + | testbraille.MustApply(bc, ft) |
| 150 | + | return ft |
| 151 | + | }, |
| 152 | + | }, |
| 153 | + | { |
| 154 | + | desc: "horizontal, segment 1x3", |
| 155 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 156 | + | ar: image.Rect(0, 0, 1, 3), |
| 157 | + | st: Horizontal, |
| 158 | + | want: func(size image.Point) *faketerm.Terminal { |
| 159 | + | ft := faketerm.MustNew(size) |
| 160 | + | bc := testbraille.MustNew(ft.Area()) |
| 161 | + | |
| 162 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{0, 0}) |
| 163 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{0, 1}) |
| 164 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{0, 2}) |
| 165 | + | testbraille.MustApply(bc, ft) |
| 166 | + | return ft |
| 167 | + | }, |
| 168 | + | }, |
| 169 | + | { |
| 170 | + | desc: "horizontal, segment 1x4", |
| 171 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 172 | + | ar: image.Rect(0, 0, 1, 4), |
| 173 | + | st: Horizontal, |
| 174 | + | want: func(size image.Point) *faketerm.Terminal { |
| 175 | + | ft := faketerm.MustNew(size) |
| 176 | + | bc := testbraille.MustNew(ft.Area()) |
| 177 | + | |
| 178 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{0, 0}) |
| 179 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{0, 1}) |
| 180 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{0, 2}) |
| 181 | + | testdraw.MustBrailleLine(bc, image.Point{0, 3}, image.Point{0, 3}) |
| 182 | + | testbraille.MustApply(bc, ft) |
| 183 | + | return ft |
| 184 | + | }, |
| 185 | + | }, |
| 186 | + | { |
| 187 | + | desc: "horizontal, segment 1x5", |
| 188 | + | cellCanvas: image.Rect(0, 0, 1, 2), |
| 189 | + | ar: image.Rect(0, 0, 1, 5), |
| 190 | + | st: Horizontal, |
| 191 | + | want: func(size image.Point) *faketerm.Terminal { |
| 192 | + | ft := faketerm.MustNew(size) |
| 193 | + | bc := testbraille.MustNew(ft.Area()) |
| 194 | + | |
| 195 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{0, 0}) |
| 196 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{0, 1}) |
| 197 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{0, 2}) |
| 198 | + | testdraw.MustBrailleLine(bc, image.Point{0, 3}, image.Point{0, 3}) |
| 199 | + | testdraw.MustBrailleLine(bc, image.Point{0, 4}, image.Point{0, 4}) |
| 200 | + | testbraille.MustApply(bc, ft) |
| 201 | + | return ft |
| 202 | + | }, |
| 203 | + | }, |
| 204 | + | { |
| 205 | + | desc: "horizontal, segment 2x1", |
| 206 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 207 | + | ar: image.Rect(0, 0, 2, 1), |
| 208 | + | st: Horizontal, |
| 209 | + | want: func(size image.Point) *faketerm.Terminal { |
| 210 | + | ft := faketerm.MustNew(size) |
| 211 | + | bc := testbraille.MustNew(ft.Area()) |
| 212 | + | |
| 213 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{1, 0}) |
| 214 | + | testbraille.MustApply(bc, ft) |
| 215 | + | return ft |
| 216 | + | }, |
| 217 | + | }, |
| 218 | + | { |
| 219 | + | desc: "horizontal, segment 2x2", |
| 220 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 221 | + | ar: image.Rect(0, 0, 2, 2), |
| 222 | + | st: Horizontal, |
| 223 | + | want: func(size image.Point) *faketerm.Terminal { |
| 224 | + | ft := faketerm.MustNew(size) |
| 225 | + | bc := testbraille.MustNew(ft.Area()) |
| 226 | + | |
| 227 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{1, 0}) |
| 228 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{1, 1}) |
| 229 | + | testbraille.MustApply(bc, ft) |
| 230 | + | return ft |
| 231 | + | }, |
| 232 | + | }, |
| 233 | + | { |
| 234 | + | desc: "horizontal, segment 2x3", |
| 235 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 236 | + | ar: image.Rect(0, 0, 2, 3), |
| 237 | + | st: Horizontal, |
| 238 | + | want: func(size image.Point) *faketerm.Terminal { |
| 239 | + | ft := faketerm.MustNew(size) |
| 240 | + | bc := testbraille.MustNew(ft.Area()) |
| 241 | + | |
| 242 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{1, 0}) |
| 243 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{1, 1}) |
| 244 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{1, 2}) |
| 245 | + | testbraille.MustApply(bc, ft) |
| 246 | + | return ft |
| 247 | + | }, |
| 248 | + | }, |
| 249 | + | { |
| 250 | + | desc: "horizontal, segment 2x4", |
| 251 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 252 | + | ar: image.Rect(0, 0, 2, 4), |
| 253 | + | st: Horizontal, |
| 254 | + | want: func(size image.Point) *faketerm.Terminal { |
| 255 | + | ft := faketerm.MustNew(size) |
| 256 | + | bc := testbraille.MustNew(ft.Area()) |
| 257 | + | |
| 258 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{1, 0}) |
| 259 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{1, 1}) |
| 260 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{1, 2}) |
| 261 | + | testdraw.MustBrailleLine(bc, image.Point{0, 3}, image.Point{1, 3}) |
| 262 | + | testbraille.MustApply(bc, ft) |
| 263 | + | return ft |
| 264 | + | }, |
| 265 | + | }, |
| 266 | + | { |
| 267 | + | desc: "horizontal, segment 2x5", |
| 268 | + | cellCanvas: image.Rect(0, 0, 1, 2), |
| 269 | + | ar: image.Rect(0, 0, 2, 5), |
| 270 | + | st: Horizontal, |
| 271 | + | want: func(size image.Point) *faketerm.Terminal { |
| 272 | + | ft := faketerm.MustNew(size) |
| 273 | + | bc := testbraille.MustNew(ft.Area()) |
| 274 | + | |
| 275 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{1, 0}) |
| 276 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{1, 1}) |
| 277 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{1, 2}) |
| 278 | + | testdraw.MustBrailleLine(bc, image.Point{0, 3}, image.Point{1, 3}) |
| 279 | + | testdraw.MustBrailleLine(bc, image.Point{0, 4}, image.Point{1, 4}) |
| 280 | + | testbraille.MustApply(bc, ft) |
| 281 | + | return ft |
| 282 | + | }, |
| 283 | + | }, |
| 284 | + | { |
| 285 | + | desc: "horizontal, segment 3x1", |
| 286 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 287 | + | ar: image.Rect(0, 0, 3, 1), |
| 288 | + | st: Horizontal, |
| 289 | + | want: func(size image.Point) *faketerm.Terminal { |
| 290 | + | ft := faketerm.MustNew(size) |
| 291 | + | bc := testbraille.MustNew(ft.Area()) |
| 292 | + | |
| 293 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{2, 0}) |
| 294 | + | testbraille.MustApply(bc, ft) |
| 295 | + | return ft |
| 296 | + | }, |
| 297 | + | }, |
| 298 | + | { |
| 299 | + | desc: "horizontal, segment 3x2", |
| 300 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 301 | + | ar: image.Rect(0, 0, 3, 2), |
| 302 | + | st: Horizontal, |
| 303 | + | want: func(size image.Point) *faketerm.Terminal { |
| 304 | + | ft := faketerm.MustNew(size) |
| 305 | + | bc := testbraille.MustNew(ft.Area()) |
| 306 | + | |
| 307 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{1, 0}) |
| 308 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 1}) |
| 309 | + | testbraille.MustApply(bc, ft) |
| 310 | + | return ft |
| 311 | + | }, |
| 312 | + | }, |
| 313 | + | { |
| 314 | + | desc: "horizontal, segment 3x2, reverse slopes", |
| 315 | + | opts: []Option{ |
| 316 | + | ReverseSlopes(), |
| 317 | + | }, |
| 318 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 319 | + | ar: image.Rect(0, 0, 3, 2), |
| 320 | + | st: Horizontal, |
| 321 | + | want: func(size image.Point) *faketerm.Terminal { |
| 322 | + | ft := faketerm.MustNew(size) |
| 323 | + | bc := testbraille.MustNew(ft.Area()) |
| 324 | + | |
| 325 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{2, 0}) |
| 326 | + | testdraw.MustBrailleLine(bc, image.Point{1, 1}, image.Point{1, 1}) |
| 327 | + | testbraille.MustApply(bc, ft) |
| 328 | + | return ft |
| 329 | + | }, |
| 330 | + | }, |
| 331 | + | { |
| 332 | + | desc: "horizontal, segment 3x3", |
| 333 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 334 | + | ar: image.Rect(0, 0, 3, 3), |
| 335 | + | st: Horizontal, |
| 336 | + | want: func(size image.Point) *faketerm.Terminal { |
| 337 | + | ft := faketerm.MustNew(size) |
| 338 | + | bc := testbraille.MustNew(ft.Area()) |
| 339 | + | |
| 340 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{1, 0}) |
| 341 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 1}) |
| 342 | + | testdraw.MustBrailleLine(bc, image.Point{1, 2}, image.Point{1, 2}) |
| 343 | + | testbraille.MustApply(bc, ft) |
| 344 | + | return ft |
| 345 | + | }, |
| 346 | + | }, |
| 347 | + | { |
| 348 | + | desc: "horizontal, segment 3x3, reverse slopes has no effect on larger height", |
| 349 | + | opts: []Option{ |
| 350 | + | ReverseSlopes(), |
| 351 | + | }, |
| 352 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 353 | + | ar: image.Rect(0, 0, 3, 3), |
| 354 | + | st: Horizontal, |
| 355 | + | want: func(size image.Point) *faketerm.Terminal { |
| 356 | + | ft := faketerm.MustNew(size) |
| 357 | + | bc := testbraille.MustNew(ft.Area()) |
| 358 | + | |
| 359 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{1, 0}) |
| 360 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 1}) |
| 361 | + | testdraw.MustBrailleLine(bc, image.Point{1, 2}, image.Point{1, 2}) |
| 362 | + | testbraille.MustApply(bc, ft) |
| 363 | + | return ft |
| 364 | + | }, |
| 365 | + | }, |
| 366 | + | { |
| 367 | + | desc: "horizontal, segment 3x3, skip slopes", |
| 368 | + | opts: []Option{ |
| 369 | + | SkipSlopesLTE(3), |
| 370 | + | }, |
| 371 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 372 | + | ar: image.Rect(0, 0, 3, 3), |
| 373 | + | st: Horizontal, |
| 374 | + | want: func(size image.Point) *faketerm.Terminal { |
| 375 | + | ft := faketerm.MustNew(size) |
| 376 | + | bc := testbraille.MustNew(ft.Area()) |
| 377 | + | |
| 378 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{2, 0}) |
| 379 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 1}) |
| 380 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{2, 2}) |
| 381 | + | testbraille.MustApply(bc, ft) |
| 382 | + | return ft |
| 383 | + | }, |
| 384 | + | }, |
| 385 | + | { |
| 386 | + | desc: "horizontal, segment 3x3, doesn't skip slopes because is taller", |
| 387 | + | opts: []Option{ |
| 388 | + | SkipSlopesLTE(2), |
| 389 | + | }, |
| 390 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 391 | + | ar: image.Rect(0, 0, 3, 3), |
| 392 | + | st: Horizontal, |
| 393 | + | want: func(size image.Point) *faketerm.Terminal { |
| 394 | + | ft := faketerm.MustNew(size) |
| 395 | + | bc := testbraille.MustNew(ft.Area()) |
| 396 | + | |
| 397 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{1, 0}) |
| 398 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 1}) |
| 399 | + | testdraw.MustBrailleLine(bc, image.Point{1, 2}, image.Point{1, 2}) |
| 400 | + | testbraille.MustApply(bc, ft) |
| 401 | + | return ft |
| 402 | + | }, |
| 403 | + | }, |
| 404 | + | { |
| 405 | + | desc: "horizontal, segment 3x4", |
| 406 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 407 | + | ar: image.Rect(0, 0, 3, 4), |
| 408 | + | st: Horizontal, |
| 409 | + | want: func(size image.Point) *faketerm.Terminal { |
| 410 | + | ft := faketerm.MustNew(size) |
| 411 | + | bc := testbraille.MustNew(ft.Area()) |
| 412 | + | |
| 413 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{1, 0}) |
| 414 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 1}) |
| 415 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{2, 2}) |
| 416 | + | testdraw.MustBrailleLine(bc, image.Point{1, 3}, image.Point{1, 3}) |
| 417 | + | testbraille.MustApply(bc, ft) |
| 418 | + | return ft |
| 419 | + | }, |
| 420 | + | }, |
| 421 | + | { |
| 422 | + | desc: "horizontal, segment 3x5", |
| 423 | + | cellCanvas: image.Rect(0, 0, 2, 2), |
| 424 | + | ar: image.Rect(0, 0, 3, 5), |
| 425 | + | st: Horizontal, |
| 426 | + | want: func(size image.Point) *faketerm.Terminal { |
| 427 | + | ft := faketerm.MustNew(size) |
| 428 | + | bc := testbraille.MustNew(ft.Area()) |
| 429 | + | |
| 430 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{1, 0}) |
| 431 | + | testdraw.MustBrailleLine(bc, image.Point{1, 1}, image.Point{1, 1}) |
| 432 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{2, 2}) |
| 433 | + | testdraw.MustBrailleLine(bc, image.Point{1, 3}, image.Point{1, 3}) |
| 434 | + | testdraw.MustBrailleLine(bc, image.Point{1, 4}, image.Point{1, 4}) |
| 435 | + | testbraille.MustApply(bc, ft) |
| 436 | + | return ft |
| 437 | + | }, |
| 438 | + | }, |
| 439 | + | { |
| 440 | + | desc: "horizontal, segment 4x1", |
| 441 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 442 | + | ar: image.Rect(0, 0, 4, 1), |
| 443 | + | st: Horizontal, |
| 444 | + | want: func(size image.Point) *faketerm.Terminal { |
| 445 | + | ft := faketerm.MustNew(size) |
| 446 | + | bc := testbraille.MustNew(ft.Area()) |
| 447 | + | |
| 448 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{3, 0}) |
| 449 | + | testbraille.MustApply(bc, ft) |
| 450 | + | return ft |
| 451 | + | }, |
| 452 | + | }, |
| 453 | + | { |
| 454 | + | desc: "horizontal, segment 4x2", |
| 455 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 456 | + | ar: image.Rect(0, 0, 4, 2), |
| 457 | + | st: Horizontal, |
| 458 | + | want: func(size image.Point) *faketerm.Terminal { |
| 459 | + | ft := faketerm.MustNew(size) |
| 460 | + | bc := testbraille.MustNew(ft.Area()) |
| 461 | + | |
| 462 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{2, 0}) |
| 463 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{3, 1}) |
| 464 | + | testbraille.MustApply(bc, ft) |
| 465 | + | return ft |
| 466 | + | }, |
| 467 | + | }, |
| 468 | + | { |
| 469 | + | desc: "horizontal, segment 4x3", |
| 470 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 471 | + | ar: image.Rect(0, 0, 4, 3), |
| 472 | + | st: Horizontal, |
| 473 | + | want: func(size image.Point) *faketerm.Terminal { |
| 474 | + | ft := faketerm.MustNew(size) |
| 475 | + | bc := testbraille.MustNew(ft.Area()) |
| 476 | + | |
| 477 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{2, 0}) |
| 478 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{3, 1}) |
| 479 | + | testdraw.MustBrailleLine(bc, image.Point{1, 2}, image.Point{2, 2}) |
| 480 | + | testbraille.MustApply(bc, ft) |
| 481 | + | return ft |
| 482 | + | }, |
| 483 | + | }, |
| 484 | + | { |
| 485 | + | desc: "horizontal, segment 4x4", |
| 486 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 487 | + | ar: image.Rect(0, 0, 4, 4), |
| 488 | + | st: Horizontal, |
| 489 | + | want: func(size image.Point) *faketerm.Terminal { |
| 490 | + | ft := faketerm.MustNew(size) |
| 491 | + | bc := testbraille.MustNew(ft.Area()) |
| 492 | + | |
| 493 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{2, 0}) |
| 494 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{3, 1}) |
| 495 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{3, 2}) |
| 496 | + | testdraw.MustBrailleLine(bc, image.Point{1, 3}, image.Point{2, 3}) |
| 497 | + | testbraille.MustApply(bc, ft) |
| 498 | + | return ft |
| 499 | + | }, |
| 500 | + | }, |
| 501 | + | { |
| 502 | + | desc: "horizontal, segment 4x5", |
| 503 | + | cellCanvas: image.Rect(0, 0, 2, 2), |
| 504 | + | ar: image.Rect(0, 0, 4, 5), |
| 505 | + | st: Horizontal, |
| 506 | + | want: func(size image.Point) *faketerm.Terminal { |
| 507 | + | ft := faketerm.MustNew(size) |
| 508 | + | bc := testbraille.MustNew(ft.Area()) |
| 509 | + | |
| 510 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{2, 0}) |
| 511 | + | testdraw.MustBrailleLine(bc, image.Point{1, 1}, image.Point{2, 1}) |
| 512 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{3, 2}) |
| 513 | + | testdraw.MustBrailleLine(bc, image.Point{1, 3}, image.Point{2, 3}) |
| 514 | + | testdraw.MustBrailleLine(bc, image.Point{1, 4}, image.Point{2, 4}) |
| 515 | + | testbraille.MustApply(bc, ft) |
| 516 | + | return ft |
| 517 | + | }, |
| 518 | + | }, |
| 519 | + | { |
| 520 | + | desc: "horizontal, segment 5x1", |
| 521 | + | cellCanvas: image.Rect(0, 0, 3, 1), |
| 522 | + | ar: image.Rect(0, 0, 5, 1), |
| 523 | + | st: Horizontal, |
| 524 | + | want: func(size image.Point) *faketerm.Terminal { |
| 525 | + | ft := faketerm.MustNew(size) |
| 526 | + | bc := testbraille.MustNew(ft.Area()) |
| 527 | + | |
| 528 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{4, 0}) |
| 529 | + | testbraille.MustApply(bc, ft) |
| 530 | + | return ft |
| 531 | + | }, |
| 532 | + | }, |
| 533 | + | { |
| 534 | + | desc: "horizontal, segment 5x2", |
| 535 | + | cellCanvas: image.Rect(0, 0, 3, 1), |
| 536 | + | ar: image.Rect(0, 0, 5, 2), |
| 537 | + | st: Horizontal, |
| 538 | + | want: func(size image.Point) *faketerm.Terminal { |
| 539 | + | ft := faketerm.MustNew(size) |
| 540 | + | bc := testbraille.MustNew(ft.Area()) |
| 541 | + | |
| 542 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{3, 0}) |
| 543 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{4, 1}) |
| 544 | + | testbraille.MustApply(bc, ft) |
| 545 | + | return ft |
| 546 | + | }, |
| 547 | + | }, |
| 548 | + | { |
| 549 | + | desc: "horizontal, segment 5x3", |
| 550 | + | cellCanvas: image.Rect(0, 0, 3, 1), |
| 551 | + | ar: image.Rect(0, 0, 5, 3), |
| 552 | + | st: Horizontal, |
| 553 | + | want: func(size image.Point) *faketerm.Terminal { |
| 554 | + | ft := faketerm.MustNew(size) |
| 555 | + | bc := testbraille.MustNew(ft.Area()) |
| 556 | + | |
| 557 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{3, 0}) |
| 558 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{4, 1}) |
| 559 | + | testdraw.MustBrailleLine(bc, image.Point{1, 2}, image.Point{3, 2}) |
| 560 | + | testbraille.MustApply(bc, ft) |
| 561 | + | return ft |
| 562 | + | }, |
| 563 | + | }, |
| 564 | + | { |
| 565 | + | desc: "horizontal, segment 5x4", |
| 566 | + | cellCanvas: image.Rect(0, 0, 3, 1), |
| 567 | + | ar: image.Rect(0, 0, 5, 4), |
| 568 | + | st: Horizontal, |
| 569 | + | want: func(size image.Point) *faketerm.Terminal { |
| 570 | + | ft := faketerm.MustNew(size) |
| 571 | + | bc := testbraille.MustNew(ft.Area()) |
| 572 | + | |
| 573 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{3, 0}) |
| 574 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{4, 1}) |
| 575 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{4, 2}) |
| 576 | + | testdraw.MustBrailleLine(bc, image.Point{1, 3}, image.Point{3, 3}) |
| 577 | + | testbraille.MustApply(bc, ft) |
| 578 | + | return ft |
| 579 | + | }, |
| 580 | + | }, |
| 581 | + | { |
| 582 | + | desc: "horizontal, segment 5x5", |
| 583 | + | cellCanvas: image.Rect(0, 0, 3, 2), |
| 584 | + | ar: image.Rect(0, 0, 5, 5), |
| 585 | + | st: Horizontal, |
| 586 | + | want: func(size image.Point) *faketerm.Terminal { |
| 587 | + | ft := faketerm.MustNew(size) |
| 588 | + | bc := testbraille.MustNew(ft.Area()) |
| 589 | + | |
| 590 | + | testdraw.MustBrailleLine(bc, image.Point{2, 0}, image.Point{2, 0}) |
| 591 | + | testdraw.MustBrailleLine(bc, image.Point{1, 1}, image.Point{3, 1}) |
| 592 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{4, 2}) |
| 593 | + | testdraw.MustBrailleLine(bc, image.Point{1, 3}, image.Point{3, 3}) |
| 594 | + | testdraw.MustBrailleLine(bc, image.Point{2, 4}, image.Point{2, 4}) |
| 595 | + | testbraille.MustApply(bc, ft) |
| 596 | + | return ft |
| 597 | + | }, |
| 598 | + | }, |
| 599 | + | { |
| 600 | + | desc: "vertical, segment 1x1", |
| 601 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 602 | + | ar: image.Rect(0, 0, 1, 1), |
| 603 | + | st: Vertical, |
| 604 | + | want: func(size image.Point) *faketerm.Terminal { |
| 605 | + | ft := faketerm.MustNew(size) |
| 606 | + | bc := testbraille.MustNew(ft.Area()) |
| 607 | + | |
| 608 | + | testbraille.MustSetPixel(bc, image.Point{0, 0}) |
| 609 | + | testbraille.MustApply(bc, ft) |
| 610 | + | return ft |
| 611 | + | }, |
| 612 | + | }, |
| 613 | + | { |
| 614 | + | desc: "vertical, segment 1x2", |
| 615 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 616 | + | ar: image.Rect(0, 0, 1, 2), |
| 617 | + | st: Vertical, |
| 618 | + | want: func(size image.Point) *faketerm.Terminal { |
| 619 | + | ft := faketerm.MustNew(size) |
| 620 | + | bc := testbraille.MustNew(ft.Area()) |
| 621 | + | |
| 622 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{0, 0}) |
| 623 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{0, 1}) |
| 624 | + | testbraille.MustApply(bc, ft) |
| 625 | + | return ft |
| 626 | + | }, |
| 627 | + | }, |
| 628 | + | { |
| 629 | + | desc: "vertical, segment 1x3", |
| 630 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 631 | + | ar: image.Rect(0, 0, 1, 3), |
| 632 | + | st: Vertical, |
| 633 | + | want: func(size image.Point) *faketerm.Terminal { |
| 634 | + | ft := faketerm.MustNew(size) |
| 635 | + | bc := testbraille.MustNew(ft.Area()) |
| 636 | + | |
| 637 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{0, 0}) |
| 638 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{0, 1}) |
| 639 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{0, 2}) |
| 640 | + | testbraille.MustApply(bc, ft) |
| 641 | + | return ft |
| 642 | + | }, |
| 643 | + | }, |
| 644 | + | { |
| 645 | + | desc: "vertical, segment 1x4", |
| 646 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 647 | + | ar: image.Rect(0, 0, 1, 4), |
| 648 | + | st: Vertical, |
| 649 | + | want: func(size image.Point) *faketerm.Terminal { |
| 650 | + | ft := faketerm.MustNew(size) |
| 651 | + | bc := testbraille.MustNew(ft.Area()) |
| 652 | + | |
| 653 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{0, 0}) |
| 654 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{0, 1}) |
| 655 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{0, 2}) |
| 656 | + | testdraw.MustBrailleLine(bc, image.Point{0, 3}, image.Point{0, 3}) |
| 657 | + | testbraille.MustApply(bc, ft) |
| 658 | + | return ft |
| 659 | + | }, |
| 660 | + | }, |
| 661 | + | { |
| 662 | + | desc: "vertical, segment 1x5", |
| 663 | + | cellCanvas: image.Rect(0, 0, 1, 2), |
| 664 | + | ar: image.Rect(0, 0, 1, 5), |
| 665 | + | st: Vertical, |
| 666 | + | want: func(size image.Point) *faketerm.Terminal { |
| 667 | + | ft := faketerm.MustNew(size) |
| 668 | + | bc := testbraille.MustNew(ft.Area()) |
| 669 | + | |
| 670 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{0, 0}) |
| 671 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{0, 1}) |
| 672 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{0, 2}) |
| 673 | + | testdraw.MustBrailleLine(bc, image.Point{0, 3}, image.Point{0, 3}) |
| 674 | + | testdraw.MustBrailleLine(bc, image.Point{0, 4}, image.Point{0, 4}) |
| 675 | + | testbraille.MustApply(bc, ft) |
| 676 | + | return ft |
| 677 | + | }, |
| 678 | + | }, |
| 679 | + | { |
| 680 | + | desc: "vertical, segment 2x1", |
| 681 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 682 | + | ar: image.Rect(0, 0, 2, 1), |
| 683 | + | st: Vertical, |
| 684 | + | want: func(size image.Point) *faketerm.Terminal { |
| 685 | + | ft := faketerm.MustNew(size) |
| 686 | + | bc := testbraille.MustNew(ft.Area()) |
| 687 | + | |
| 688 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{1, 0}) |
| 689 | + | testbraille.MustApply(bc, ft) |
| 690 | + | return ft |
| 691 | + | }, |
| 692 | + | }, |
| 693 | + | { |
| 694 | + | desc: "vertical, segment 2x2", |
| 695 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 696 | + | ar: image.Rect(0, 0, 2, 2), |
| 697 | + | st: Vertical, |
| 698 | + | want: func(size image.Point) *faketerm.Terminal { |
| 699 | + | ft := faketerm.MustNew(size) |
| 700 | + | bc := testbraille.MustNew(ft.Area()) |
| 701 | + | |
| 702 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{1, 0}) |
| 703 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{1, 1}) |
| 704 | + | testbraille.MustApply(bc, ft) |
| 705 | + | return ft |
| 706 | + | }, |
| 707 | + | }, |
| 708 | + | { |
| 709 | + | desc: "vertical, segment 2x3", |
| 710 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 711 | + | ar: image.Rect(0, 0, 2, 3), |
| 712 | + | st: Vertical, |
| 713 | + | want: func(size image.Point) *faketerm.Terminal { |
| 714 | + | ft := faketerm.MustNew(size) |
| 715 | + | bc := testbraille.MustNew(ft.Area()) |
| 716 | + | |
| 717 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{1, 0}) |
| 718 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{1, 1}) |
| 719 | + | testdraw.MustBrailleLine(bc, image.Point{1, 2}, image.Point{1, 2}) |
| 720 | + | testbraille.MustApply(bc, ft) |
| 721 | + | return ft |
| 722 | + | }, |
| 723 | + | }, |
| 724 | + | { |
| 725 | + | desc: "vertical, segment 2x3, reverse slopes", |
| 726 | + | opts: []Option{ |
| 727 | + | ReverseSlopes(), |
| 728 | + | }, |
| 729 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 730 | + | ar: image.Rect(0, 0, 2, 3), |
| 731 | + | st: Vertical, |
| 732 | + | want: func(size image.Point) *faketerm.Terminal { |
| 733 | + | ft := faketerm.MustNew(size) |
| 734 | + | bc := testbraille.MustNew(ft.Area()) |
| 735 | + | |
| 736 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{0, 0}) |
| 737 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{1, 1}) |
| 738 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{0, 2}) |
| 739 | + | testbraille.MustApply(bc, ft) |
| 740 | + | return ft |
| 741 | + | }, |
| 742 | + | }, |
| 743 | + | { |
| 744 | + | desc: "vertical, segment 2x4", |
| 745 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 746 | + | ar: image.Rect(0, 0, 2, 4), |
| 747 | + | st: Vertical, |
| 748 | + | want: func(size image.Point) *faketerm.Terminal { |
| 749 | + | ft := faketerm.MustNew(size) |
| 750 | + | bc := testbraille.MustNew(ft.Area()) |
| 751 | + | |
| 752 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{1, 0}) |
| 753 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{1, 1}) |
| 754 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{1, 2}) |
| 755 | + | testdraw.MustBrailleLine(bc, image.Point{1, 3}, image.Point{1, 3}) |
| 756 | + | testbraille.MustApply(bc, ft) |
| 757 | + | return ft |
| 758 | + | }, |
| 759 | + | }, |
| 760 | + | { |
| 761 | + | desc: "vertical, segment 2x5", |
| 762 | + | cellCanvas: image.Rect(0, 0, 1, 2), |
| 763 | + | ar: image.Rect(0, 0, 2, 5), |
| 764 | + | st: Vertical, |
| 765 | + | want: func(size image.Point) *faketerm.Terminal { |
| 766 | + | ft := faketerm.MustNew(size) |
| 767 | + | bc := testbraille.MustNew(ft.Area()) |
| 768 | + | |
| 769 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{1, 0}) |
| 770 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{1, 1}) |
| 771 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{1, 2}) |
| 772 | + | testdraw.MustBrailleLine(bc, image.Point{0, 3}, image.Point{1, 3}) |
| 773 | + | testdraw.MustBrailleLine(bc, image.Point{1, 4}, image.Point{1, 4}) |
| 774 | + | testbraille.MustApply(bc, ft) |
| 775 | + | return ft |
| 776 | + | }, |
| 777 | + | }, |
| 778 | + | { |
| 779 | + | desc: "vertical, segment 3x1", |
| 780 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 781 | + | ar: image.Rect(0, 0, 3, 1), |
| 782 | + | st: Vertical, |
| 783 | + | want: func(size image.Point) *faketerm.Terminal { |
| 784 | + | ft := faketerm.MustNew(size) |
| 785 | + | bc := testbraille.MustNew(ft.Area()) |
| 786 | + | |
| 787 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{2, 0}) |
| 788 | + | testbraille.MustApply(bc, ft) |
| 789 | + | return ft |
| 790 | + | }, |
| 791 | + | }, |
| 792 | + | { |
| 793 | + | desc: "vertical, segment 3x2", |
| 794 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 795 | + | ar: image.Rect(0, 0, 3, 2), |
| 796 | + | st: Vertical, |
| 797 | + | want: func(size image.Point) *faketerm.Terminal { |
| 798 | + | ft := faketerm.MustNew(size) |
| 799 | + | bc := testbraille.MustNew(ft.Area()) |
| 800 | + | |
| 801 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{2, 0}) |
| 802 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 1}) |
| 803 | + | testbraille.MustApply(bc, ft) |
| 804 | + | return ft |
| 805 | + | }, |
| 806 | + | }, |
| 807 | + | { |
| 808 | + | desc: "vertical, segment 3x3", |
| 809 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 810 | + | ar: image.Rect(0, 0, 3, 3), |
| 811 | + | st: Vertical, |
| 812 | + | want: func(size image.Point) *faketerm.Terminal { |
| 813 | + | ft := faketerm.MustNew(size) |
| 814 | + | bc := testbraille.MustNew(ft.Area()) |
| 815 | + | |
| 816 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{1, 0}) |
| 817 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 1}) |
| 818 | + | testdraw.MustBrailleLine(bc, image.Point{1, 2}, image.Point{1, 2}) |
| 819 | + | testbraille.MustApply(bc, ft) |
| 820 | + | return ft |
| 821 | + | }, |
| 822 | + | }, |
| 823 | + | { |
| 824 | + | desc: "vertical, segment 3x3, reverse slopes has no effect on larger width", |
| 825 | + | opts: []Option{ |
| 826 | + | ReverseSlopes(), |
| 827 | + | }, |
| 828 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 829 | + | ar: image.Rect(0, 0, 3, 3), |
| 830 | + | st: Vertical, |
| 831 | + | want: func(size image.Point) *faketerm.Terminal { |
| 832 | + | ft := faketerm.MustNew(size) |
| 833 | + | bc := testbraille.MustNew(ft.Area()) |
| 834 | + | |
| 835 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{1, 0}) |
| 836 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 1}) |
| 837 | + | testdraw.MustBrailleLine(bc, image.Point{1, 2}, image.Point{1, 2}) |
| 838 | + | testbraille.MustApply(bc, ft) |
| 839 | + | return ft |
| 840 | + | }, |
| 841 | + | }, |
| 842 | + | { |
| 843 | + | desc: "vertical, segment 3x3, skips slopes", |
| 844 | + | opts: []Option{ |
| 845 | + | SkipSlopesLTE(3), |
| 846 | + | }, |
| 847 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 848 | + | ar: image.Rect(0, 0, 3, 3), |
| 849 | + | st: Vertical, |
| 850 | + | want: func(size image.Point) *faketerm.Terminal { |
| 851 | + | ft := faketerm.MustNew(size) |
| 852 | + | bc := testbraille.MustNew(ft.Area()) |
| 853 | + | |
| 854 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{2, 0}) |
| 855 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 1}) |
| 856 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{2, 2}) |
| 857 | + | testbraille.MustApply(bc, ft) |
| 858 | + | return ft |
| 859 | + | }, |
| 860 | + | }, |
| 861 | + | { |
| 862 | + | desc: "vertical, segment 3x3, doesn't skips slopes because is wider", |
| 863 | + | opts: []Option{ |
| 864 | + | SkipSlopesLTE(2), |
| 865 | + | }, |
| 866 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 867 | + | ar: image.Rect(0, 0, 3, 3), |
| 868 | + | st: Vertical, |
| 869 | + | want: func(size image.Point) *faketerm.Terminal { |
| 870 | + | ft := faketerm.MustNew(size) |
| 871 | + | bc := testbraille.MustNew(ft.Area()) |
| 872 | + | |
| 873 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{1, 0}) |
| 874 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 1}) |
| 875 | + | testdraw.MustBrailleLine(bc, image.Point{1, 2}, image.Point{1, 2}) |
| 876 | + | testbraille.MustApply(bc, ft) |
| 877 | + | return ft |
| 878 | + | }, |
| 879 | + | }, |
| 880 | + | { |
| 881 | + | desc: "vertical, segment 3x4", |
| 882 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 883 | + | ar: image.Rect(0, 0, 3, 4), |
| 884 | + | st: Vertical, |
| 885 | + | want: func(size image.Point) *faketerm.Terminal { |
| 886 | + | ft := faketerm.MustNew(size) |
| 887 | + | bc := testbraille.MustNew(ft.Area()) |
| 888 | + | |
| 889 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{1, 0}) |
| 890 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 1}) |
| 891 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{2, 2}) |
| 892 | + | testdraw.MustBrailleLine(bc, image.Point{1, 3}, image.Point{1, 3}) |
| 893 | + | testbraille.MustApply(bc, ft) |
| 894 | + | return ft |
| 895 | + | }, |
| 896 | + | }, |
| 897 | + | { |
| 898 | + | desc: "vertical, segment 3x5", |
| 899 | + | cellCanvas: image.Rect(0, 0, 2, 2), |
| 900 | + | ar: image.Rect(0, 0, 3, 5), |
| 901 | + | st: Vertical, |
| 902 | + | want: func(size image.Point) *faketerm.Terminal { |
| 903 | + | ft := faketerm.MustNew(size) |
| 904 | + | bc := testbraille.MustNew(ft.Area()) |
| 905 | + | |
| 906 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{1, 0}) |
| 907 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 1}) |
| 908 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{2, 2}) |
| 909 | + | testdraw.MustBrailleLine(bc, image.Point{0, 3}, image.Point{2, 3}) |
| 910 | + | testdraw.MustBrailleLine(bc, image.Point{1, 4}, image.Point{1, 4}) |
| 911 | + | testbraille.MustApply(bc, ft) |
| 912 | + | return ft |
| 913 | + | }, |
| 914 | + | }, |
| 915 | + | { |
| 916 | + | desc: "vertical, segment 4x1", |
| 917 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 918 | + | ar: image.Rect(0, 0, 4, 1), |
| 919 | + | st: Vertical, |
| 920 | + | want: func(size image.Point) *faketerm.Terminal { |
| 921 | + | ft := faketerm.MustNew(size) |
| 922 | + | bc := testbraille.MustNew(ft.Area()) |
| 923 | + | |
| 924 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{3, 0}) |
| 925 | + | testbraille.MustApply(bc, ft) |
| 926 | + | return ft |
| 927 | + | }, |
| 928 | + | }, |
| 929 | + | { |
| 930 | + | desc: "vertical, segment 4x2", |
| 931 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 932 | + | ar: image.Rect(0, 0, 4, 2), |
| 933 | + | st: Vertical, |
| 934 | + | want: func(size image.Point) *faketerm.Terminal { |
| 935 | + | ft := faketerm.MustNew(size) |
| 936 | + | bc := testbraille.MustNew(ft.Area()) |
| 937 | + | |
| 938 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{3, 0}) |
| 939 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{3, 1}) |
| 940 | + | testbraille.MustApply(bc, ft) |
| 941 | + | return ft |
| 942 | + | }, |
| 943 | + | }, |
| 944 | + | { |
| 945 | + | desc: "vertical, segment 4x3", |
| 946 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 947 | + | ar: image.Rect(0, 0, 4, 3), |
| 948 | + | st: Vertical, |
| 949 | + | want: func(size image.Point) *faketerm.Terminal { |
| 950 | + | ft := faketerm.MustNew(size) |
| 951 | + | bc := testbraille.MustNew(ft.Area()) |
| 952 | + | |
| 953 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{2, 0}) |
| 954 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{3, 1}) |
| 955 | + | testdraw.MustBrailleLine(bc, image.Point{1, 2}, image.Point{2, 2}) |
| 956 | + | testbraille.MustApply(bc, ft) |
| 957 | + | return ft |
| 958 | + | }, |
| 959 | + | }, |
| 960 | + | { |
| 961 | + | desc: "vertical, segment 4x4", |
| 962 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 963 | + | ar: image.Rect(0, 0, 4, 4), |
| 964 | + | st: Vertical, |
| 965 | + | want: func(size image.Point) *faketerm.Terminal { |
| 966 | + | ft := faketerm.MustNew(size) |
| 967 | + | bc := testbraille.MustNew(ft.Area()) |
| 968 | + | |
| 969 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{2, 0}) |
| 970 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{3, 1}) |
| 971 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{3, 2}) |
| 972 | + | testdraw.MustBrailleLine(bc, image.Point{1, 3}, image.Point{2, 3}) |
| 973 | + | testbraille.MustApply(bc, ft) |
| 974 | + | return ft |
| 975 | + | }, |
| 976 | + | }, |
| 977 | + | { |
| 978 | + | desc: "vertical, segment 4x5", |
| 979 | + | cellCanvas: image.Rect(0, 0, 2, 2), |
| 980 | + | ar: image.Rect(0, 0, 4, 5), |
| 981 | + | st: Vertical, |
| 982 | + | want: func(size image.Point) *faketerm.Terminal { |
| 983 | + | ft := faketerm.MustNew(size) |
| 984 | + | bc := testbraille.MustNew(ft.Area()) |
| 985 | + | |
| 986 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{2, 0}) |
| 987 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{3, 1}) |
| 988 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{3, 2}) |
| 989 | + | testdraw.MustBrailleLine(bc, image.Point{0, 3}, image.Point{3, 3}) |
| 990 | + | testdraw.MustBrailleLine(bc, image.Point{1, 4}, image.Point{2, 4}) |
| 991 | + | testbraille.MustApply(bc, ft) |
| 992 | + | return ft |
| 993 | + | }, |
| 994 | + | }, |
| 995 | + | { |
| 996 | + | desc: "vertical, segment 5x1", |
| 997 | + | cellCanvas: image.Rect(0, 0, 3, 1), |
| 998 | + | ar: image.Rect(0, 0, 5, 1), |
| 999 | + | st: Vertical, |
| 1000 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1001 | + | ft := faketerm.MustNew(size) |
| 1002 | + | bc := testbraille.MustNew(ft.Area()) |
| 1003 | + | |
| 1004 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{4, 0}) |
| 1005 | + | testbraille.MustApply(bc, ft) |
| 1006 | + | return ft |
| 1007 | + | }, |
| 1008 | + | }, |
| 1009 | + | { |
| 1010 | + | desc: "vertical, segment 5x2", |
| 1011 | + | cellCanvas: image.Rect(0, 0, 3, 1), |
| 1012 | + | ar: image.Rect(0, 0, 5, 2), |
| 1013 | + | st: Vertical, |
| 1014 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1015 | + | ft := faketerm.MustNew(size) |
| 1016 | + | bc := testbraille.MustNew(ft.Area()) |
| 1017 | + | |
| 1018 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{4, 0}) |
| 1019 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{4, 1}) |
| 1020 | + | testbraille.MustApply(bc, ft) |
| 1021 | + | return ft |
| 1022 | + | }, |
| 1023 | + | }, |
| 1024 | + | { |
| 1025 | + | desc: "vertical, segment 5x3", |
| 1026 | + | cellCanvas: image.Rect(0, 0, 3, 1), |
| 1027 | + | ar: image.Rect(0, 0, 5, 3), |
| 1028 | + | st: Vertical, |
| 1029 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1030 | + | ft := faketerm.MustNew(size) |
| 1031 | + | bc := testbraille.MustNew(ft.Area()) |
| 1032 | + | |
| 1033 | + | testdraw.MustBrailleLine(bc, image.Point{2, 0}, image.Point{2, 0}) |
| 1034 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{4, 1}) |
| 1035 | + | testdraw.MustBrailleLine(bc, image.Point{2, 2}, image.Point{2, 2}) |
| 1036 | + | testbraille.MustApply(bc, ft) |
| 1037 | + | return ft |
| 1038 | + | }, |
| 1039 | + | }, |
| 1040 | + | { |
| 1041 | + | desc: "vertical, segment 5x4", |
| 1042 | + | cellCanvas: image.Rect(0, 0, 3, 1), |
| 1043 | + | ar: image.Rect(0, 0, 5, 4), |
| 1044 | + | st: Vertical, |
| 1045 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1046 | + | ft := faketerm.MustNew(size) |
| 1047 | + | bc := testbraille.MustNew(ft.Area()) |
| 1048 | + | |
| 1049 | + | testdraw.MustBrailleLine(bc, image.Point{2, 0}, image.Point{2, 0}) |
| 1050 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{4, 1}) |
| 1051 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{4, 2}) |
| 1052 | + | testdraw.MustBrailleLine(bc, image.Point{2, 3}, image.Point{2, 3}) |
| 1053 | + | testbraille.MustApply(bc, ft) |
| 1054 | + | return ft |
| 1055 | + | }, |
| 1056 | + | }, |
| 1057 | + | { |
| 1058 | + | desc: "vertical, segment 5x5", |
| 1059 | + | cellCanvas: image.Rect(0, 0, 3, 2), |
| 1060 | + | ar: image.Rect(0, 0, 5, 5), |
| 1061 | + | st: Vertical, |
| 1062 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1063 | + | ft := faketerm.MustNew(size) |
| 1064 | + | bc := testbraille.MustNew(ft.Area()) |
| 1065 | + | |
| 1066 | + | testdraw.MustBrailleLine(bc, image.Point{2, 0}, image.Point{2, 0}) |
| 1067 | + | testdraw.MustBrailleLine(bc, image.Point{1, 1}, image.Point{3, 1}) |
| 1068 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{4, 2}) |
| 1069 | + | testdraw.MustBrailleLine(bc, image.Point{1, 3}, image.Point{3, 3}) |
| 1070 | + | testdraw.MustBrailleLine(bc, image.Point{2, 4}, image.Point{2, 4}) |
| 1071 | + | testbraille.MustApply(bc, ft) |
| 1072 | + | return ft |
| 1073 | + | }, |
| 1074 | + | }, |
| 1075 | + | } |
| 1076 | + | |
| 1077 | + | for _, tc := range tests { |
| 1078 | + | t.Run(fmt.Sprintf("%s st:%v", tc.desc, tc.st), func(t *testing.T) { |
| 1079 | + | bc, err := braille.New(tc.cellCanvas) |
| 1080 | + | if err != nil { |
| 1081 | + | t.Fatalf("braille.New => unexpected error: %v", err) |
| 1082 | + | } |
| 1083 | + | |
| 1084 | + | err = HV(bc, tc.ar, tc.st, tc.opts...) |
| 1085 | + | if (err != nil) != tc.wantErr { |
| 1086 | + | t.Errorf("HV => unexpected error: %v, wantErr: %v", err, tc.wantErr) |
| 1087 | + | } |
| 1088 | + | if err != nil { |
| 1089 | + | return |
| 1090 | + | } |
| 1091 | + | |
| 1092 | + | size := area.Size(tc.cellCanvas) |
| 1093 | + | want := faketerm.MustNew(size) |
| 1094 | + | if tc.want != nil { |
| 1095 | + | want = tc.want(size) |
| 1096 | + | } |
| 1097 | + | |
| 1098 | + | got, err := faketerm.New(size) |
| 1099 | + | if err != nil { |
| 1100 | + | t.Fatalf("faketerm.New => unexpected error: %v", err) |
| 1101 | + | } |
| 1102 | + | if err := bc.Apply(got); err != nil { |
| 1103 | + | t.Fatalf("bc.Apply => unexpected error: %v", err) |
| 1104 | + | } |
| 1105 | + | if diff := faketerm.Diff(want, got); diff != "" { |
| 1106 | + | t.Fatalf("HV => %v", diff) |
| 1107 | + | } |
| 1108 | + | }) |
| 1109 | + | } |
| 1110 | + | } |
| 1111 | + | |
| 1112 | + | // hvSegment is one horizontal or vertical segment. |
| 1113 | + | type hvSegment struct { |
| 1114 | + | ar image.Rectangle |
| 1115 | + | st Type |
| 1116 | + | } |
| 1117 | + | |
| 1118 | + | // diagSegment is one diagonal segment. |
| 1119 | + | type diagSegment struct { |
| 1120 | + | ar image.Rectangle |
| 1121 | + | width int |
| 1122 | + | dt DiagonalType |
| 1123 | + | } |
| 1124 | + | |
| 1125 | + | func TestAdjustHoriz(t *testing.T) { |
| 1126 | + | tests := []struct { |
| 1127 | + | desc string |
| 1128 | + | start image.Point |
| 1129 | + | end image.Point |
| 1130 | + | segWidth int |
| 1131 | + | adjust int |
| 1132 | + | wantStart image.Point |
| 1133 | + | wantEnd image.Point |
| 1134 | + | }{ |
| 1135 | + | { |
| 1136 | + | desc: "no change for zero adjustment", |
| 1137 | + | }, |
| 1138 | + | { |
| 1139 | + | desc: "safe adjustments, points don't cross", |
| 1140 | + | start: image.Point{0, 0}, |
| 1141 | + | end: image.Point{5, 0}, |
| 1142 | + | segWidth: 6, |
| 1143 | + | adjust: 1, |
| 1144 | + | wantStart: image.Point{1, 0}, |
| 1145 | + | wantEnd: image.Point{4, 0}, |
| 1146 | + | }, |
| 1147 | + | { |
| 1148 | + | desc: "safe adjustments, points land on each other", |
| 1149 | + | start: image.Point{0, 0}, |
| 1150 | + | end: image.Point{4, 0}, |
| 1151 | + | segWidth: 5, |
| 1152 | + | adjust: 2, |
| 1153 | + | wantStart: image.Point{2, 0}, |
| 1154 | + | wantEnd: image.Point{2, 0}, |
| 1155 | + | }, |
| 1156 | + | |
| 1157 | + | { |
| 1158 | + | desc: "points cross, width divides evenly", |
| 1159 | + | start: image.Point{0, 0}, |
| 1160 | + | end: image.Point{5, 0}, |
| 1161 | + | segWidth: 6, |
| 1162 | + | adjust: 3, |
| 1163 | + | wantStart: image.Point{2, 0}, |
| 1164 | + | wantEnd: image.Point{3, 0}, |
| 1165 | + | }, |
| 1166 | + | { |
| 1167 | + | desc: "points cross, width divides oddly", |
| 1168 | + | start: image.Point{0, 0}, |
| 1169 | + | end: image.Point{6, 0}, |
| 1170 | + | segWidth: 7, |
| 1171 | + | adjust: 4, |
| 1172 | + | wantStart: image.Point{3, 0}, |
| 1173 | + | wantEnd: image.Point{3, 0}, |
| 1174 | + | }, |
| 1175 | + | } |
| 1176 | + | |
| 1177 | + | for _, tc := range tests { |
| 1178 | + | t.Run(tc.desc, func(t *testing.T) { |
| 1179 | + | gotStart, gotEnd := adjustHoriz(tc.start, tc.end, tc.segWidth, tc.adjust) |
| 1180 | + | if !gotStart.Eq(tc.wantStart) || !gotEnd.Eq(tc.wantEnd) { |
| 1181 | + | t.Errorf("adjustHoriz(%v, %v, %v, %v) => %v, %v, want %v, %v", tc.start, tc.end, tc.segWidth, tc.adjust, gotStart, gotEnd, tc.wantStart, tc.wantEnd) |
| 1182 | + | } |
| 1183 | + | |
| 1184 | + | }) |
| 1185 | + | } |
| 1186 | + | } |
| 1187 | + | |
| 1188 | + | func TestAdjustVert(t *testing.T) { |
| 1189 | + | tests := []struct { |
| 1190 | + | desc string |
| 1191 | + | start image.Point |
| 1192 | + | end image.Point |
| 1193 | + | segHeight int |
| 1194 | + | adjust int |
| 1195 | + | wantStart image.Point |
| 1196 | + | wantEnd image.Point |
| 1197 | + | }{ |
| 1198 | + | { |
| 1199 | + | desc: "no change for zero adjustment", |
| 1200 | + | }, |
| 1201 | + | { |
| 1202 | + | desc: "safe adjustments, points don't cross", |
| 1203 | + | start: image.Point{0, 0}, |
| 1204 | + | end: image.Point{0, 5}, |
| 1205 | + | segHeight: 6, |
| 1206 | + | adjust: 1, |
| 1207 | + | wantStart: image.Point{0, 1}, |
| 1208 | + | wantEnd: image.Point{0, 4}, |
| 1209 | + | }, |
| 1210 | + | { |
| 1211 | + | desc: "safe adjustments, points land on each other", |
| 1212 | + | start: image.Point{0, 0}, |
| 1213 | + | end: image.Point{0, 4}, |
| 1214 | + | segHeight: 5, |
| 1215 | + | adjust: 2, |
| 1216 | + | wantStart: image.Point{0, 2}, |
| 1217 | + | wantEnd: image.Point{0, 2}, |
| 1218 | + | }, |
| 1219 | + | |
| 1220 | + | { |
| 1221 | + | desc: "points cross, width divides evenly", |
| 1222 | + | start: image.Point{0, 0}, |
| 1223 | + | end: image.Point{0, 5}, |
| 1224 | + | segHeight: 6, |
| 1225 | + | adjust: 3, |
| 1226 | + | wantStart: image.Point{0, 2}, |
| 1227 | + | wantEnd: image.Point{0, 3}, |
| 1228 | + | }, |
| 1229 | + | { |
| 1230 | + | desc: "points cross, width divides oddly", |
| 1231 | + | start: image.Point{0, 0}, |
| 1232 | + | end: image.Point{0, 6}, |
| 1233 | + | segHeight: 7, |
| 1234 | + | adjust: 4, |
| 1235 | + | wantStart: image.Point{0, 3}, |
| 1236 | + | wantEnd: image.Point{0, 3}, |
| 1237 | + | }, |
| 1238 | + | } |
| 1239 | + | |
| 1240 | + | for _, tc := range tests { |
| 1241 | + | t.Run(tc.desc, func(t *testing.T) { |
| 1242 | + | gotStart, gotEnd := adjustVert(tc.start, tc.end, tc.segHeight, tc.adjust) |
| 1243 | + | if !gotStart.Eq(tc.wantStart) || !gotEnd.Eq(tc.wantEnd) { |
| 1244 | + | t.Errorf("adjustVert(%v, %v, %v, %v) => %v, %v, want %v, %v", tc.start, tc.end, tc.segHeight, tc.adjust, gotStart, gotEnd, tc.wantStart, tc.wantEnd) |
| 1245 | + | } |
| 1246 | + | |
| 1247 | + | }) |
| 1248 | + | } |
| 1249 | + | } |
| 1250 | + | |
| 1251 | + | func TestDiagonal(t *testing.T) { |
| 1252 | + | tests := []struct { |
| 1253 | + | desc string |
| 1254 | + | opts []DiagonalOption |
| 1255 | + | cellCanvas image.Rectangle // Canvas in cells that will be converted to braille canvas for drawing. |
| 1256 | + | ar image.Rectangle |
| 1257 | + | width int |
| 1258 | + | dt DiagonalType |
| 1259 | + | want func(size image.Point) *faketerm.Terminal |
| 1260 | + | wantErr bool |
| 1261 | + | }{ |
| 1262 | + | { |
| 1263 | + | desc: "fails on area with negative Min.X", |
| 1264 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 1265 | + | ar: image.Rect(-1, 0, 1, 1), |
| 1266 | + | width: 1, |
| 1267 | + | dt: LeftToRight, |
| 1268 | + | wantErr: true, |
| 1269 | + | }, |
| 1270 | + | { |
| 1271 | + | desc: "fails on area with negative Min.Y", |
| 1272 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 1273 | + | ar: image.Rect(0, -1, 1, 1), |
| 1274 | + | width: 1, |
| 1275 | + | dt: LeftToRight, |
| 1276 | + | wantErr: true, |
| 1277 | + | }, |
| 1278 | + | { |
| 1279 | + | desc: "fails on area with negative Max.X", |
| 1280 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 1281 | + | ar: image.Rectangle{image.Point{0, 0}, image.Point{-1, 1}}, |
| 1282 | + | width: 1, |
| 1283 | + | dt: LeftToRight, |
| 1284 | + | wantErr: true, |
| 1285 | + | }, |
| 1286 | + | { |
| 1287 | + | desc: "fails on area with negative Max.Y", |
| 1288 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 1289 | + | ar: image.Rectangle{image.Point{0, 0}, image.Point{1, -1}}, |
| 1290 | + | width: 1, |
| 1291 | + | dt: LeftToRight, |
| 1292 | + | wantErr: true, |
| 1293 | + | }, |
| 1294 | + | { |
| 1295 | + | desc: "fails on area with zero Dx()", |
| 1296 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 1297 | + | ar: image.Rect(0, 0, 0, 1), |
| 1298 | + | width: 1, |
| 1299 | + | dt: LeftToRight, |
| 1300 | + | wantErr: true, |
| 1301 | + | }, |
| 1302 | + | { |
| 1303 | + | desc: "fails on area with zero Dy()", |
| 1304 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 1305 | + | ar: image.Rect(0, 0, 1, 0), |
| 1306 | + | width: 1, |
| 1307 | + | dt: LeftToRight, |
| 1308 | + | wantErr: true, |
| 1309 | + | }, |
| 1310 | + | { |
| 1311 | + | desc: "fails on unsupported diagonal type (too small)", |
| 1312 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 1313 | + | ar: image.Rect(0, 0, 2, 2), |
| 1314 | + | width: 1, |
| 1315 | + | dt: DiagonalType(0), |
| 1316 | + | wantErr: true, |
| 1317 | + | }, |
| 1318 | + | { |
| 1319 | + | desc: "fails on unsupported diagonal type (too large)", |
| 1320 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 1321 | + | ar: image.Rect(0, 0, 2, 2), |
| 1322 | + | width: 1, |
| 1323 | + | dt: DiagonalType(int(RightToLeft) + 1), |
| 1324 | + | wantErr: true, |
| 1325 | + | }, |
| 1326 | + | { |
| 1327 | + | desc: "fails on area larger than the canvas", |
| 1328 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 1329 | + | ar: image.Rect(0, 0, 3, 1), |
| 1330 | + | width: 1, |
| 1331 | + | dt: LeftToRight, |
| 1332 | + | wantErr: true, |
| 1333 | + | }, |
| 1334 | + | { |
| 1335 | + | desc: "fails on zero width", |
| 1336 | + | cellCanvas: image.Rect(0, 0, 1, 1), |
| 1337 | + | ar: image.Rect(0, 0, 3, 1), |
| 1338 | + | width: 0, |
| 1339 | + | dt: LeftToRight, |
| 1340 | + | wantErr: true, |
| 1341 | + | }, |
| 1342 | + | { |
| 1343 | + | desc: "left to right, area 4x4, width 1", |
| 1344 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1345 | + | ar: image.Rect(0, 0, 4, 4), |
| 1346 | + | dt: LeftToRight, |
| 1347 | + | width: 1, |
| 1348 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1349 | + | ft := faketerm.MustNew(size) |
| 1350 | + | bc := testbraille.MustNew(ft.Area()) |
| 1351 | + | |
| 1352 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{3, 3}) |
| 1353 | + | |
| 1354 | + | testbraille.MustApply(bc, ft) |
| 1355 | + | return ft |
| 1356 | + | }, |
| 1357 | + | }, |
| 1358 | + | { |
| 1359 | + | desc: "right to left, area 4x4, width 1", |
| 1360 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1361 | + | ar: image.Rect(0, 0, 4, 4), |
| 1362 | + | dt: RightToLeft, |
| 1363 | + | width: 1, |
| 1364 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1365 | + | ft := faketerm.MustNew(size) |
| 1366 | + | bc := testbraille.MustNew(ft.Area()) |
| 1367 | + | |
| 1368 | + | testdraw.MustBrailleLine(bc, image.Point{3, 0}, image.Point{0, 3}) |
| 1369 | + | |
| 1370 | + | testbraille.MustApply(bc, ft) |
| 1371 | + | return ft |
| 1372 | + | }, |
| 1373 | + | }, |
| 1374 | + | { |
| 1375 | + | desc: "left to right, area 4x4, width 2", |
| 1376 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1377 | + | ar: image.Rect(0, 0, 4, 4), |
| 1378 | + | dt: LeftToRight, |
| 1379 | + | width: 2, |
| 1380 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1381 | + | ft := faketerm.MustNew(size) |
| 1382 | + | bc := testbraille.MustNew(ft.Area()) |
| 1383 | + | |
| 1384 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{3, 2}) |
| 1385 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{3, 3}) |
| 1386 | + | |
| 1387 | + | testbraille.MustApply(bc, ft) |
| 1388 | + | return ft |
| 1389 | + | }, |
| 1390 | + | }, |
| 1391 | + | { |
| 1392 | + | desc: "right to left, area 4x4, width 2", |
| 1393 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1394 | + | ar: image.Rect(0, 0, 4, 4), |
| 1395 | + | dt: RightToLeft, |
| 1396 | + | width: 2, |
| 1397 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1398 | + | ft := faketerm.MustNew(size) |
| 1399 | + | bc := testbraille.MustNew(ft.Area()) |
| 1400 | + | |
| 1401 | + | testdraw.MustBrailleLine(bc, image.Point{2, 0}, image.Point{0, 2}) |
| 1402 | + | testdraw.MustBrailleLine(bc, image.Point{3, 0}, image.Point{0, 3}) |
| 1403 | + | |
| 1404 | + | testbraille.MustApply(bc, ft) |
| 1405 | + | return ft |
| 1406 | + | }, |
| 1407 | + | }, |
| 1408 | + | { |
| 1409 | + | desc: "left to right, area 4x4, width 3", |
| 1410 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1411 | + | ar: image.Rect(0, 0, 4, 4), |
| 1412 | + | dt: LeftToRight, |
| 1413 | + | width: 3, |
| 1414 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1415 | + | ft := faketerm.MustNew(size) |
| 1416 | + | bc := testbraille.MustNew(ft.Area()) |
| 1417 | + | |
| 1418 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{3, 2}) |
| 1419 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{3, 3}) |
| 1420 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 3}) |
| 1421 | + | |
| 1422 | + | testbraille.MustApply(bc, ft) |
| 1423 | + | return ft |
| 1424 | + | }, |
| 1425 | + | }, |
| 1426 | + | { |
| 1427 | + | desc: "right to left, area 4x4, width 3", |
| 1428 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1429 | + | ar: image.Rect(0, 0, 4, 4), |
| 1430 | + | dt: RightToLeft, |
| 1431 | + | width: 3, |
| 1432 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1433 | + | ft := faketerm.MustNew(size) |
| 1434 | + | bc := testbraille.MustNew(ft.Area()) |
| 1435 | + | |
| 1436 | + | testdraw.MustBrailleLine(bc, image.Point{2, 0}, image.Point{0, 2}) |
| 1437 | + | testdraw.MustBrailleLine(bc, image.Point{3, 0}, image.Point{0, 3}) |
| 1438 | + | testdraw.MustBrailleLine(bc, image.Point{3, 1}, image.Point{1, 3}) |
| 1439 | + | |
| 1440 | + | testbraille.MustApply(bc, ft) |
| 1441 | + | return ft |
| 1442 | + | }, |
| 1443 | + | }, |
| 1444 | + | { |
| 1445 | + | desc: "left to right, area 8x4, width 3", |
| 1446 | + | cellCanvas: image.Rect(0, 0, 4, 1), |
| 1447 | + | ar: image.Rect(0, 0, 8, 4), |
| 1448 | + | dt: LeftToRight, |
| 1449 | + | width: 3, |
| 1450 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1451 | + | ft := faketerm.MustNew(size) |
| 1452 | + | bc := testbraille.MustNew(ft.Area()) |
| 1453 | + | |
| 1454 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{7, 3}) |
| 1455 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{7, 2}) |
| 1456 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{6, 3}) |
| 1457 | + | |
| 1458 | + | testbraille.MustApply(bc, ft) |
| 1459 | + | return ft |
| 1460 | + | }, |
| 1461 | + | }, |
| 1462 | + | { |
| 1463 | + | desc: "right to left, area 8x4, width 3", |
| 1464 | + | cellCanvas: image.Rect(0, 0, 4, 1), |
| 1465 | + | ar: image.Rect(0, 0, 8, 4), |
| 1466 | + | dt: RightToLeft, |
| 1467 | + | width: 3, |
| 1468 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1469 | + | ft := faketerm.MustNew(size) |
| 1470 | + | bc := testbraille.MustNew(ft.Area()) |
| 1471 | + | |
| 1472 | + | testdraw.MustBrailleLine(bc, image.Point{7, 0}, image.Point{0, 3}) |
| 1473 | + | testdraw.MustBrailleLine(bc, image.Point{6, 0}, image.Point{0, 2}) |
| 1474 | + | testdraw.MustBrailleLine(bc, image.Point{7, 1}, image.Point{1, 3}) |
| 1475 | + | |
| 1476 | + | testbraille.MustApply(bc, ft) |
| 1477 | + | return ft |
| 1478 | + | }, |
| 1479 | + | }, |
| 1480 | + | { |
| 1481 | + | desc: "left to right, area 4x8, width 3", |
| 1482 | + | cellCanvas: image.Rect(0, 0, 2, 2), |
| 1483 | + | ar: image.Rect(0, 0, 4, 8), |
| 1484 | + | dt: LeftToRight, |
| 1485 | + | width: 3, |
| 1486 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1487 | + | ft := faketerm.MustNew(size) |
| 1488 | + | bc := testbraille.MustNew(ft.Area()) |
| 1489 | + | |
| 1490 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{3, 7}) |
| 1491 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{3, 6}) |
| 1492 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 7}) |
| 1493 | + | |
| 1494 | + | testbraille.MustApply(bc, ft) |
| 1495 | + | return ft |
| 1496 | + | }, |
| 1497 | + | }, |
| 1498 | + | { |
| 1499 | + | desc: "right to left, area 4x8, width 3", |
| 1500 | + | cellCanvas: image.Rect(0, 0, 2, 2), |
| 1501 | + | ar: image.Rect(0, 0, 4, 8), |
| 1502 | + | dt: RightToLeft, |
| 1503 | + | width: 3, |
| 1504 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1505 | + | ft := faketerm.MustNew(size) |
| 1506 | + | bc := testbraille.MustNew(ft.Area()) |
| 1507 | + | |
| 1508 | + | testdraw.MustBrailleLine(bc, image.Point{3, 0}, image.Point{0, 7}) |
| 1509 | + | testdraw.MustBrailleLine(bc, image.Point{2, 0}, image.Point{0, 6}) |
| 1510 | + | testdraw.MustBrailleLine(bc, image.Point{3, 1}, image.Point{1, 7}) |
| 1511 | + | |
| 1512 | + | testbraille.MustApply(bc, ft) |
| 1513 | + | return ft |
| 1514 | + | }, |
| 1515 | + | }, |
| 1516 | + | { |
| 1517 | + | desc: "left to right, area 4x4, width 4", |
| 1518 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1519 | + | ar: image.Rect(0, 0, 4, 4), |
| 1520 | + | dt: LeftToRight, |
| 1521 | + | width: 4, |
| 1522 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1523 | + | ft := faketerm.MustNew(size) |
| 1524 | + | bc := testbraille.MustNew(ft.Area()) |
| 1525 | + | |
| 1526 | + | testdraw.MustBrailleLine(bc, image.Point{2, 0}, image.Point{3, 1}) |
| 1527 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{3, 2}) |
| 1528 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{3, 3}) |
| 1529 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 3}) |
| 1530 | + | |
| 1531 | + | testbraille.MustApply(bc, ft) |
| 1532 | + | return ft |
| 1533 | + | }, |
| 1534 | + | }, |
| 1535 | + | { |
| 1536 | + | desc: "right to left, area 4x4, width 4", |
| 1537 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1538 | + | ar: image.Rect(0, 0, 4, 4), |
| 1539 | + | dt: RightToLeft, |
| 1540 | + | width: 4, |
| 1541 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1542 | + | ft := faketerm.MustNew(size) |
| 1543 | + | bc := testbraille.MustNew(ft.Area()) |
| 1544 | + | |
| 1545 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{0, 1}) |
| 1546 | + | testdraw.MustBrailleLine(bc, image.Point{2, 0}, image.Point{0, 2}) |
| 1547 | + | testdraw.MustBrailleLine(bc, image.Point{3, 0}, image.Point{0, 3}) |
| 1548 | + | testdraw.MustBrailleLine(bc, image.Point{3, 1}, image.Point{1, 3}) |
| 1549 | + | |
| 1550 | + | testbraille.MustApply(bc, ft) |
| 1551 | + | return ft |
| 1552 | + | }, |
| 1553 | + | }, |
| 1554 | + | { |
| 1555 | + | desc: "left to right, area 4x4, width 5", |
| 1556 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1557 | + | ar: image.Rect(0, 0, 4, 4), |
| 1558 | + | dt: LeftToRight, |
| 1559 | + | width: 5, |
| 1560 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1561 | + | ft := faketerm.MustNew(size) |
| 1562 | + | bc := testbraille.MustNew(ft.Area()) |
| 1563 | + | |
| 1564 | + | testdraw.MustBrailleLine(bc, image.Point{2, 0}, image.Point{3, 1}) |
| 1565 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{3, 2}) |
| 1566 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{3, 3}) |
| 1567 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 3}) |
| 1568 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{1, 3}) |
| 1569 | + | |
| 1570 | + | testbraille.MustApply(bc, ft) |
| 1571 | + | return ft |
| 1572 | + | }, |
| 1573 | + | }, |
| 1574 | + | { |
| 1575 | + | desc: "right to left, area 4x4, width 5", |
| 1576 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1577 | + | ar: image.Rect(0, 0, 4, 4), |
| 1578 | + | dt: RightToLeft, |
| 1579 | + | width: 5, |
| 1580 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1581 | + | ft := faketerm.MustNew(size) |
| 1582 | + | bc := testbraille.MustNew(ft.Area()) |
| 1583 | + | |
| 1584 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{0, 1}) |
| 1585 | + | testdraw.MustBrailleLine(bc, image.Point{2, 0}, image.Point{0, 2}) |
| 1586 | + | testdraw.MustBrailleLine(bc, image.Point{3, 0}, image.Point{0, 3}) |
| 1587 | + | testdraw.MustBrailleLine(bc, image.Point{3, 1}, image.Point{1, 3}) |
| 1588 | + | testdraw.MustBrailleLine(bc, image.Point{3, 2}, image.Point{2, 3}) |
| 1589 | + | |
| 1590 | + | testbraille.MustApply(bc, ft) |
| 1591 | + | return ft |
| 1592 | + | }, |
| 1593 | + | }, |
| 1594 | + | { |
| 1595 | + | desc: "left to right, area 4x4, width 6", |
| 1596 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1597 | + | ar: image.Rect(0, 0, 4, 4), |
| 1598 | + | dt: LeftToRight, |
| 1599 | + | width: 6, |
| 1600 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1601 | + | ft := faketerm.MustNew(size) |
| 1602 | + | bc := testbraille.MustNew(ft.Area()) |
| 1603 | + | |
| 1604 | + | testdraw.MustBrailleLine(bc, image.Point{3, 0}, image.Point{3, 0}) |
| 1605 | + | testdraw.MustBrailleLine(bc, image.Point{2, 0}, image.Point{3, 1}) |
| 1606 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{3, 2}) |
| 1607 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{3, 3}) |
| 1608 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 3}) |
| 1609 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{1, 3}) |
| 1610 | + | |
| 1611 | + | testbraille.MustApply(bc, ft) |
| 1612 | + | return ft |
| 1613 | + | }, |
| 1614 | + | }, |
| 1615 | + | { |
| 1616 | + | desc: "right to left, area 4x4, width 6", |
| 1617 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1618 | + | ar: image.Rect(0, 0, 4, 4), |
| 1619 | + | dt: RightToLeft, |
| 1620 | + | width: 6, |
| 1621 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1622 | + | ft := faketerm.MustNew(size) |
| 1623 | + | bc := testbraille.MustNew(ft.Area()) |
| 1624 | + | |
| 1625 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{0, 0}) |
| 1626 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{0, 1}) |
| 1627 | + | testdraw.MustBrailleLine(bc, image.Point{2, 0}, image.Point{0, 2}) |
| 1628 | + | testdraw.MustBrailleLine(bc, image.Point{3, 0}, image.Point{0, 3}) |
| 1629 | + | testdraw.MustBrailleLine(bc, image.Point{3, 1}, image.Point{1, 3}) |
| 1630 | + | testdraw.MustBrailleLine(bc, image.Point{3, 2}, image.Point{2, 3}) |
| 1631 | + | |
| 1632 | + | testbraille.MustApply(bc, ft) |
| 1633 | + | return ft |
| 1634 | + | }, |
| 1635 | + | }, |
| 1636 | + | { |
| 1637 | + | desc: "left to right, area 4x4, width 7", |
| 1638 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1639 | + | ar: image.Rect(0, 0, 4, 4), |
| 1640 | + | dt: LeftToRight, |
| 1641 | + | width: 7, |
| 1642 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1643 | + | ft := faketerm.MustNew(size) |
| 1644 | + | bc := testbraille.MustNew(ft.Area()) |
| 1645 | + | |
| 1646 | + | testdraw.MustBrailleLine(bc, image.Point{3, 0}, image.Point{3, 0}) |
| 1647 | + | testdraw.MustBrailleLine(bc, image.Point{2, 0}, image.Point{3, 1}) |
| 1648 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{3, 2}) |
| 1649 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{3, 3}) |
| 1650 | + | testdraw.MustBrailleLine(bc, image.Point{0, 1}, image.Point{2, 3}) |
| 1651 | + | testdraw.MustBrailleLine(bc, image.Point{0, 2}, image.Point{1, 3}) |
| 1652 | + | testdraw.MustBrailleLine(bc, image.Point{0, 3}, image.Point{3, 3}) |
| 1653 | + | |
| 1654 | + | testbraille.MustApply(bc, ft) |
| 1655 | + | return ft |
| 1656 | + | }, |
| 1657 | + | }, |
| 1658 | + | { |
| 1659 | + | desc: "right to left, area 4x4, width 7", |
| 1660 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1661 | + | ar: image.Rect(0, 0, 4, 4), |
| 1662 | + | dt: RightToLeft, |
| 1663 | + | width: 7, |
| 1664 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1665 | + | ft := faketerm.MustNew(size) |
| 1666 | + | bc := testbraille.MustNew(ft.Area()) |
| 1667 | + | |
| 1668 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{0, 0}) |
| 1669 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{0, 1}) |
| 1670 | + | testdraw.MustBrailleLine(bc, image.Point{2, 0}, image.Point{0, 2}) |
| 1671 | + | testdraw.MustBrailleLine(bc, image.Point{3, 0}, image.Point{0, 3}) |
| 1672 | + | testdraw.MustBrailleLine(bc, image.Point{3, 1}, image.Point{1, 3}) |
| 1673 | + | testdraw.MustBrailleLine(bc, image.Point{3, 2}, image.Point{2, 3}) |
| 1674 | + | testdraw.MustBrailleLine(bc, image.Point{3, 3}, image.Point{3, 3}) |
| 1675 | + | |
| 1676 | + | testbraille.MustApply(bc, ft) |
| 1677 | + | return ft |
| 1678 | + | }, |
| 1679 | + | }, |
| 1680 | + | { |
| 1681 | + | desc: "left to right, fails when width is larger than area", |
| 1682 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1683 | + | ar: image.Rect(0, 0, 4, 4), |
| 1684 | + | dt: LeftToRight, |
| 1685 | + | width: 8, |
| 1686 | + | wantErr: true, |
| 1687 | + | }, |
| 1688 | + | { |
| 1689 | + | desc: "right to left, fails when width is larger than area", |
| 1690 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1691 | + | ar: image.Rect(0, 0, 4, 4), |
| 1692 | + | dt: RightToLeft, |
| 1693 | + | width: 8, |
| 1694 | + | wantErr: true, |
| 1695 | + | }, |
| 1696 | + | { |
| 1697 | + | desc: "sets cell options", |
| 1698 | + | opts: []DiagonalOption{ |
| 1699 | + | DiagonalCellOpts( |
| 1700 | + | cell.FgColor(cell.ColorRed), |
| 1701 | + | cell.BgColor(cell.ColorGreen), |
| 1702 | + | ), |
| 1703 | + | }, |
| 1704 | + | cellCanvas: image.Rect(0, 0, 2, 1), |
| 1705 | + | ar: image.Rect(0, 0, 4, 4), |
| 1706 | + | dt: LeftToRight, |
| 1707 | + | width: 2, |
| 1708 | + | want: func(size image.Point) *faketerm.Terminal { |
| 1709 | + | ft := faketerm.MustNew(size) |
| 1710 | + | bc := testbraille.MustNew(ft.Area()) |
| 1711 | + | |
| 1712 | + | opts := []draw.BrailleLineOption{ |
| 1713 | + | draw.BrailleLineCellOpts( |
| 1714 | + | cell.FgColor(cell.ColorRed), |
| 1715 | + | cell.BgColor(cell.ColorGreen), |
| 1716 | + | ), |
| 1717 | + | } |
| 1718 | + | testdraw.MustBrailleLine(bc, image.Point{1, 0}, image.Point{3, 2}, opts...) |
| 1719 | + | testdraw.MustBrailleLine(bc, image.Point{0, 0}, image.Point{3, 3}, opts...) |
| 1720 | + | |
| 1721 | + | testbraille.MustApply(bc, ft) |
| 1722 | + | return ft |
| 1723 | + | }, |
| 1724 | + | }, |
| 1725 | + | } |
| 1726 | + | |
| 1727 | + | for _, tc := range tests { |
| 1728 | + | t.Run(fmt.Sprintf("%s dt:%v", tc.desc, tc.dt), func(t *testing.T) { |
| 1729 | + | bc, err := braille.New(tc.cellCanvas) |
| 1730 | + | if err != nil { |
| 1731 | + | t.Fatalf("braille.New => unexpected error: %v", err) |
| 1732 | + | } |
| 1733 | + | |
| 1734 | + | err = Diagonal(bc, tc.ar, tc.width, tc.dt, tc.opts...) |
| 1735 | + | if (err != nil) != tc.wantErr { |
| 1736 | + | t.Errorf("Diagonal => unexpected error: %v, wantErr: %v", err, tc.wantErr) |
| 1737 | + | } |
| 1738 | + | if err != nil { |
| 1739 | + | return |
| 1740 | + | } |
| 1741 | + | |
| 1742 | + | size := area.Size(tc.cellCanvas) |
| 1743 | + | want := faketerm.MustNew(size) |
| 1744 | + | if tc.want != nil { |
| 1745 | + | want = tc.want(size) |
| 1746 | + | } |
| 1747 | + | |
| 1748 | + | got, err := faketerm.New(size) |
| 1749 | + | if err != nil { |
| 1750 | + | t.Fatalf("faketerm.New => unexpected error: %v", err) |
| 1751 | + | } |
| 1752 | + | if err := bc.Apply(got); err != nil { |
| 1753 | + | t.Fatalf("bc.Apply => unexpected error: %v", err) |
| 1754 | + | } |
| 1755 | + | if diff := faketerm.Diff(want, got); diff != "" { |
| 1756 | + | t.Fatalf("Diagonal => %v", diff) |
| 1757 | + | } |
| 1758 | + | }) |
| 1759 | + | } |
| 1760 | + | } |
| 1761 | + | |