Commit 2ce8b444 authored by Russ Cox's avatar Russ Cox

base64: cut out some middle layers

R=austin
DELTA=352  (67 added, 196 deleted, 89 changed)
OCL=30694
CL=30713
parent a1646fd5
archive/tar.install: bufio.install bytes.install io.install os.install strconv.install
base64.install: io.install os.install strconv.install
base64.install: bytes.install io.install os.install strconv.install
bignum.install: fmt.install
bufio.install: io.install os.install utf8.install
bytes.install: utf8.install
......
This diff is collapsed.
......@@ -6,6 +6,7 @@ package base64
import (
"base64";
"bytes";
"io";
"os";
"reflect";
......@@ -167,3 +168,36 @@ func TestDecodeCorrupt(t *testing.T) {
}
}
}
func TestBig(t *testing.T) {
n := 3*1000+1;
raw := make([]byte, n);
const alpha = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for i := 0; i < n; i++ {
raw[i] = alpha[i%len(alpha)];
}
encoded := new(io.ByteBuffer);
w := NewEncoder(StdEncoding, encoded);
nn, err := w.Write(raw);
if nn != n || err != nil {
t.Fatalf("Encoder.Write(raw) = %d, %v want %d, nil", nn, err, n);
}
err = w.Close();
if err != nil {
t.Fatalf("Encoder.Close() = %v want nil", err);
}
decoded, err := io.ReadAll(NewDecoder(StdEncoding, encoded));
if err != nil {
t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err);
}
if !bytes.Equal(raw, decoded) {
var i int;
for i = 0; i < len(decoded) && i < len(raw); i++ {
if decoded[i] != raw[i] {
break;
}
}
t.Errorf("Decode(Encode(%d-byte string)) failed at offset %d", n, i);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment