Index: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.jscompat.test.js |
— | — | @@ -33,3 +33,30 @@ |
34 | 34 | deepEqual( foo.\u0069\u0066, orig, 'foo.\\u0069\\u0066' ); |
35 | 35 | }); |
36 | 36 | */ |
| 37 | + |
| 38 | +test( 'Stripping of single initial newline from textarea\'s literal contents (bug 12130)', function() { |
| 39 | + var maxn = 4; |
| 40 | + expect(maxn * 2); |
| 41 | + |
| 42 | + var repeat = function(str, n) { |
| 43 | + if (n <= 0) { |
| 44 | + return ''; |
| 45 | + } else { |
| 46 | + var out = Array(n); |
| 47 | + for (var i = 0; i < n; i++) { |
| 48 | + out[i] = str; |
| 49 | + } |
| 50 | + return out.join(''); |
| 51 | + } |
| 52 | + }; |
| 53 | + |
| 54 | + for (var n = 0; n < maxn; n++) { |
| 55 | + var expected = repeat('\n', n) + 'some text'; |
| 56 | + |
| 57 | + var $textarea = $('<textarea>\n' + expected + '</textarea>'); |
| 58 | + equal($textarea.val(), expected, 'Expecting ' + n + ' newlines (HTML contained ' + (n + 1) + ')'); |
| 59 | + |
| 60 | + var $textarea2 = $('<textarea>').val(expected); |
| 61 | + equal($textarea2.val(), expected, 'Expecting ' + n + ' newlines (from DOM set with ' + n + ')'); |
| 62 | + } |
| 63 | +}); |