]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/base64/base64-tests.factor
factor: add newlines to .factor files
[factor.git] / basis / base64 / base64-tests.factor
index 23daf0083eafa5c0fca48531119140143197d3dd..ef7e809c8836689bd89f170d594793e760683d0a 100644 (file)
@@ -1,6 +1,7 @@
-USING: kernel tools.test base64 strings sequences
-io.encodings.string io.encodings.ascii ;
-IN: base64.tests
+USING: base64 byte-arrays io.encodings.ascii io.encodings.string
+kernel sequences splitting strings tools.test ;
+
+{ t } [ 256 <iota> >byte-array dup >base64 base64> = ] unit-test
 
 { "abcdefghijklmnopqrstuvwxyz" } [ "abcdefghijklmnopqrstuvwxyz" ascii encode >base64 base64> ascii decode
 ] unit-test
@@ -25,3 +26,31 @@ IN: base64.tests
 
 [ { 33 52 17 40 12 51 33 43 18 33 23 } base64> ]
 [ malformed-base64? ] must-fail-with
+
+{
+    {
+        B{ 123 34 97 108 103 34 58 34 72 83 50 53 54 34 125 }
+        B{ 123 34 115 117 98 34 58 34 74 111 101 34 125 }
+        B{
+            138 151 175 68 219 145 63 161 223 148 111 28 20 169 230
+            80 251 114 166 187 145 11 135 219 212 53 173 160 178 250
+            217 38
+        }
+    }
+} [
+    "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJKb2UifQ.ipevRNuRP6HflG8cFKnmUPtypruRC4fb1DWtoLL62SY"
+    "." split [ base64> ] map
+] unit-test
+
+{ "01a+b/cd" } [ "\xd3V\xbeo\xf7\x1d" >base64 "" like ] unit-test
+{ "\xd3V\xbeo\xf7\x1d" } [ "01a+b/cd" base64> "" like ] unit-test
+
+{ "01a-b_cd" } [ "\xd3V\xbeo\xf7\x1d" >urlsafe-base64 "" like ] unit-test
+{ "\xd3V\xbeo\xf7\x1d" } [ "01a-b_cd" urlsafe-base64> "" like ] unit-test
+
+{ "eyJhIjoiYmNkIn0" }
+[ "{\"a\":\"bcd\"}" >urlsafe-base64-jwt >string ] unit-test
+
+{ "{\"a\":\"bcd\"}" }
+[ "{\"a\":\"bcd\"}" >urlsafe-base64-jwt urlsafe-base64> >string ] unit-test
+