utils_test.go 988 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
  2. package config
  3. import (
  4. "fmt"
  5. "strings"
  6. "testing"
  7. "github.com/google/go-cmp/cmp"
  8. )
  9. var _ = fmt.Print
  10. func TestStringLiteralParsing(t *testing.T) {
  11. for q, expected := range map[string]string{
  12. `abc`: `abc`,
  13. `a\nb\M`: "a\nb\\M",
  14. `a\x20\x1\u1234\123\12|`: "a \\x1\u1234\123\x0a|",
  15. } {
  16. actual, err := StringLiteral(q)
  17. if err != nil {
  18. t.Fatal(err)
  19. }
  20. if expected != actual {
  21. t.Fatalf("Failed with input: %#v\n%#v != %#v", q, expected, actual)
  22. }
  23. }
  24. }
  25. func TestNormalizeShortcuts(t *testing.T) {
  26. for q, expected_ := range map[string]string{
  27. `a`: `a`,
  28. `+`: `plus`,
  29. `cmd+b>opt+>`: `super+b alt+>`,
  30. `cmd+>>opt+>`: `super+> alt+>`,
  31. } {
  32. expected := strings.Split(expected_, " ")
  33. actual := NormalizeShortcuts(q)
  34. if diff := cmp.Diff(expected, actual); diff != "" {
  35. t.Fatalf("failed with input: %#v\n%s", q, diff)
  36. }
  37. }
  38. }