Debian Codegraph @

demos/styles/styles_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 "sync"
19 "testing"
20 "time"
21
22 "github.com/gdamore/tcell/v3"
23 "github.com/gdamore/tcell/v3/vt"
24 )
25
26 // TestStyles just exercises the code in the styles demo program.
27 // It does not validate that the content is accurate, that should be done
28 // manually by running the program with a real terminal.
29 func TestStyles(t *testing.T) {
30
31 mt := vt.NewMockTerm()
32 scr, err := tcell.NewTerminfoScreenFromTty(mt)
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
40 go func() {
41 defer wg.Done()
42 main()
43 }()
44
45 // give enough time for the screen to draw
46 // this is needed because main is running asynchronously.
47 time.Sleep(time.Millisecond * 50)
48
49 mt.Drain()
50
51 // control L (forces sync)
52 mt.KeyTap(vt.KeyRCtrl, vt.KeyL)
53
54 attrs := 0
55 var lastAttr vt.Attr
56 for y := range vt.Row(24) {
57 for x := range vt.Col(80) {
58 if attr := mt.GetCell(vt.Coord{X: vt.Col(x), Y: vt.Row(y)}).S.Attr(); attr != lastAttr {
59 attrs++
60 lastAttr = attr
61 }
62 }
63 }
64
65 mt.KeyTap(vt.KeyRCtrl, vt.KeyQ)
66
67 wg.Wait()
68 if attrs < 8 {
69 t.Errorf("Not enough attribute changes changes: %d", attrs)
70 }
71 }