-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzalgo_test.go
84 lines (79 loc) · 1.95 KB
/
zalgo_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package gostringconverters
import (
"math/rand"
"testing"
)
func TestZalgoEncoder(t *testing.T) {
var testCases = []struct {
givenString string
givenNumChars int
expected string
}{
{
givenString: "",
givenNumChars: 1,
expected: "",
},
{
givenString: "abcdefg",
givenNumChars: 0,
expected: "abcdefg",
},
{
givenString: "abcdefg",
givenNumChars: 1,
expected: "aͦb͉c̹d̶ėf̯g̻",
},
{
givenString: "abcdefg",
givenNumChars: 5,
expected: "a̵ͯ̐͗ͦb͓̺͂ͨͩc̷̨̜̔̿d̻̽̊͠͞e̻̠͗̇̀f̮̩͛̽͢g̵̞͓͋ͅ",
},
{
givenString: "abcdefg",
givenNumChars: 10,
expected: "a̸̡̰̓́͑ͧ̽͘͡b̵̨̨̲̰̝̽̍̎ͧc͎̟̞̽ͭͣͦ̋̆͞d̴̢͖̙̙̮̑͊ͥ͊e̢̨̗͙̱ͥ̎̊͘͘f̴̲̬̳͕̻ͥ̆͋ͪg̷̫̗̰̺͙͍̒̔̇",
},
}
rand.Seed(1)
for i, testCase := range testCases {
result := ZalgoEncoder(testCase.givenString, testCase.givenNumChars)
if result != testCase.expected {
t.Error("test", i, "given", testCase.givenString, "and", testCase.givenNumChars, "expected", testCase.expected, "result", result)
}
}
}
func TestZalgoDecoder(t *testing.T) {
var testCases = []struct {
given string
expected string
}{
{
given: "",
expected: "",
},
{
given: "abcdefg",
expected: "abcdefg",
},
{
given: "aͦb͉c̹d̶ėf̯g̻",
expected: "abcdefg",
},
{
given: "a̵ͯ̐͗ͦb͓̺͂ͨͩc̷̨̜̔̿d̻̽̊͠͞e̻̠͗̇̀f̮̩͛̽͢g̵̞͓͋ͅ",
expected: "abcdefg",
},
{
given: "a̸̡̰̓́͑ͧ̽͘͡b̵̨̨̲̰̝̽̍̎ͧc͎̟̞̽ͭͣͦ̋̆͞d̴̢͖̙̙̮̑͊ͥ͊e̢̨̗͙̱ͥ̎̊͘͘f̴̲̬̳͕̻ͥ̆͋ͪg̷̫̗̰̺͙͍̒̔̇",
expected: "abcdefg",
},
}
rand.Seed(1)
for i, testCase := range testCases {
result := ZalgoDecoder(testCase.given)
if result != testCase.expected {
t.Error("test", i, "given", testCase.given, "expected", testCase.expected, "result", result)
}
}
}