@@ -5,25 +5,42 @@ suite('EditorTextExtractor', () => {
55
66 test ( 'it extracts a text from editor for comparison' , ( ) => {
77 const extractor = new EditorTextExtractor ( ) ;
8- const editor = fakeEditor ( 'SELECTED_TEXT' ) ;
8+ const editor = fakeEditor ( [ 'SELECTED_TEXT' ] ) ;
99 expect ( extractor . extract ( editor ) ) . to . eql ( 'SELECTED_TEXT' ) ;
1010 } ) ;
1111
1212 test ( 'it extracts a whole text if no text is currently selected' , ( ) => {
1313 const extractor = new EditorTextExtractor ( ) ;
14- const editor = fakeEditor ( '' ) ;
15- expect ( extractor . extract ( editor ) ) . to . eql ( 'ENTIRE TEXT ' ) ;
14+ const editor = fakeEditor ( [ '' ] ) ;
15+ expect ( extractor . extract ( editor ) ) . to . eql ( 'ENTIRE TEXT' ) ;
1616 } ) ;
1717
18- function fakeEditor ( selectedText ) {
18+ test ( 'it extracts texts selected by all cursors and join them with newline character' , ( ) => {
19+ const extractor = new EditorTextExtractor ( ) ;
20+ const editor = fakeEditor ( [ 'SELECTED_TEXT_1' , 'SELECTED_TEXT_2' ] ) ;
21+ expect ( extractor . extract ( editor ) ) . to . eql ( 'SELECTED_TEXT_1\nSELECTED_TEXT_2' ) ;
22+ } ) ;
23+
24+ test ( 'it ignores cursor that is not selecting text if others are selecting one' , ( ) => {
25+ const extractor = new EditorTextExtractor ( ) ;
26+ const editor = fakeEditor ( [ '' , 'SELECTED_TEXT_1' , '' , 'SELECTED_TEXT_2' ] ) ;
27+ expect ( extractor . extract ( editor ) ) . to . eql ( 'SELECTED_TEXT_1\nSELECTED_TEXT_2' ) ;
28+ } ) ;
29+
30+ test ( 'it extracts the whole text if no cursors are selecting text' , ( ) => {
31+ const extractor = new EditorTextExtractor ( ) ;
32+ const editor = fakeEditor ( [ '' , '' , '' ] ) ;
33+ expect ( extractor . extract ( editor ) ) . to . eql ( 'ENTIRE TEXT' ) ;
34+ } ) ;
35+
36+ function fakeEditor ( selectedTexts ) {
37+ const selections = selectedTexts . map ( text => ( { text, isEmpty : ! text } ) ) ;
1938 return {
20- selection : {
21- text : selectedText ,
22- isEmpty : ! selectedText
23- } ,
39+ selections,
40+ selection : selections [ 0 ] ,
2441 document : {
25- _entireText : ` ENTIRE TEXT ${ selectedText } ` ,
26- getText : function ( selection ) {
42+ _entireText : ' ENTIRE TEXT' ,
43+ getText ( selection ) {
2744 return selection ? selection . text : this . _entireText ;
2845 }
2946 }
0 commit comments