-
Notifications
You must be signed in to change notification settings - Fork 0
/
strings_test.go
47 lines (35 loc) · 1.22 KB
/
strings_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package emoji_test
import (
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/koofr/emoji"
)
var _ = Describe("Strings", func() {
Describe("StringToAliases", func() {
It("should keep normal text", func() {
Expect(StringToAliases("text")).To(Equal("text"))
})
It("should convert 4-byte UTF-8 to aliases", func() {
Expect(StringToAliases("𩸽")).To(Equal(":u29e3d:"))
})
It("should convert emojis and 4-byte UTF-8 to aliases", func() {
s := StringToAliases("test 👩❤️💋👨👩❤️💋👩😃👩❤️💋 𩸽 test ❤️❤️💚💛")
Expect(s).To(Equal("test :couplekiss_man_woman::couplekiss_woman_woman::smiley::woman:\u200d:heart:\u200d:kiss:\u200d :u29e3d: test :heart::heart::green_heart::yellow_heart:"))
})
})
})
func BenchmarkStringToAliasesPlain(b *testing.B) {
StringToAliases("")
b.ResetTimer()
for i := 0; i < b.N; i++ {
StringToAliases("test")
}
}
func BenchmarkStringToAliasesUnicode(b *testing.B) {
StringToAliases("")
b.ResetTimer()
for i := 0; i < b.N; i++ {
StringToAliases("test 👩❤️💋👨👩❤️💋👩😃👩❤️💋 𩸽 test ❤️❤️💚💛")
}
}