aboutsummaryrefslogtreecommitdiff
path: root/tests/core/encoding/base64
diff options
context:
space:
mode:
authorLaytan Laats <laytanlaats@hotmail.com>2023-12-16 21:40:41 +0100
committerLaytan Laats <laytanlaats@hotmail.com>2024-03-04 17:26:17 +0100
commitb6c47e796390924faabd236204bc620ea35c1d13 (patch)
treec8d7912237ec13e81ec4bcb04418d2dfe0979584 /tests/core/encoding/base64
parent5533a327eb0f526cbebbe71124620fcbb0bc0649 (diff)
encoding/base64: add decode_into, add tests
Diffstat (limited to 'tests/core/encoding/base64')
-rw-r--r--tests/core/encoding/base64/base64.odin60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/core/encoding/base64/base64.odin b/tests/core/encoding/base64/base64.odin
new file mode 100644
index 000000000..41dbba683
--- /dev/null
+++ b/tests/core/encoding/base64/base64.odin
@@ -0,0 +1,60 @@
+package test_encoding_base64
+
+import "core:encoding/base64"
+import "core:fmt"
+import "core:intrinsics"
+import "core:os"
+import "core:reflect"
+import "core:testing"
+
+TEST_count := 0
+TEST_fail := 0
+
+when ODIN_TEST {
+ expect_value :: testing.expect_value
+
+} else {
+ expect_value :: proc(t: ^testing.T, value, expected: $T, loc := #caller_location) -> bool where intrinsics.type_is_comparable(T) {
+ TEST_count += 1
+ ok := value == expected || reflect.is_nil(value) && reflect.is_nil(expected)
+ if !ok {
+ TEST_fail += 1
+ fmt.printf("[%v] expected %v, got %v\n", loc, expected, value)
+ }
+ return ok
+ }
+}
+
+main :: proc() {
+ t := testing.T{}
+
+ test_encoding(&t)
+ test_decoding(&t)
+
+ fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
+ if TEST_fail > 0 {
+ os.exit(1)
+ }
+}
+
+@(test)
+test_encoding :: proc(t: ^testing.T) {
+ expect_value(t, base64.encode(transmute([]byte)string("")), "")
+ expect_value(t, base64.encode(transmute([]byte)string("f")), "Zg==")
+ expect_value(t, base64.encode(transmute([]byte)string("fo")), "Zm8=")
+ expect_value(t, base64.encode(transmute([]byte)string("foo")), "Zm9v")
+ expect_value(t, base64.encode(transmute([]byte)string("foob")), "Zm9vYg==")
+ expect_value(t, base64.encode(transmute([]byte)string("fooba")), "Zm9vYmE=")
+ expect_value(t, base64.encode(transmute([]byte)string("foobar")), "Zm9vYmFy")
+}
+
+@(test)
+test_decoding :: proc(t: ^testing.T) {
+ expect_value(t, string(base64.decode("")), "")
+ expect_value(t, string(base64.decode("Zg==")), "f")
+ expect_value(t, string(base64.decode("Zm8=")), "fo")
+ expect_value(t, string(base64.decode("Zm9v")), "foo")
+ expect_value(t, string(base64.decode("Zm9vYg==")), "foob")
+ expect_value(t, string(base64.decode("Zm9vYmE=")), "fooba")
+ expect_value(t, string(base64.decode("Zm9vYmFy")), "foobar")
+}