You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

emoji_test.go 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Copyright 2015 Kenneth Shaw
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package emoji
  6. import (
  7. "reflect"
  8. "testing"
  9. )
  10. func TestDumpInfo(t *testing.T) {
  11. t.Logf("codes: %d", len(codeMap))
  12. t.Logf("aliases: %d", len(aliasMap))
  13. }
  14. func TestLookup(t *testing.T) {
  15. a := FromCode("\U0001f37a")
  16. b := FromCode("🍺")
  17. c := FromAlias(":beer:")
  18. d := FromAlias("beer")
  19. if !reflect.DeepEqual(a, b) {
  20. t.Errorf("a and b should equal")
  21. }
  22. if !reflect.DeepEqual(b, c) {
  23. t.Errorf("b and c should equal")
  24. }
  25. if !reflect.DeepEqual(c, d) {
  26. t.Errorf("c and d should equal")
  27. }
  28. if !reflect.DeepEqual(a, d) {
  29. t.Errorf("a and d should equal")
  30. }
  31. m := FromCode("\U0001f44d")
  32. n := FromAlias(":thumbsup:")
  33. o := FromAlias("+1")
  34. if !reflect.DeepEqual(m, n) {
  35. t.Errorf("m and n should equal")
  36. }
  37. if !reflect.DeepEqual(n, o) {
  38. t.Errorf("n and o should equal")
  39. }
  40. if !reflect.DeepEqual(m, o) {
  41. t.Errorf("m and o should equal")
  42. }
  43. }
  44. func TestReplacers(t *testing.T) {
  45. tests := []struct {
  46. f func(string) string
  47. v, exp string
  48. }{
  49. {ReplaceCodes, ":thumbsup: +1 for \U0001f37a! 🍺 \U0001f44d", ":thumbsup: +1 for :beer:! :beer: :+1:"},
  50. {ReplaceAliases, ":thumbsup: +1 :+1: :beer:", "\U0001f44d +1 \U0001f44d \U0001f37a"},
  51. }
  52. for i, x := range tests {
  53. s := x.f(x.v)
  54. if s != x.exp {
  55. t.Errorf("test %d `%s` expected `%s`, got: `%s`", i, x.v, x.exp, s)
  56. }
  57. }
  58. }