@@ -87,18 +87,27 @@ describe('VirtualDocument', () => {
87
87
let cm_editor_for_cell_2 = { } as CodeMirror . Editor ;
88
88
let cm_editor_for_cell_3 = { } as CodeMirror . Editor ;
89
89
let cm_editor_for_cell_4 = { } as CodeMirror . Editor ;
90
+ // first block
90
91
document . append_code_block (
91
92
'test line in Python 1\n%R 1st test line in R line magic 1' ,
92
93
cm_editor_for_cell_1
93
94
) ;
95
+ // second block
94
96
document . append_code_block (
95
97
'test line in Python 2\n%R 1st test line in R line magic 2' ,
96
98
cm_editor_for_cell_2
97
99
) ;
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
98
106
document . append_code_block (
99
107
'%%R\n1st test line in R cell magic 1' ,
100
108
cm_editor_for_cell_3
101
109
) ;
110
+ // fifth block
102
111
document . append_code_block (
103
112
'%%R -i imported_variable\n1st test line in R cell magic 2' ,
104
113
cm_editor_for_cell_4
@@ -135,11 +144,15 @@ describe('VirtualDocument', () => {
135
144
expect ( foreign_document . value ) . to . equal (
136
145
'1st test line in R line magic 1\n\n\n' +
137
146
'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
138
149
'1st test line in R cell magic 1\n\n\n' +
139
150
'imported_variable <- data.frame(); 1st test line in R cell magic 2\n'
151
+ // 0123456789012345678901234567890123456 - 's' is 36th
140
152
) ;
141
153
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)
143
156
let virtual_r_1_1 = {
144
157
line : 0 ,
145
158
ch : 1
@@ -157,13 +170,41 @@ describe('VirtualDocument', () => {
157
170
expect ( editor_position . line ) . to . equal ( 1 ) ;
158
171
expect ( editor_position . ch ) . to . equal ( 4 ) ;
159
172
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)
161
175
editor_position = foreign_document . transform_virtual_to_editor ( {
162
176
line : 3 ,
163
177
ch : 0
164
178
} as IVirtualPosition ) ;
179
+ // 0th editor line is 'test line in Python 2\n'
165
180
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
166
183
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 ) ;
167
208
} ) ;
168
209
} ) ;
169
210
} ) ;
0 commit comments