Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.byteLimit.js |
— | — | @@ -23,45 +23,46 @@ |
24 | 24 | } |
25 | 25 | } |
26 | 26 | }; |
27 | | -var blti = 0; |
| 27 | + |
28 | 28 | /** |
29 | 29 | * Test factory for $.fn.byteLimit |
30 | 30 | * |
31 | 31 | * @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 |
33 | 33 | * @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) |
35 | 35 | */ |
36 | 36 | var byteLimitTest = function( options ) { |
37 | 37 | var opt = $.extend({ |
38 | 38 | description: '', |
39 | 39 | $input: null, |
40 | 40 | sample: '', |
41 | | - useLimit: false, |
42 | | - expected: 0, |
| 41 | + hasLimit: false, |
| 42 | + expected: '', |
43 | 43 | limit: null |
44 | 44 | }, options); |
45 | | - var i = blti++; |
46 | 45 | |
47 | 46 | test( opt.description, function() { |
48 | 47 | |
49 | 48 | opt.$input.appendTo( 'body' ); |
50 | | - |
| 49 | + |
51 | 50 | // Simulate pressing keys for each of the sample characters |
52 | 51 | $.addChars( opt.$input, opt.sample ); |
53 | 52 | var newVal = opt.$input.val(); |
54 | | - |
55 | | - if ( opt.useLimit ) { |
56 | | - expect(2); |
57 | | - |
| 53 | + |
| 54 | + if ( opt.hasLimit ) { |
| 55 | + expect(3); |
| 56 | + |
58 | 57 | 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 | + |
61 | 61 | } 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' ); |
64 | 65 | } |
65 | | - |
| 66 | + |
66 | 67 | opt.$input.remove(); |
67 | 68 | } ); |
68 | 69 | }; |
— | — | @@ -83,8 +84,8 @@ |
84 | 85 | 'type': 'text' |
85 | 86 | }), |
86 | 87 | sample: simpleSample, |
87 | | - useLimit: false, |
88 | | - expected: $.byteLength( simpleSample ) |
| 88 | + hasLimit: false, |
| 89 | + expected: simpleSample |
89 | 90 | }); |
90 | 91 | |
91 | 92 | byteLimitTest({ |
— | — | @@ -96,9 +97,9 @@ |
97 | 98 | }) |
98 | 99 | .byteLimit(), |
99 | 100 | sample: simpleSample, |
100 | | - useLimit: true, |
| 101 | + hasLimit: true, |
101 | 102 | limit: 10, |
102 | | - expected: 10 |
| 103 | + expected: '1234567890' |
103 | 104 | }); |
104 | 105 | |
105 | 106 | byteLimitTest({ |
— | — | @@ -109,9 +110,9 @@ |
110 | 111 | }) |
111 | 112 | .byteLimit( 10 ), |
112 | 113 | sample: simpleSample, |
113 | | - useLimit: true, |
| 114 | + hasLimit: true, |
114 | 115 | limit: 10, |
115 | | - expected: 10 |
| 116 | + expected: '1234567890' |
116 | 117 | }); |
117 | 118 | |
118 | 119 | byteLimitTest({ |
— | — | @@ -123,9 +124,9 @@ |
124 | 125 | }) |
125 | 126 | .byteLimit( 15 ), |
126 | 127 | sample: simpleSample, |
127 | | - useLimit: true, |
| 128 | + hasLimit: true, |
128 | 129 | limit: 15, |
129 | | - expected: 15 |
| 130 | + expected: '123456789012345' |
130 | 131 | }); |
131 | 132 | |
132 | 133 | byteLimitTest({ |
— | — | @@ -136,9 +137,9 @@ |
137 | 138 | }) |
138 | 139 | .byteLimit( 14 ), |
139 | 140 | sample: mbSample, |
140 | | - useLimit: true, |
| 141 | + hasLimit: true, |
141 | 142 | 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' |
143 | 144 | }); |
144 | 145 | |
145 | 146 | byteLimitTest({ |
— | — | @@ -149,7 +150,7 @@ |
150 | 151 | }) |
151 | 152 | .byteLimit( 12 ), |
152 | 153 | sample: mbSample, |
153 | | - useLimit: true, |
| 154 | + hasLimit: true, |
154 | 155 | 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' |
156 | 157 | }); |