query_test.go 958 B

123456789101112131415161718192021222324252627282930313233343536
  1. // License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
  2. package unicode_names
  3. import (
  4. "fmt"
  5. "kitty/tools/utils"
  6. "testing"
  7. "github.com/google/go-cmp/cmp"
  8. "golang.org/x/exp/slices"
  9. )
  10. var _ = fmt.Print
  11. func TestUnicodeInputQueries(t *testing.T) {
  12. ts := func(query string, expected ...rune) {
  13. if expected == nil {
  14. expected = make([]rune, 0)
  15. }
  16. expected = utils.Sort(expected, func(a, b rune) int { return int(a) - int(b) })
  17. actual := CodePointsForQuery(query)
  18. actual = utils.Sort(actual, func(a, b rune) int { return int(a) - int(b) })
  19. diff := cmp.Diff(expected, actual)
  20. if diff != "" {
  21. t.Fatalf("Failed query: %#v\n%s", query, diff)
  22. }
  23. }
  24. ts("horiz ell", 0x2026, 0x22ef, 0x2b2c, 0x2b2d, 0xfe19)
  25. ts("horizontal ell", 0x2026, 0x22ef, 0x2b2c, 0x2b2d, 0xfe19)
  26. ts("kfjhgkjdsfhgkjds")
  27. if slices.Index(CodePointsForQuery("bee"), 0x1f41d) < 0 {
  28. t.Fatalf("The query bee did not match the codepoint: 0x1f41d")
  29. }
  30. }