5b3c2ed08b6fcd8a051c4ae5c0fe8ceea82b1cea
15 regex
: /^(\s*)(={1,6})(.*?)\2(\s*)$/,
16 regexReplace
: '$1==$3==$4',
21 peri
: 'Bulleted list item',
27 QUnit
.module( 'jquery.textSelection', QUnit
.newMwEnvironment() );
30 * Test factory for $.fn.textSelection( 'encapsulateText' )
32 * @param {Object} options Associative configuration array
33 * @param {string} options.description Description
34 * @param {string} options.input Input
35 * @param {string} options.output Output
36 * @param {int} options.start Starting char for selection
37 * @param {int} options.end Ending char for selection
38 * @param {Object} options.params Additional parameters for $().textSelection( 'encapsulateText' )
40 function encapsulateTest( options
) {
48 opt
.before
= $.extend( {
53 opt
.after
= $.extend( {
58 QUnit
.test( opt
.description
, function ( assert
) {
59 var $textarea
, start
, end
, options
, text
, selected
;
61 $textarea
= $( '<textarea>' );
63 $( '#qunit-fixture' ).append( $textarea
);
65 $textarea
.textSelection( 'setContents', opt
.before
.text
);
67 start
= opt
.before
.start
;
71 options
= $.extend( {}, opt
.replace
);
72 options
.selectionStart
= start
;
73 options
.selectionEnd
= end
;
74 $textarea
.textSelection( 'encapsulateSelection', options
);
76 text
= $textarea
.textSelection( 'getContents' ).replace( /\r\n/g, '\n' );
78 assert
.equal( text
, opt
.after
.text
, 'Checking full text after encapsulation' );
80 if ( opt
.after
.selected
!== null ) {
81 selected
= $textarea
.textSelection( 'getSelection' );
82 assert
.equal( selected
, opt
.after
.selected
, 'Checking selected text after encapsulation.' );
89 description
: 'Adding sig to end of text',
91 text
: 'Wikilove dude! ',
96 text
: 'Wikilove dude! --~~~~',
103 description
: 'Adding bold to empty',
110 text
: '\'\'\'Bold text\'\'\'',
111 selected
: 'Bold text' // selected because it's the default
117 description
: 'Adding bold to existing text',
119 text
: 'Now is the time for all good men to come to the aid of their country',
124 text
: 'Now is the time for \'\'\'all good men\'\'\' to come to the aid of their country',
125 selected
: '' // empty because it's not the default'
131 description
: 'ownline option: adding new h2',
133 text
: 'Before\nAfter',
138 text
: 'Before\n== Heading 2 ==\nAfter',
139 selected
: 'Heading 2'
145 description
: 'ownline option: turn a whole line into new h2',
147 text
: 'Before\nMy heading\nAfter',
152 text
: 'Before\n== My heading ==\nAfter',
159 description
: 'ownline option: turn a partial line into new h2',
161 text
: 'BeforeMy headingAfter',
166 text
: 'Before\n== My heading ==\nAfter',
173 description
: 'splitlines option: no selection, insert new list item',
175 text
: 'Before\nAfter',
180 text
: 'Before\n* Bulleted list item\nAfter'
186 description
: 'splitlines option: single partial line selection, insert new list item',
188 text
: 'BeforeMy List ItemAfter',
193 text
: 'Before\n* My List Item\nAfter'
199 description
: 'splitlines option: multiple lines',
201 text
: 'Before\nFirst\nSecond\nThird\nAfter',
206 text
: 'Before\n* First\n* Second\n* Third\nAfter'
211 function caretTest( options
) {
212 QUnit
.test( options
.description
, function ( assert
) {
214 $textarea
= $( '<textarea>' ).text( options
.text
);
216 $( '#qunit-fixture' ).append( $textarea
);
218 if ( options
.mode
=== 'set' ) {
219 $textarea
.textSelection( 'setSelection', {
220 start
: options
.start
,
225 function among( actual
, expected
, message
) {
226 if ( Array
.isArray( expected
) ) {
227 assert
.ok( $.inArray( actual
, expected
) !== -1, message
+ ' (got ' + actual
+ '; expected one of ' + expected
.join( ', ' ) + ')' );
229 assert
.equal( actual
, expected
, message
);
233 pos
= $textarea
.textSelection( 'getCaretPosition', { startAndEnd
: true } );
234 among( pos
[ 0 ], options
.start
, 'Caret start should be where we set it.' );
235 among( pos
[ 1 ], options
.end
, 'Caret end should be where we set it.' );
239 caretSample
= 'Some big text that we like to work with. Nothing fancy... you know what I mean?';
241 /* @broken: Disabled per T36820
243 description: 'getCaretPosition with original/empty selection - T33847 with IE 6/7/8',
245 start: [0, caretSample.length], // Opera and Firefox (prior to FF 6.0) default caret to the end of the box (caretSample.length)
246 end: [0, caretSample.length], // Other browsers default it to the beginning (0), so check both.
252 description
: 'set/getCaretPosition with forced empty selection',
260 description
: 'set/getCaretPosition with small selection',