| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package main |
| 16 |
|
| 17 |
import ( |
| 18 |
"fmt" |
| 19 |
"sync" |
| 20 |
"testing" |
| 21 |
"time" |
| 22 |
|
| 23 |
"github.com/gdamore/tcell/v3" |
| 24 |
"github.com/gdamore/tcell/v3/vt" |
| 25 |
) |
| 26 |
|
| 27 |
func TestBoxes(t *testing.T) { |
| 28 |
|
| 29 |
for _, colors := range []int{0, 8, 16, 88, 256, 1 << 24} { |
| 30 |
t.Run(fmt.Sprintf("%d_colors)", colors), func(t *testing.T) { |
| 31 |
mt := vt.NewMockTerm(vt.MockOptColors(colors)) |
| 32 |
scr, err := tcell.NewTerminfoScreenFromTty(mt, tcell.OptColors(colors)) |
| 33 |
if err != nil { |
| 34 |
t.Fatalf("failed to create screen: %v", err) |
| 35 |
} |
| 36 |
tcell.ShimScreen(scr) |
| 37 |
var wg sync.WaitGroup |
| 38 |
wg.Add(1) |
| 39 |
count = 0 |
| 40 |
drawTime = 0 |
| 41 |
interval = time.Microsecond * 10 |
| 42 |
|
| 43 |
go func() { |
| 44 |
defer wg.Done() |
| 45 |
main() |
| 46 |
}() |
| 47 |
|
| 48 |
time.Sleep(time.Millisecond * 25) |
| 49 |
mt.KeyTap(vt.KeyRCtrl, vt.KeyL) |
| 50 |
mt.SetSize(vt.Coord{X: 10, Y: 10}) |
| 51 |
mt.Drain() |
| 52 |
time.Sleep(time.Millisecond * 25) |
| 53 |
mt.KeyTap(vt.KeyLCtrl, vt.KeyQ) |
| 54 |
mt.Drain() |
| 55 |
wg.Wait() |
| 56 |
|
| 57 |
if count < 10 { |
| 58 |
t.Errorf("Too few boxes: %d", count) |
| 59 |
} |
| 60 |
if drawTime < time.Microsecond { |
| 61 |
|
| 62 |
|
| 63 |
t.Logf("Draw time very short: %s", drawTime) |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
if drawTime > 10*time.Millisecond*time.Duration(count) { |
| 69 |
t.Errorf("Draw time too long: %s", drawTime) |
| 70 |
} |
| 71 |
}) |
| 72 |
} |
| 73 |
} |