diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-10-02 19:26:40 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-10-02 19:28:44 +0200 |
commit | 712654d4c023a2ab13190c6905d313e0ba897965 (patch) | |
tree | b8505b420d6621022fa6a46271340071d8881322 /tests/unit/util/base64.scm | |
parent | Made displayln into a library export. (diff) | |
download | calp-712654d4c023a2ab13190c6905d313e0ba897965.tar.gz calp-712654d4c023a2ab13190c6905d313e0ba897965.tar.xz |
Rewrite test running system.
Diffstat (limited to 'tests/unit/util/base64.scm')
-rw-r--r-- | tests/unit/util/base64.scm | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/unit/util/base64.scm b/tests/unit/util/base64.scm new file mode 100644 index 00000000..7fac883c --- /dev/null +++ b/tests/unit/util/base64.scm @@ -0,0 +1,45 @@ +;;; Commentary: +;; Test that Base64 encoding and decoding works +;; Examples from RFC4648 +;;; Code: + +(define-module (test base64) + :use-module (srfi srfi-64) + :use-module (srfi srfi-64 test-error) + :use-module (srfi srfi-88) + :use-module (base64)) + +(test-group "Tests from RFC 4648" + (test-group "Decoding tests" + (test-equal "" (base64encode "")) + (test-equal "Zg==" (base64encode "f")) + (test-equal "Zm8=" (base64encode "fo")) + (test-equal "Zm9v" (base64encode "foo")) + (test-equal "Zm9vYg==" (base64encode "foob")) + (test-equal "Zm9vYmE=" (base64encode "fooba")) + (test-equal "Zm9vYmFy" (base64encode "foobar"))) + (test-group "Encoding tests" + (test-equal "" (base64decode "")) + (test-equal "f" (base64decode "Zg==")) + (test-equal "fo" (base64decode "Zm8=")) + (test-equal "foo" (base64decode "Zm9v")) + (test-equal "foob" (base64decode "Zm9vYg==")) + (test-equal "fooba" (base64decode "Zm9vYmE=")) + (test-equal "foobar" (base64decode "Zm9vYmFy")))) + + +;; Other tests + +(test-error "Invalid base64" + 'decoding-error + (base64decode "@@@@")) + +(test-error "To short base64" + 'decoding-error + (base64decode "=")) + +(test-equal "AAECAw==" (bytevector->base64-string #vu8(0 1 2 3))) + +(test-equal #vu8(0 1 2 3) (base64-string->bytevector "AAECAw==")) + +'((base64)) |