Tests: base64_encode version 21

Function:
Description: Encodes string using MIME base64 algorithm.
Version:
Status: obsolete
Date: 2011-12-27 16:47
Summary: Doing more cycle tests.
Programmer: jj5
Tests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function base64_encode_tests() {

  // API reference: http://docs.jquery.com/QUnit
  module( "base64_encode" );

  function cycle( $value, $utf8_encode ) {

    var $clean_value = $utf8_encode ? utf8_encode( $value ) : $value;

    var $encoded = base64_encode( $clean_value );
    var $decoded = base64_decode( $encoded );

    if ( $utf8_encode ) { $decoded = utf8_decode( $decoded ); }

    equal( $decoded, $value, 'Encoded/decoded equals original value.' );

  }

  test( "base64_encode", function() {

    var data = [
      [ '', '', 0 ],
      [ 'a', 'YQ==', 1 ],
      [ 1, 'MQ==', 1 ],
      [ '1', 'MQ==', 1 ],
      [ '漢字仮名交じり文', '5ryi5a2X5Luu5ZCN5Lqk44GY44KK5paH', 24 ]
    ];

    for ( var i in data ) {

      var utf8 = utf8_encode( data[ i ][ 0 ] );

      equal( base64_encode( utf8 ), data[ i ][ 1 ] );

      cycle( utf8, true );
      cycle( utf8, false );
      cycle( data[ i ][ 0 ], true );
      cycle( data[ i ][ 0 ], false );

      //equal( data[ i ][ 0 ].length, data[ i ][ 2 ] );

    }

  } );

}
[top]

Comments

There are no comments yet, be the first!

Please Login or Register to post comments.