Merge "resources: Strip '$' and 'mw' from file closures"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.jscompat.test.js
1 /**
2 * Some misc JavaScript compatibility tests,
3 * just to make sure the environments we run in are consistent.
4 */
5 ( function () {
6 QUnit.module( 'mediawiki.jscompat', QUnit.newMwEnvironment() );
7
8 QUnit.test( 'Variable with Unicode letter in name', function ( assert ) {
9 var orig, ŝablono;
10
11 orig = 'some token';
12 ŝablono = orig;
13
14 assert.deepEqual( ŝablono, orig, 'ŝablono' );
15 assert.deepEqual( \u015dablono, orig, '\\u015dablono' );
16 assert.deepEqual( \u015Dablono, orig, '\\u015Dablono' );
17 } );
18
19 /*
20 // Not that we need this. ;)
21 // This fails on IE 6-8
22 // Works on IE 9, Firefox 6, Chrome 14
23 ...( 'Keyword workaround: "if" as variable name using Unicode escapes', function ( assert ) {
24 var orig = "another token";
25 \u0069\u0066 = orig;
26 assert.deepEqual( \u0069\u0066, orig, '\\u0069\\u0066' );
27 });
28 */
29
30 /*
31 // Not that we need this. ;)
32 // This fails on IE 6-9
33 // Works on Firefox 6, Chrome 14
34 ...( 'Keyword workaround: "if" as member variable name using Unicode escapes', function ( assert ) {
35 var orig = "another token";
36 var foo = {};
37 foo.\u0069\u0066 = orig;
38 assert.deepEqual( foo.\u0069\u0066, orig, 'foo.\\u0069\\u0066' );
39 });
40 */
41
42 QUnit.test( 'Stripping of single initial newline from textarea\'s literal contents (T14130)', function ( assert ) {
43 var maxn, n,
44 expected, $textarea;
45
46 maxn = 4;
47
48 function repeat( str, n ) {
49 var out;
50 if ( n <= 0 ) {
51 return '';
52 } else {
53 out = [];
54 out.length = n + 1;
55 return out.join( str );
56 }
57 }
58
59 for ( n = 0; n < maxn; n++ ) {
60 expected = repeat( '\n', n ) + 'some text';
61
62 $textarea = $( '<textarea>\n' + expected + '</textarea>' );
63 assert.strictEqual( $textarea.val(), expected, 'Expecting ' + n + ' newlines (HTML contained ' + ( n + 1 ) + ')' );
64
65 $textarea = $( '<textarea>' ).val( expected );
66 assert.strictEqual( $textarea.val(), expected, 'Expecting ' + n + ' newlines (from DOM set with ' + n + ')' );
67 }
68 } );
69 }() );