Permalink
Browse files

add some Perl5 base64.t tests and split off binary tests

  • Loading branch information...
1 parent 77b54b6 commit a9659281e944cd018e7e55fb3ef09d9fc9f38cae @ronaldxs committed Sep 9, 2012
Showing with 27 additions and 5 deletions.
  1. +25 −0 t/binary.t
  2. +2 −5 t/long_line_and_encoding_cases.t
View
@@ -0,0 +1,25 @@
+use v6;
+
+use Test;
+use PP::MIME::Base64;
+
+plan 8;
+
+# from Perl 5 Mime::Base64 base64.t
+# I don't think it makes sense any more to test encoding each individual byte
+# value but may make sense to do a few end cases
+is encode_base64(Buf.new(0)), 'AA==', 'encode Test on NULL/0 byte';
+is encode_base64(Buf.new(1)), 'AQ==', 'encode Test on byte value 1';
+is encode_base64(Buf.new(255)), '/w==', 'encode Test on byte value 255';
+ok decode_base64('AA==') eq Buf.new(0), 'decode Test on NULL/0 byte';
+ok decode_base64('AQ==') eq Buf.new(1), 'decode Test on byte value 1';
+ok decode_base64('/w==') eq Buf.new(255), 'decode Test on byte value 255';
+
+my Buf $camelia_ico = slurp(
+ $?FILE.path.directory ~ '/data/camelia-favicon.ico', :bin
+);
+my Str $camelia_b64 = slurp(
+ $?FILE.path.directory ~ '/data/camelia-favicon.b64'
+);
+is encode_base64($camelia_ico), $camelia_b64.chomp, 'binary img encode test';
+ok decode_base64($camelia_b64) eq $camelia_ico, 'binary img decode test';
@@ -3,6 +3,8 @@ use v6;
use Test;
use PP::MIME::Base64;
+plan 7;
+
is encode_base64_str(
'This is a long line whose base64 encoding should be broken into multiple lines as required by MIME.'),
"VGhpcyBpcyBhIGxvbmcgbGluZSB3aG9zZSBiYXNlNjQgZW5jb2Rpbmcgc2hvdWxkIGJlIGJyb2tl
@@ -25,8 +27,3 @@ is encode_base64_str($screen_w_accent_e, 'latin-1'), '6WNyYW4=', 'latin-1 string
is decode_base64_str('6WNyYW4=', 'latin-1'), $screen_w_accent_e, 'latin-1 string decoding test';
is encode_base64_str($screen_w_accent_e), 'w6ljcmFu', 'utf-8 string encoding test';
is decode_base64_str('w6ljcmFu'), $screen_w_accent_e, 'utf-8 string decoding test';
-
-my Buf $camelia_ico = slurp("data/camelia-favicon.ico", :bin);
-my Str $camelia_b64 = slurp("data/camelia-favicon.b64");
-is encode_base64($camelia_ico), $camelia_b64.chomp, 'binary img encode test';
-ok decode_base64($camelia_b64) eq $camelia_ico, 'binary img decode test';

0 comments on commit a965928

Please sign in to comment.