Merge "Define 'MW_UPDATER' when running update.php"
[mediawiki.git] / tests / qunit / suites / resources / mediawiki / mediawiki.jscompat.test.js
blob3328ce3f1a397b96594843db9d90d9737d65bf8b
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() );
8         QUnit.test( 'Variable with Unicode letter in name', 3, function ( assert ) {
9                 var orig, ŝablono;
11                 orig = 'some token';
12                 ŝablono = orig;
14                 assert.deepEqual( ŝablono, orig, 'ŝablono' );
15                 assert.deepEqual( \u015dablono, orig, '\\u015dablono' );
16                 assert.deepEqual( \u015Dablono, orig, '\\u015Dablono' );
17         } );
19         /*
20         // Not that we need this. ;)
21         // This fails on IE 6-8
22         // Works on IE 9, Firefox 6, Chrome 14
23         QUnit.test( '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         */
30         /*
31         // Not that we need this. ;)
32         // This fails on IE 6-9
33         // Works on Firefox 6, Chrome 14
34         QUnit.test( '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         */
42         QUnit.test( 'Stripping of single initial newline from textarea\'s literal contents (bug 12130)', function ( assert ) {
43                 var maxn, n,
44                         expected, $textarea;
46                 maxn = 4;
47                 QUnit.expect( maxn * 2 );
49                 function repeat( str, n ) {
50                         var out;
51                         if ( n <= 0 ) {
52                                 return '';
53                         } else {
54                                 out = [];
55                                 out.length = n + 1;
56                                 return out.join( str );
57                         }
58                 }
60                 for ( n = 0; n < maxn; n++ ) {
61                         expected = repeat( '\n', n ) + 'some text';
63                         $textarea = $( '<textarea>\n' + expected + '</textarea>' );
64                         assert.equal( $textarea.val(), expected, 'Expecting ' + n + ' newlines (HTML contained ' + (n + 1) + ')' );
66                         $textarea = $( '<textarea>' ).val( expected );
67                         assert.equal( $textarea.val(), expected, 'Expecting ' + n + ' newlines (from DOM set with ' + n + ')' );
68                 }
69         } );
70 }( jQuery ) );