-
Notifications
You must be signed in to change notification settings - Fork 4
/
base64_test.go
55 lines (44 loc) · 1.09 KB
/
base64_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
package main
import (
"bytes"
"testing"
)
func TestBase64(t *testing.T) {
var samples = []struct {
in, out string
}{
{"", ""},
{"1", "MQ=="},
{"12", "MTI="},
{"123", "MTIz"},
{"1234", "MTIzNA=="},
{"12345", "MTIzNDU="},
{"123456", "MTIzNDU2"},
}
t.Log("test non-overlapping buffers")
for i, sample := range samples {
in := []byte(sample.in)
expected := []byte(sample.out)
out := make([]byte, len(expected))
sgpBase64(out, in, _SGP_BASE64_ALPHABET)
t.Logf("%d: %q => %q", i, in, out)
if bytes.Compare(out, expected) != 0 {
t.Fatalf("%d: expected %q for %q, got %q", i, expected, in, out)
}
}
// test-case for
// [bbbb....[xxxyyy]]
// +--------+
t.Log("test selfencoding-buffer")
for i, sample := range samples {
expected := []byte(sample.out)
out := make([]byte, len(expected))
j := len(out) - len(sample.in)
copy(out[j:], sample.in)
sgpBase64(out, out[j:], _SGP_BASE64_ALPHABET)
t.Logf("%d: %q => %q", i, sample.in, out)
if bytes.Compare(out, expected) != 0 {
t.Fatalf("%d: expected %q for %q, got %q", i, expected, sample.in, out)
}
}
}