summaryrefslogtreecommitdiff
path: root/base64_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'base64_test.go')
-rw-r--r--base64_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/base64_test.go b/base64_test.go
new file mode 100644
index 0000000..43367af
--- /dev/null
+++ b/base64_test.go
@@ -0,0 +1,44 @@
+// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+//
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+package lowmemjson
+
+import (
+ "bytes"
+ "encoding/base64"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func b64encode(t *testing.T, input []byte) []byte {
+ var encoded bytes.Buffer
+ enc := base64.NewEncoder(base64.StdEncoding, &encoded)
+ _, err := enc.Write(input)
+ require.NoError(t, err)
+ require.NoError(t, enc.Close())
+ return encoded.Bytes()
+}
+
+func b64decode(t *testing.T, input []byte) []byte {
+ var decoded bytes.Buffer
+ dec := newBase64Decoder(&decoded)
+ _, err := dec.Write(input)
+ require.NoError(t, err)
+ require.NoError(t, dec.Close())
+ return decoded.Bytes()
+}
+
+func FuzzBase64Decoder(f *testing.F) {
+ f.Fuzz(func(t *testing.T, input []byte) {
+ encoded := b64encode(t, input)
+ decoded := b64decode(t, encoded)
+ t.Logf("input b64 = %q", encoded)
+ t.Logf("expected decoded = %#v", input)
+ t.Logf("actual decoded = %#v", decoded)
+ if !bytes.Equal(input, decoded) {
+ t.Fail()
+ }
+ })
+}