MCPcopy
hub / github.com/gdamore/tcell / TestBoxes

Function TestBoxes

demos/boxes/boxes_test.go:27–73  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func 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 { // CI runs *slow*
58 t.Errorf("Too few boxes: %d", count)
59 }
60 if drawTime < time.Microsecond {
61 // on windows this can happen because our tick counter is too coarse,
62 // and our mock screen is basically limited only by CPU.
63 t.Logf("Draw time very short: %s", drawTime)
64 }
65
66 // It should not take 10 milliseconds to draw a box,
67 // as we generally see values sub millisecond here.
68 if drawTime > 10*time.Millisecond*time.Duration(count) {
69 t.Errorf("Draw time too long: %s", drawTime)
70 }
71 })
72 }
73}

Callers

nothing calls this directly

Calls 6

KeyTapMethod · 0.95
SetSizeMethod · 0.95
NewMockTermFunction · 0.92
MockOptColorsTypeAlias · 0.92
mainFunction · 0.70
DrainMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…