summaryrefslogtreecommitdiff
path: root/tui/termfo/termfo_test.go
diff options
context:
space:
mode:
authorraven <citrons@mondecitronne.com>2026-02-20 13:42:12 -0600
committerraven <citrons@mondecitronne.com>2026-02-20 13:46:59 -0600
commit5b6196ebe67cf954bae8212c1a33b869da723e11 (patch)
treedce33c06621847c3862e64bda914b1e8a450317d /tui/termfo/termfo_test.go
parent05c068749740f9430d1fda7698c433697eef1652 (diff)
support builtin terminfo
copy termfo into the repository and modify it to embed an xterm terminfo to as a fallback
Diffstat (limited to 'tui/termfo/termfo_test.go')
-rw-r--r--tui/termfo/termfo_test.go87
1 files changed, 87 insertions, 0 deletions
diff --git a/tui/termfo/termfo_test.go b/tui/termfo/termfo_test.go
new file mode 100644
index 0000000..60564ef
--- /dev/null
+++ b/tui/termfo/termfo_test.go
@@ -0,0 +1,87 @@
+package termfo
+
+import (
+ "fmt"
+ "io"
+ "os"
+ "strings"
+ "testing"
+)
+
+func BenchmarkNew(b *testing.B) {
+ t := os.Getenv("TERM")
+ b.ReportAllocs()
+ for n := 0; n < b.N; n++ {
+ New(t)
+ }
+}
+
+func TestNew(t *testing.T) {
+ tests := []struct {
+ term string
+ intSize int
+ }{
+ {"xterm", 2},
+ {"xterm-256color", 4},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.term, func(t *testing.T) {
+ ti, err := New(tt.term)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if ti.Name != tt.term {
+ t.Errorf("wrong name: %q", ti.Name)
+ }
+ if ti.IntSize != tt.intSize {
+ t.Errorf("intsize: %d", ti.IntSize)
+ }
+
+ // Just a basic sanity check.
+ if len(ti.Bools) < 10 || len(ti.Numbers) < 5 || len(ti.Strings) < 200 || len(ti.Extended) < 50 {
+ t.Errorf("bools: %d nums: %d strs: %d ext: %d", len(ti.Bools), len(ti.Numbers), len(ti.Strings), len(ti.Extended))
+ }
+ })
+ }
+}
+
+func TestKeys(t *testing.T) {
+ run := func(ti *Terminfo, seq string) []string {
+ var collect []string
+ ch := ti.FindKeys(strings.NewReader(seq))
+ for e := <-ch; ; e = <-ch {
+ if e.Err != nil {
+ if e.Err == io.EOF {
+ break
+ }
+ t.Fatal(e.Err)
+ }
+ collect = append(collect, e.Key.String())
+ }
+ return collect
+ }
+
+ {
+ ti, err := New("xterm")
+ if err != nil {
+ t.Fatal(err)
+ }
+ f := run(ti, "\x1bOP\x1b[1;2P\x1bOA")
+ if fmt.Sprintf("%s", f) != "[<F1> <S-F1> <Up>]" {
+ t.Error(f)
+ }
+ }
+
+ {
+ ti, err := New("vi200")
+ if err != nil {
+ t.Fatal(err)
+ }
+ f := run(ti, "\x1b?q\x1bA")
+ if fmt.Sprintf("%s", f) != "[<F1> <Up>]" {
+ t.Error(f)
+ }
+ }
+}