@@ -5,23 +5,43 @@ suite('EditorLineRangeExtractor', () => {
55
66 test ( 'it extracts the line range of text selection' , ( ) => {
77 const extractor = new EditorLineRangeExtractor ( ) ;
8- const editor = fakeEditor ( 'SELECTED_TEXT' ) ;
9- expect ( extractor . extract ( editor ) ) . to . eql ( { start : 'START_LINE ' , end : 'END_LINE' } ) ;
8+ const editor = fakeEditor ( [ 'SELECTED_TEXT' ] ) ;
9+ expect ( extractor . extract ( editor ) ) . to . eql ( [ { start : 'START_LINE_1 ' , end : 'END_LINE_1' } ] ) ;
1010 } ) ;
1111
1212 test ( 'it returns null if no text is selected' , ( ) => {
1313 const extractor = new EditorLineRangeExtractor ( ) ;
14- const editor = fakeEditor ( '' ) ;
15- expect ( extractor . extract ( editor ) ) . to . eql ( null ) ;
14+ const editor = fakeEditor ( [ '' ] ) ;
15+ expect ( extractor . extract ( editor ) ) . to . eql ( [ ] ) ;
1616 } ) ;
1717
18- function fakeEditor ( selectedText ) {
18+ test ( 'it extracts all the line ranges of text selections' , ( ) => {
19+ const extractor = new EditorLineRangeExtractor ( ) ;
20+ const editor = fakeEditor ( [ 'SELECTED_TEXT_1' , 'SELECTED_TEXT_2' ] ) ;
21+ expect ( extractor . extract ( editor ) ) . to . eql ( [
22+ { start : 'START_LINE_1' , end : 'END_LINE_1' } ,
23+ { start : 'START_LINE_2' , end : 'END_LINE_2' }
24+ ] ) ;
25+ } ) ;
26+
27+ test ( 'it skips all cursors that are not selecting any text' , ( ) => {
28+ const extractor = new EditorLineRangeExtractor ( ) ;
29+ const editor = fakeEditor ( [ 'SELECTED_TEXT_1' , '' , 'SELECTED_TEXT_3' ] ) ;
30+ expect ( extractor . extract ( editor ) ) . to . eql ( [
31+ { start : 'START_LINE_1' , end : 'END_LINE_1' } ,
32+ { start : 'START_LINE_3' , end : 'END_LINE_3' }
33+ ] ) ;
34+ } ) ;
35+
36+ function fakeEditor ( selectedTexts ) {
37+ const selections = selectedTexts . map ( ( text , i ) => ( {
38+ start : { line : `START_LINE_${ i + 1 } ` } ,
39+ end : { line : `END_LINE_${ i + 1 } ` } ,
40+ isEmpty : ! text
41+ } ) ) ;
1942 return {
20- selection : {
21- start : { line : 'START_LINE' } ,
22- end : { line : 'END_LINE' } ,
23- isEmpty : ! selectedText
24- }
43+ selections,
44+ selection : selections [ 0 ]
2545 } ;
2646 }
2747} ) ;
0 commit comments