unidecode_test.go 976 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package unidecode
  2. import (
  3. "testing"
  4. )
  5. func testTransliteration(original string, decoded string, t *testing.T) {
  6. if r := Unidecode(original); r != decoded {
  7. t.Errorf("Expected '%s', got '%s'\n", decoded, r)
  8. }
  9. }
  10. func TestASCII(t *testing.T) {
  11. s := "ABCDEF"
  12. testTransliteration(s, s, t)
  13. }
  14. func TestKnosos(t *testing.T) {
  15. o := "Κνωσός"
  16. d := "Knosos"
  17. testTransliteration(o, d, t)
  18. }
  19. func TestBeiJing(t *testing.T) {
  20. o := "\u5317\u4EB0"
  21. d := "Bei Jing "
  22. testTransliteration(o, d, t)
  23. }
  24. func TestEmoji(t *testing.T) {
  25. o := "Hey Luna t belle 😵😂"
  26. d := "Hey Luna t belle "
  27. testTransliteration(o, d, t)
  28. }
  29. func BenchmarkUnidecode(b *testing.B) {
  30. cases := []string{
  31. "ABCDEF",
  32. "Κνωσός",
  33. "\u5317\u4EB0",
  34. }
  35. for ii := 0; ii < b.N; ii++ {
  36. for _, v := range cases {
  37. _ = Unidecode(v)
  38. }
  39. }
  40. }
  41. func BenchmarkDecodeTable(b *testing.B) {
  42. for ii := 0; ii < b.N; ii++ {
  43. decodeTransliterations()
  44. }
  45. }
  46. func init() {
  47. decodeTransliterations()
  48. }