e4e579b06342f71a80a2fc050f833c8442dd9376
[lhc/web/wiklou.git] / tests / qunit / suites / resources / jquery / jquery.byteLength.test.js
1 ( function ( $ ) {
2 QUnit.module( 'jquery.byteLength', QUnit.newMwEnvironment() );
3
4 QUnit.test( 'Simple text', 5, function ( assert ) {
5 var azLc = 'abcdefghijklmnopqrstuvwxyz',
6 azUc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
7 num = '0123456789',
8 x = '*',
9 space = ' ';
10
11 assert.equal( $.byteLength( azLc ), 26, 'Lowercase a-z' );
12 assert.equal( $.byteLength( azUc ), 26, 'Uppercase A-Z' );
13 assert.equal( $.byteLength( num ), 10, 'Numbers 0-9' );
14 assert.equal( $.byteLength( x ), 1, 'An asterisk' );
15 assert.equal( $.byteLength( space ), 3, '3 spaces' );
16
17 } );
18
19 QUnit.test( 'Special text', 5, function ( assert ) {
20 // http://en.wikipedia.org/wiki/UTF-8
21 var u0024 = '$',
22 u00A2 = '\u00A2',
23 u20AC = '\u20AC',
24 u024B62 = '\u024B62',
25 // The normal one doesn't display properly, try the below which is the same
26 // according to http://www.fileformat.info/info/unicode/char/24B62/index.htm
27 u024B62alt = '\uD852\uDF62';
28
29 assert.strictEqual( $.byteLength( u0024 ), 1, 'U+0024: 1 byte. $ (dollar sign)' );
30 assert.strictEqual( $.byteLength( u00A2 ), 2, 'U+00A2: 2 bytes. \u00A2 (cent sign)' );
31 assert.strictEqual( $.byteLength( u20AC ), 3, 'U+20AC: 3 bytes. \u20AC (euro sign)' );
32 assert.strictEqual( $.byteLength( u024B62 ), 4, 'U+024B62: 4 bytes. \uD852\uDF62 (a Han character)' );
33 assert.strictEqual( $.byteLength( u024B62alt ), 4, 'U+024B62: 4 bytes. \uD852\uDF62 (a Han character) - alternative method' );
34 } );
35 }( jQuery ) );