@@ -87,18 +87,27 @@ describe('VirtualDocument', () => {
8787 let cm_editor_for_cell_2 = { } as CodeMirror . Editor ;
8888 let cm_editor_for_cell_3 = { } as CodeMirror . Editor ;
8989 let cm_editor_for_cell_4 = { } as CodeMirror . Editor ;
90+ // first block
9091 document . append_code_block (
9192 'test line in Python 1\n%R 1st test line in R line magic 1' ,
9293 cm_editor_for_cell_1
9394 ) ;
95+ // second block
9496 document . append_code_block (
9597 'test line in Python 2\n%R 1st test line in R line magic 2' ,
9698 cm_editor_for_cell_2
9799 ) ;
100+ // third block
101+ document . append_code_block (
102+ 'test line in Python 3\n%R -i imported_variable 1st test line in R line magic 3' ,
103+ cm_editor_for_cell_2
104+ ) ;
105+ // fourth block
98106 document . append_code_block (
99107 '%%R\n1st test line in R cell magic 1' ,
100108 cm_editor_for_cell_3
101109 ) ;
110+ // fifth block
102111 document . append_code_block (
103112 '%%R -i imported_variable\n1st test line in R cell magic 2' ,
104113 cm_editor_for_cell_4
@@ -135,11 +144,15 @@ describe('VirtualDocument', () => {
135144 expect ( foreign_document . value ) . to . equal (
136145 '1st test line in R line magic 1\n\n\n' +
137146 '1st test line in R line magic 2\n\n\n' +
147+ 'imported_variable <- data.frame(); 1st test line in R line magic 3\n\n\n' +
148+ // 23456789012345678901234567890123456 - 's' is 36th
138149 '1st test line in R cell magic 1\n\n\n' +
139150 'imported_variable <- data.frame(); 1st test line in R cell magic 2\n'
151+ // 0123456789012345678901234567890123456 - 's' is 36th
140152 ) ;
141153
142- // The second (R) line in the first block ("s" in "1st", "1st" in "1st test line in R line magic")
154+ // The first R line (in source); second in the first block;
155+ // targeting "s" in "1st", "1st" in "1st test line in R line magic" (first virtual line == line 0)
143156 let virtual_r_1_1 = {
144157 line : 0 ,
145158 ch : 1
@@ -157,13 +170,41 @@ describe('VirtualDocument', () => {
157170 expect ( editor_position . line ) . to . equal ( 1 ) ;
158171 expect ( editor_position . ch ) . to . equal ( 4 ) ;
159172
160- // The second (R) line in the second block
173+ // The second R line (in source), second in the second block
174+ // targeting 1 in "1st test line in R line magic 2" (4th virtual line == line 3)
161175 editor_position = foreign_document . transform_virtual_to_editor ( {
162176 line : 3 ,
163177 ch : 0
164178 } as IVirtualPosition ) ;
179+ // 0th editor line is 'test line in Python 2\n'
165180 expect ( editor_position . line ) . to . equal ( 1 ) ;
181+ // 1st editor lines is '%R 1st test line in R line magic 2'
182+ // 0123 - 3rd character
166183 expect ( editor_position . ch ) . to . equal ( 3 ) ;
184+
185+ // The third R line (in source), second in the third block;
186+ // targeting "s" in "1st" in "1st test line in R line magic 3" (7th virtual line == line 6)
187+ editor_position = foreign_document . transform_virtual_to_editor ( {
188+ line : 6 ,
189+ ch : 36
190+ } as IVirtualPosition ) ;
191+ // 0th editor line is 'test line in Python 3\n'
192+ expect ( editor_position . line ) . to . equal ( 1 ) ;
193+ // 1st editor line is '%R -i imported_variable 1st test line in R line magic 3'
194+ // 01234567890123456789012345 - 25th character
195+ expect ( editor_position . ch ) . to . equal ( 25 ) ;
196+
197+ // The fifth R line (in source), second in the fifth block;
198+ // targeting "s" in "1st" in "1st test line in R cell magic 2" (13th virtual lines == line 12)
199+ editor_position = foreign_document . transform_virtual_to_editor ( {
200+ line : 12 ,
201+ ch : 36
202+ } as IVirtualPosition ) ;
203+ // 0th editor line is '%%R -i imported_variable\n'
204+ expect ( editor_position . line ) . to . equal ( 1 ) ;
205+ // 1st editor line is '1st test line in R cell magic 2'
206+ // 01
207+ expect ( editor_position . ch ) . to . equal ( 1 ) ;
167208 } ) ;
168209 } ) ;
169210} ) ;
0 commit comments