r94054 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94053‎ | r94054 | r94055 >
Date:11:11, 8 August 2011
Author:krinkle
Status:ok
Tags:
Comment:
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) (history)

Diff [purge]

Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.byteLimit.js
@@ -23,45 +23,46 @@
2424 }
2525 }
2626 };
27 -var blti = 0;
 27+
2828 /**
2929 * Test factory for $.fn.byteLimit
3030 *
3131 * @param $input {jQuery} jQuery object in an input element
32 - * @param useLimit {Boolean} Wether a limit should apply at all
 32+ * @param hasLimit {Boolean} Wether a limit should apply at all
3333 * @param limit {Number} Limit (if used) otherwise undefined
34 - * The limit should be less than 20 (the sample data's length)
 34+ * The limit should be less than 20 (the sample data's length)
3535 */
3636 var byteLimitTest = function( options ) {
3737 var opt = $.extend({
3838 description: '',
3939 $input: null,
4040 sample: '',
41 - useLimit: false,
42 - expected: 0,
 41+ hasLimit: false,
 42+ expected: '',
4343 limit: null
4444 }, options);
45 - var i = blti++;
4645
4746 test( opt.description, function() {
4847
4948 opt.$input.appendTo( 'body' );
50 -
 49+
5150 // Simulate pressing keys for each of the sample characters
5251 $.addChars( opt.$input, opt.sample );
5352 var newVal = opt.$input.val();
54 -
55 - if ( opt.useLimit ) {
56 - expect(2);
57 -
 53+
 54+ if ( opt.hasLimit ) {
 55+ expect(3);
 56+
5857 ltOrEq( $.byteLength( newVal ), opt.limit, 'Prevent keypresses after byteLimit was reached, length never exceeded the limit' );
59 - equal( $.byteLength( newVal ), opt.expected, 'Not preventing keypresses too early, length has reached the expected length' );
60 -
 58+ equal( $.byteLength( newVal ), $.byteLength( opt.expected ), 'Not preventing keypresses too early, length has reached the expected length' );
 59+ equal( newVal, opt.expected, 'New value matches the expected string' );
 60+
6161 } else {
62 - expect(1);
63 - equal( $.byteLength( newVal ), opt.expected, 'Unlimited scenarios are not affected, expected length reached' );
 62+ expect(2);
 63+ equal( newVal, opt.expected, 'New value matches the expected string' );
 64+ equal( $.byteLength( newVal ), $.byteLength( opt.expected ), 'Unlimited scenarios are not affected, expected length reached' );
6465 }
65 -
 66+
6667 opt.$input.remove();
6768 } );
6869 };
@@ -83,8 +84,8 @@
8485 'type': 'text'
8586 }),
8687 sample: simpleSample,
87 - useLimit: false,
88 - expected: $.byteLength( simpleSample )
 88+ hasLimit: false,
 89+ expected: simpleSample
8990 });
9091
9192 byteLimitTest({
@@ -96,9 +97,9 @@
9798 })
9899 .byteLimit(),
99100 sample: simpleSample,
100 - useLimit: true,
 101+ hasLimit: true,
101102 limit: 10,
102 - expected: 10
 103+ expected: '1234567890'
103104 });
104105
105106 byteLimitTest({
@@ -109,9 +110,9 @@
110111 })
111112 .byteLimit( 10 ),
112113 sample: simpleSample,
113 - useLimit: true,
 114+ hasLimit: true,
114115 limit: 10,
115 - expected: 10
 116+ expected: '1234567890'
116117 });
117118
118119 byteLimitTest({
@@ -123,9 +124,9 @@
124125 })
125126 .byteLimit( 15 ),
126127 sample: simpleSample,
127 - useLimit: true,
 128+ hasLimit: true,
128129 limit: 15,
129 - expected: 15
 130+ expected: '123456789012345'
130131 });
131132
132133 byteLimitTest({
@@ -136,9 +137,9 @@
137138 })
138139 .byteLimit( 14 ),
139140 sample: mbSample,
140 - useLimit: true,
 141+ hasLimit: true,
141142 limit: 14,
142 - expected: 14 // (10 x 1-byte char) + (1 x 3-byte char) + (1 x 1-byte char)
 143+ expected: '1234567890' + U_20AC + '1'
143144 });
144145
145146 byteLimitTest({
@@ -149,7 +150,7 @@
150151 })
151152 .byteLimit( 12 ),
152153 sample: mbSample,
153 - useLimit: true,
 154+ hasLimit: true,
154155 limit: 12,
155 - 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.
 156+ expected: '1234567890' + '12'
156157 });

Status & tagging log