aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/encoding/base64/base64_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2015-10-31 00:59:47 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2015-10-31 00:59:47 +0000
commitaf146490bb04205107cb23e301ec7a8ff927b5fc (patch)
tree13beeaed3698c61903fe93fb1ce70bd9b18d4e7f /libgo/go/encoding/base64/base64_test.go
parent725e1be3406315d9bcc8195d7eef0a7082b3c7cc (diff)
downloadgcc-af146490bb04205107cb23e301ec7a8ff927b5fc.zip
gcc-af146490bb04205107cb23e301ec7a8ff927b5fc.tar.gz
gcc-af146490bb04205107cb23e301ec7a8ff927b5fc.tar.bz2
runtime: Remove now unnecessary pad field from ParFor.
It is not needed due to the removal of the ctx field. Reviewed-on: https://go-review.googlesource.com/16525 From-SVN: r229616
Diffstat (limited to 'libgo/go/encoding/base64/base64_test.go')
-rw-r--r--libgo/go/encoding/base64/base64_test.go74
1 files changed, 61 insertions, 13 deletions
diff --git a/libgo/go/encoding/base64/base64_test.go b/libgo/go/encoding/base64/base64_test.go
index 7d199bf..d144b96 100644
--- a/libgo/go/encoding/base64/base64_test.go
+++ b/libgo/go/encoding/base64/base64_test.go
@@ -45,6 +45,48 @@ var pairs = []testpair{
{"sure.", "c3VyZS4="},
}
+// Do nothing to a reference base64 string (leave in standard format)
+func stdRef(ref string) string {
+ return ref
+}
+
+// Convert a reference string to URL-encoding
+func urlRef(ref string) string {
+ ref = strings.Replace(ref, "+", "-", -1)
+ ref = strings.Replace(ref, "/", "_", -1)
+ return ref
+}
+
+// Convert a reference string to raw, unpadded format
+func rawRef(ref string) string {
+ return strings.TrimRight(ref, "=")
+}
+
+// Both URL and unpadding conversions
+func rawUrlRef(ref string) string {
+ return rawRef(urlRef(ref))
+}
+
+// A nonstandard encoding with a funny padding character, for testing
+var funnyEncoding = NewEncoding(encodeStd).WithPadding(rune('@'))
+
+func funnyRef(ref string) string {
+ return strings.Replace(ref, "=", "@", -1)
+}
+
+type encodingTest struct {
+ enc *Encoding // Encoding to test
+ conv func(string) string // Reference string converter
+}
+
+var encodingTests = []encodingTest{
+ encodingTest{StdEncoding, stdRef},
+ encodingTest{URLEncoding, urlRef},
+ encodingTest{RawStdEncoding, rawRef},
+ encodingTest{RawURLEncoding, rawUrlRef},
+ encodingTest{funnyEncoding, funnyRef},
+}
+
var bigtest = testpair{
"Twas brillig, and the slithy toves",
"VHdhcyBicmlsbGlnLCBhbmQgdGhlIHNsaXRoeSB0b3Zlcw==",
@@ -60,8 +102,11 @@ func testEqual(t *testing.T, msg string, args ...interface{}) bool {
func TestEncode(t *testing.T) {
for _, p := range pairs {
- got := StdEncoding.EncodeToString([]byte(p.decoded))
- testEqual(t, "Encode(%q) = %q, want %q", p.decoded, got, p.encoded)
+ for _, tt := range encodingTests {
+ got := tt.enc.EncodeToString([]byte(p.decoded))
+ testEqual(t, "Encode(%q) = %q, want %q", p.decoded,
+ got, tt.conv(p.encoded))
+ }
}
}
@@ -97,18 +142,21 @@ func TestEncoderBuffering(t *testing.T) {
func TestDecode(t *testing.T) {
for _, p := range pairs {
- dbuf := make([]byte, StdEncoding.DecodedLen(len(p.encoded)))
- count, end, err := StdEncoding.decode(dbuf, []byte(p.encoded))
- testEqual(t, "Decode(%q) = error %v, want %v", p.encoded, err, error(nil))
- testEqual(t, "Decode(%q) = length %v, want %v", p.encoded, count, len(p.decoded))
- if len(p.encoded) > 0 {
- testEqual(t, "Decode(%q) = end %v, want %v", p.encoded, end, (p.encoded[len(p.encoded)-1] == '='))
- }
- testEqual(t, "Decode(%q) = %q, want %q", p.encoded, string(dbuf[0:count]), p.decoded)
+ for _, tt := range encodingTests {
+ encoded := tt.conv(p.encoded)
+ dbuf := make([]byte, tt.enc.DecodedLen(len(encoded)))
+ count, end, err := tt.enc.decode(dbuf, []byte(encoded))
+ testEqual(t, "Decode(%q) = error %v, want %v", encoded, err, error(nil))
+ testEqual(t, "Decode(%q) = length %v, want %v", encoded, count, len(p.decoded))
+ if len(encoded) > 0 {
+ testEqual(t, "Decode(%q) = end %v, want %v", encoded, end, len(p.decoded)%3 != 0)
+ }
+ testEqual(t, "Decode(%q) = %q, want %q", encoded, string(dbuf[0:count]), p.decoded)
- dbuf, err = StdEncoding.DecodeString(p.encoded)
- testEqual(t, "DecodeString(%q) = error %v, want %v", p.encoded, err, error(nil))
- testEqual(t, "DecodeString(%q) = %q, want %q", string(dbuf), p.decoded)
+ dbuf, err = tt.enc.DecodeString(encoded)
+ testEqual(t, "DecodeString(%q) = error %v, want %v", encoded, err, error(nil))
+ testEqual(t, "DecodeString(%q) = %q, want %q", string(dbuf), p.decoded)
+ }
}
}