Diff tests: base64_encode

Function:
Description: Encodes string using MIME base64 algorithm.
Version A:
Version B:
base64_encode tests version 22base64_encode tests version 23
 1function base64_encode_tests() {
 1function base64_encode_tests() {
 2
 2
 3  // API reference: http://docs.jquery.com/QUnit
 3  // API reference: http://docs.jquery.com/QUnit
 4  module( "base64_encode" );
 4  module( "base64_encode" );
 5
 5
 6  function cycle( $value, $utf8_encode ) {
 6  function cycle( $value, $utf8_encode ) {
 7
 7
 8    var $clean_value = $utf8_encode ? utf8_encode( $value ) : $value;
 8    var $clean_value = $utf8_encode ? utf8_encode( $value ) : $value;
 9
 9
10    var $encoded = base64_encode( $clean_value );
10    var $encoded = base64_encode( $clean_value );
11    var $decoded = base64_decode( $encoded );
11    var $decoded = base64_decode( $encoded );
12
12
13    if ( $utf8_encode ) { $decoded = utf8_decode( $decoded ); }
13    if ( $utf8_encode ) { $decoded = utf8_decode( $decoded ); }
14
14
15    equal( $decoded, $value, 'Encoded/decoded equals original value.' );
15    equal( $decoded, $value, 'Encoded/decoded equals original value.' );
16
16
17  }
17  }
18
18
19  test( "base64_encode", function() {
19  test( "base64_encode", function() {
20
20
21    var data = [
21    var data = [
22      [ '', '', 0, false ],
22      [ '', '', 0, false ],
23      [ 'a', 'YQ==', 1, false ],
23      [ 'a', 'YQ==', 1, false ],
24      [ 1, 'MQ==', 1, false ],
24      [ 1, 'MQ==', 1, false ],
25      [ '1', 'MQ==', 1, false ],
25      [ '1', 'MQ==', 1, false ],
26      [ '漢字仮名交じり文', '5ryi5a2X5Luu5ZCN5Lqk44GY44KK5paH', 24, true ]
26      [ '漢字仮名交じり文', '5ryi5a2X5Luu5ZCN5Lqk44GY44KK5paH', 24, true ]
27    ];
27    ];
28
28
29    for ( var i in data ) {
29    for ( var i in data ) {
30
30
31      var is_utf16 = data[ i ][ 3 ];
31      var is_utf16 = data[ i ][ 3 ];
32      var utf8 = utf8_encode( data[ i ][ 0 ] );
32      var utf8 = utf8_encode( data[ i ][ 0 ] );
33
33
34      equal( base64_encode( utf8 ), data[ i ][ 1 ] );
34      equal( base64_encode( utf8 ), data[ i ][ 1 ] );
35
35
36      cycle( utf8, true );
36      cycle( utf8, true );
37      cycle( utf8, false );
37      cycle( utf8, false );
38      cycle( data[ i ][ 0 ], true );
38      cycle( data[ i ][ 0 ], true );
39
39
40      if ( is_utf16 ) {
40      if ( is_utf16 ) {
41        raises( function() { cycle( data[ i ][ 0 ], false ); }, 'Error', 'Cannot encode UTF-16 string.' );
41        raises(
42          function() { cycle( data[ i ][ 0 ], false ); },
43          'Cannot encode UTF-16 string.',
44          'Cannot encode UTF-16 string.'
45        );
42      }
46      }
43      else {
47      else {
44        cycle( data[ i ][ 0 ], false );
48        cycle( data[ i ][ 0 ], false );
45      }
49      }
46
50
47      //equal( data[ i ][ 0 ].length, data[ i ][ 2 ] );
51      //equal( data[ i ][ 0 ].length, data[ i ][ 2 ] );
48
52
49    }
53    }
50
54
51  } );
55  } );
52
56
53}
57}