+ byteLimitTest({
+ description: 'Plain text input',
+ $input: $( '<input>' )
+ .attr( 'type', 'text' ),
+ sample: simpleSample,
+ hasLimit: false,
+ expected: simpleSample
+ });
+
+ byteLimitTest({
+ description: 'Limit using the maxlength attribute',
+ $input: $( '<input>' )
+ .attr( 'type', 'text' )
+ .prop( 'maxLength', '10' )
+ .byteLimit(),
+ sample: simpleSample,
+ hasLimit: true,
+ limit: 10,
+ expected: '1234567890'
+ });
+
+ byteLimitTest({
+ description: 'Limit using a custom value',
+ $input: $( '<input>' )
+ .attr( 'type', 'text' )
+ .byteLimit( 10 ),
+ sample: simpleSample,
+ hasLimit: true,
+ limit: 10,
+ expected: '1234567890'
+ });
+
+ byteLimitTest({
+ description: 'Limit using a custom value, overriding maxlength attribute',
+ $input: $( '<input>' )
+ .attr( 'type', 'text' )
+ .prop( 'maxLength', '10' )
+ .byteLimit( 15 ),
+ sample: simpleSample,
+ hasLimit: true,
+ limit: 15,
+ expected: '123456789012345'
+ });
+
+ byteLimitTest({
+ description: 'Limit using a custom value (multibyte)',
+ $input: $( '<input>' )
+ .attr( 'type', 'text' )
+ .byteLimit( 14 ),
+ sample: mbSample,
+ hasLimit: true,
+ limit: 14,
+ expected: '1234567890' + U_20AC + '1'
+ });
+
+ byteLimitTest({
+ description: 'Limit using a custom value (multibyte) overlapping a byte',
+ $input: $( '<input>' )
+ .attr( 'type', 'text' )
+ .byteLimit( 12 ),
+ sample: mbSample,
+ hasLimit: true,
+ limit: 12,
+ expected: '1234567890' + '12'
+ });
+
+ byteLimitTest({
+ description: 'Pass the limit and a callback as input filter',
+ $input: $( '<input>' )
+ .attr( 'type', 'text' )
+ .byteLimit( 6, function ( val ) {
+ // Invalid title
+ if ( val === '' ) {
+ return '';
+ }
+
+ // Return without namespace prefix
+ return new mw.Title( String( val ) ).getMain();
+ } ),
+ sample: 'User:Sample',
+ hasLimit: true,
+ limit: 6, // 'Sample' length
+ expected: 'User:Sample'
+ });
+
+ byteLimitTest({
+ description: 'Limit using the maxlength attribute and pass a callback as input filter',
+ $input: $( '<input>' )
+ .attr( 'type', 'text' )
+ .prop( 'maxLength', '6' )
+ .byteLimit( function ( val ) {
+ // Invalid title
+ if ( val === '' ) {
+ return '';
+ }
+
+ // Return without namespace prefix
+ return new mw.Title( String( val ) ).getMain();
+ } ),
+ sample: 'User:Sample',
+ hasLimit: true,
+ limit: 6, // 'Sample' length
+ expected: 'User:Sample'
+ });
+
+}( jQuery ) );
\ No newline at end of file