@@ -348,7 +348,7 @@ test('Pasting with leading static pattern in selection', function(t) {
348348} )
349349
350350test ( 'Setting selection' , function ( t ) {
351- t . plan ( 8 )
351+ t . plan ( 16 )
352352
353353 var mask = new InputMask ( { pattern : '----- [[11 1111 ]]-' } )
354354 t . equal ( mask . pattern . firstEditableIndex , 8 , 'First editable index calculation' )
@@ -358,10 +358,24 @@ test('Setting selection', function(t) {
358358 t . deepEqual ( mask . selection , { start : 8 , end : 8 } , 'Cursor placed at first editable character' )
359359 // ...or beyond the last editable character
360360 t . true ( mask . setSelection ( { start : 18 , end : 18 } ) , 'Cursor after editable region is changed' )
361- t . deepEqual ( mask . selection , { start : 15 , end : 15 } , 'Cursor placed after last editable character' )
361+ t . deepEqual ( mask . selection , { start : 8 , end : 8 } , 'Cursor placed after last editable character' )
362362 // ...however a selection can span beyond the editable region
363363 t . false ( mask . setSelection ( { start : 0 , end : 19 } ) , 'Selection beyond editable region not changed' )
364364 t . deepEqual ( mask . selection , { start : 0 , end : 19 } , 'Whole value can be selected' )
365+
366+ var mask = new InputMask ( { pattern : '----- [[11 1111 ]]-' , value : '23 45' } )
367+ // Setting the selection before the first editable index moves selection to first editable index
368+ t . true ( mask . setSelection ( { start : 0 , end : 0 } ) , 'Cursor before editable region, regardless of value, is changed' )
369+ t . deepEqual ( mask . selection , { start : 8 , end : 8 } , 'Cursor placed at first editable character, regardless of value' )
370+ // Setting the selection within the value works as expected
371+ t . true ( mask . setSelection ( { start : 9 , end : 9 } ) , 'Cursor within value is not changed' )
372+ t . deepEqual ( mask . selection , { start : 9 , end : 9 } , 'Cursor stays within value' )
373+ // Setting the selection after the last editable index moves selection to the next editable index after the last value
374+ t . true ( mask . setSelection ( { start : 18 , end : 18 } ) , 'Cursor after editable region is changed, regardless of value' )
375+ t . deepEqual ( mask . selection , { start : 14 , end : 14 } , 'Cursor placed at first editable character after last value' )
376+ // Setting the selection after (but not within) a value moves selection to the next editable index after the previous value
377+ t . true ( mask . setSelection ( { start : 11 , end : 11 } ) , 'Cursor after editable region with values both before and after it is changed' )
378+ t . deepEqual ( mask . selection , { start : 10 , end : 10 } , 'Cursor placed at first editable character after prior value' )
365379} )
366380
367381test ( 'History' , function ( t ) {
0 commit comments