1 module( 'jquery.byteLength' );
3 test( '-- Initial check', function() {
5 ok( $.byteLength
, 'jQuery.byteLength defined' );
8 test( 'Simple text', function() {
11 var azLc
= 'abcdefghijklmnopqrstuvwxyz',
12 azUc
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
17 equal( $.byteLength( azLc
), 26, 'Lowercase a-z' );
18 equal( $.byteLength( azUc
), 26, 'Uppercase A-Z' );
19 equal( $.byteLength( num
), 10, 'Numbers 0-9' );
20 equal( $.byteLength( x
), 1, 'An asterisk' );
21 equal( $.byteLength( space
), 3, '3 spaces' );
25 test( 'Special text', window
.foo = function() {
28 // http://en.wikipedia.org/wiki/UTF-8
29 var U_0024
= '\u0024',
32 U_024B62
= '\u024B62',
33 // The normal one doesn't display properly, try the below which is the same
34 // according to http://www.fileformat.info/info/unicode/char/24B62/index.htm
35 U_024B62_alt
= '\uD852\uDF62';
37 strictEqual( $.byteLength( U_0024
), 1, 'U+0024: 1 byte. \u0024 (dollar sign)' );
38 strictEqual( $.byteLength( U_00A2
), 2, 'U+00A2: 2 bytes. \u00A2 (cent sign)' );
39 strictEqual( $.byteLength( U_20AC
), 3, 'U+20AC: 3 bytes. \u20AC (euro sign)' );
40 strictEqual( $.byteLength( U_024B62
), 4, 'U+024B62: 4 bytes. \uD852\uDF62 (a Han character)' );
41 strictEqual( $.byteLength( U_024B62_alt
), 4, 'U+024B62: 4 bytes. \uD852\uDF62 (a Han character) - alternative method' );