-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathencode_test.go
41 lines (37 loc) · 1.38 KB
/
encode_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
package base256
import (
"bytes"
"testing"
)
var (
encodeSpec = map[string]string{
"Equim": "💀🍵👯🎂💁",
"Hello World!": "👾🍧🙆🍬🙇🕷👦🍯🚶🍬👱🕸",
"「さやかちゃん、大好きだ!(*^ω^*)」": "🦁🌐👈🚁🚴🏤🦁🗾🏍🚁🚴🏟🦁🗺👀🚁🚵🏔🦁🗾🖐🚁🏋🗺🐅🕍💓🚠💋🚈🦁🗺👉🚁🚴💒🐖🚇🚴🌺🤑🍠👟🏝👼🌼🙃🚁🏋🏗",
"👩🏻💻 👨🏻💻咱们工人有力量(": "🐗🏰🖖🌅🐗🏰🖕🚆🐈🌐👉🛀👃🏡💬🕷🐗🏰🖖🌄🐗🏰🖕🚆🐈🌐👉🛀👃🏡💬🚠🤘💈🐯🚆💙🚠💥🕋🐯🚅💫🚡🙏🏝🐅🏞🙌🛎👭🏙😕",
"\xf2\x8e\x88\x31\x1a\xf0\x68\xce\x7a\x3f": "🐏🏘💏🌾😮🛀👲🚘🏇🍏",
"": "",
}
)
func TestEncode(t *testing.T) {
for k, v := range encodeSpec {
if actual := EncodeToString([]byte(k)); actual != v {
t.Fatalf("expected `%s`, got `%s`", v, actual)
}
}
}
func TestEncoder(t *testing.T) {
for k, v := range encodeSpec {
buf := new(bytes.Buffer)
e := NewEncoder(buf)
if _, err := e.Write([]byte(k)); err != nil {
t.Fatal(err)
}
if err := e.Close(); err != nil {
t.Fatal(err)
}
if actual := string(buf.Bytes()); actual != v {
t.Fatalf("expected `%s`, got `%s`", v, actual)
}
}
}