key-encoding_test.go 695 B

12345678910111213141516171819202122232425262728293031
  1. // License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
  2. package loop
  3. import (
  4. "fmt"
  5. "testing"
  6. "github.com/google/go-cmp/cmp"
  7. )
  8. var _ = fmt.Print
  9. func TestKeyEventFromCSI(t *testing.T) {
  10. test_text := func(csi string, expected, alternate string) {
  11. ev := KeyEventFromCSI(csi)
  12. if ev == nil {
  13. t.Fatalf("Failed to get parse %#v", csi)
  14. }
  15. if diff := cmp.Diff(expected, ev.Text); diff != "" {
  16. t.Fatalf("Failed to get text from %#v:\n%s", csi, diff)
  17. }
  18. if diff := cmp.Diff(alternate, ev.AlternateKey); diff != "" {
  19. t.Fatalf("Failed to get alternate from %#v:\n%s", csi, diff)
  20. }
  21. }
  22. test_text("121;;121u", "y", "")
  23. test_text("121::122;;121u", "y", "z")
  24. }