-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathc12_test.go
117 lines (97 loc) · 2.03 KB
/
c12_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package c12
import "testing"
func CheckGood(t *testing.T, raw, expect string) {
s, err := Encode(raw)
if err != nil {
t.Error("Error encoding:", err)
} else if s != expect {
t.Error("Bad encoding:", s, "Expected:", expect)
}
s, err = Decode(s)
if err != nil {
t.Error("Error decoding:", err)
} else if s != raw {
t.Error("Bad decoding:", s, "Expected:", raw)
}
}
func TestEmpty(t *testing.T) {
CheckGood(t, "", "")
}
func TestSingleChar(t *testing.T) {
CheckGood(t, "a", "a")
}
func TestMultiSameChar(t *testing.T) {
CheckGood(t, "aaaaaaaaaaaa", "a#12")
}
func TestMultipleSingles(t *testing.T) {
CheckGood(t, "abcdefgh", "abcdefgh")
}
func TestMultipleMultiples(t *testing.T) {
CheckGood(t, "aaabbbaaacccaaaaaaaaaaaadddddddddddddddddd", "a#3b#3a#3c#3a#12d#18")
}
func TestMixed1(t *testing.T) {
CheckGood(t, "aaabaaacaaadaaaeaaa", "a#3ba#3ca#3da#3ea#3")
}
func TestMixed2(t *testing.T) {
CheckGood(t, "abbbacccaddda", "ab#3ac#3ad#3a")
}
func TestMixed3(t *testing.T) {
CheckGood(t, "aaab", "a#3b")
}
func TestMixed4(t *testing.T) {
CheckGood(t, "abbb", "ab#3")
}
func TestUppercase(t *testing.T) {
CheckGood(t, "AaBBbbcCddDD", "AaB#2b#2cCd#2D#2")
}
func TestReallyLongRune(t *testing.T) {
ll := 0x10011
rs := make([]rune, 0, ll)
for i := 0; i < ll; i++ {
rs = append(rs, 'a')
}
s := string(rs)
CheckGood(t, s, "a#65535a#18")
}
func TestBadChar1(t *testing.T) {
_, err := Encode("@")
if err == nil {
t.Fail()
}
}
func TestBadChar2(t *testing.T) {
_, err := Encode("[")
if err == nil {
t.Fail()
}
}
func TestBadChar3(t *testing.T) {
_, err := Encode("{")
if err == nil {
t.Fail()
}
}
func TestBadDecoding1(t *testing.T) {
_, err := Decode("a#")
if err == nil {
t.Fail()
}
}
func TestBadDecoding2(t *testing.T) {
_, err := Decode("a#a")
if err == nil {
t.Fail()
}
}
func TestBadDecoding3(t *testing.T) {
_, err := Decode("a#99999")
if err == nil {
t.Fail()
}
}
func TestBadDecoding4(t *testing.T) {
_, err := Decode("a#9999999999999999999999999999999999999999999")
if err == nil {
t.Fail()
}
}