2 QUnit
.module( 'jquery.byteLength', QUnit
.newMwEnvironment() );
4 QUnit
.test( 'Simple text', 5, function ( assert
) {
5 var azLc
= 'abcdefghijklmnopqrstuvwxyz',
6 azUc
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
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' );
19 QUnit
.test( 'Special text', 4, function ( assert
) {
20 // https://en.wikipedia.org/wiki/UTF-8
26 // Character \U00024B62 (Han script) can't be represented in javascript as a single
27 // code point, instead it is composed as a surrogate pair of two separate code units.
28 // http://codepoints.net/U+24B62
29 // http://www.fileformat.info/info/unicode/char/24B62/index.htm
30 u024B62
= '\uD852\uDF62';
32 assert
.strictEqual( $.byteLength( u0024
), 1, 'U+0024' );
33 assert
.strictEqual( $.byteLength( u00A2
), 2, 'U+00A2' );
34 assert
.strictEqual( $.byteLength( u20AC
), 3, 'U+20AC' );
35 assert
.strictEqual( $.byteLength( u024B62
), 4, 'U+024B62 (surrogate pair: \\uD852\\uDF62)' );