http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94054
Revision: 94054 Author: krinkle Date: 2011-08-08 11:11:02 +0000 (Mon, 08 Aug 2011) Log Message: ----------- Clean up mediawiki.Title test suite: * Remove unused variable i and blti * Change expected to a string instead of a number ** This removes the need for all the comments after 'expected' explaining the choice for that number * Add assertion to verify exact output of the string, rather than just it's length * Rename useLimit to hasLimit Modified Paths: -------------- trunk/phase3/tests/qunit/suites/resources/jquery/jquery.byteLimit.js Modified: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.byteLimit.js =================================================================== --- trunk/phase3/tests/qunit/suites/resources/jquery/jquery.byteLimit.js 2011-08-08 05:39:45 UTC (rev 94053) +++ trunk/phase3/tests/qunit/suites/resources/jquery/jquery.byteLimit.js 2011-08-08 11:11:02 UTC (rev 94054) @@ -23,45 +23,46 @@ } } }; -var blti = 0; + /** * Test factory for $.fn.byteLimit * * @param $input {jQuery} jQuery object in an input element - * @param useLimit {Boolean} Wether a limit should apply at all + * @param hasLimit {Boolean} Wether a limit should apply at all * @param limit {Number} Limit (if used) otherwise undefined - * The limit should be less than 20 (the sample data's length) + * The limit should be less than 20 (the sample data's length) */ var byteLimitTest = function( options ) { var opt = $.extend({ description: '', $input: null, sample: '', - useLimit: false, - expected: 0, + hasLimit: false, + expected: '', limit: null }, options); - var i = blti++; test( opt.description, function() { opt.$input.appendTo( 'body' ); - + // Simulate pressing keys for each of the sample characters $.addChars( opt.$input, opt.sample ); var newVal = opt.$input.val(); - - if ( opt.useLimit ) { - expect(2); - + + if ( opt.hasLimit ) { + expect(3); + ltOrEq( $.byteLength( newVal ), opt.limit, 'Prevent keypresses after byteLimit was reached, length never exceeded the limit' ); - equal( $.byteLength( newVal ), opt.expected, 'Not preventing keypresses too early, length has reached the expected length' ); - + equal( $.byteLength( newVal ), $.byteLength( opt.expected ), 'Not preventing keypresses too early, length has reached the expected length' ); + equal( newVal, opt.expected, 'New value matches the expected string' ); + } else { - expect(1); - equal( $.byteLength( newVal ), opt.expected, 'Unlimited scenarios are not affected, expected length reached' ); + expect(2); + equal( newVal, opt.expected, 'New value matches the expected string' ); + equal( $.byteLength( newVal ), $.byteLength( opt.expected ), 'Unlimited scenarios are not affected, expected length reached' ); } - + opt.$input.remove(); } ); }; @@ -83,8 +84,8 @@ 'type': 'text' }), sample: simpleSample, - useLimit: false, - expected: $.byteLength( simpleSample ) + hasLimit: false, + expected: simpleSample }); byteLimitTest({ @@ -96,9 +97,9 @@ }) .byteLimit(), sample: simpleSample, - useLimit: true, + hasLimit: true, limit: 10, - expected: 10 + expected: '1234567890' }); byteLimitTest({ @@ -109,9 +110,9 @@ }) .byteLimit( 10 ), sample: simpleSample, - useLimit: true, + hasLimit: true, limit: 10, - expected: 10 + expected: '1234567890' }); byteLimitTest({ @@ -123,9 +124,9 @@ }) .byteLimit( 15 ), sample: simpleSample, - useLimit: true, + hasLimit: true, limit: 15, - expected: 15 + expected: '123456789012345' }); byteLimitTest({ @@ -136,9 +137,9 @@ }) .byteLimit( 14 ), sample: mbSample, - useLimit: true, + hasLimit: true, limit: 14, - expected: 14 // (10 x 1-byte char) + (1 x 3-byte char) + (1 x 1-byte char) + expected: '1234567890' + U_20AC + '1' }); byteLimitTest({ @@ -149,7 +150,7 @@ }) .byteLimit( 12 ), sample: mbSample, - useLimit: true, + hasLimit: true, limit: 12, - expected: 12 // 10 x 1-byte char. The next 3-byte char exceeds limit of 12, but 2 more 1-byte chars come in after. + expected: '1234567890' + '12' }); _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs