Debian Codegraph @

demos/colors/colors_test.go

raw symbols SCIP
1 // Copyright 2026 The TCell Authors
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 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 // TestColors just exercises the code in the colors demo program.
28 // It does not validate that the content is accurate, that should be done
29 func TestColors(t *testing.T) {
30
31 interval = time.Microsecond * 10
32
33 for _, colors := range []int{0, 8, 16, 88, 256, 1 << 24} {
34 t.Run(fmt.Sprintf("%d_colors)", colors), func(t *testing.T) {
35 mt := vt.NewMockTerm(vt.MockOptColors(colors))
36 scr, err := tcell.NewTerminfoScreenFromTty(mt)
37 if err != nil {
38 t.Fatalf("failed to create screen: %v", err)
39 }
40 tcell.ShimScreen(scr)
41 var wg sync.WaitGroup
42 wg.Add(1)
43
44 go func() {
45 defer wg.Done()
46 main()
47 }()
48
49 time.Sleep(time.Millisecond * 25)
50 mt.KeyTap(vt.KeyLCtrl, vt.KeyL)
51 mt.SetSize(vt.Coord{X: 10, Y: 10})
52 mt.Drain()
53 time.Sleep(time.Millisecond * 25)
54 mt.KeyTap(vt.KeyLCtrl, vt.KeyQ)
55 mt.Drain()
56 wg.Wait()
57 })
58 }
59 }