@@ -114,158 +114,91 @@ and grew 1cm per day`;
114114 var checkText : string ;
115115 var insertString : string ;
116116
117- it ( 'Case VII: insert at end of file' , ( ) => {
118- insertString = "hmmmm...\r\n" ;
119- checkText = editFlat ( content . length , 0 , insertString , content ) ;
120- snapshot = lineIndex . edit ( content . length , 0 , insertString ) ;
121- editedText = snapshot . getText ( 0 , checkText . length ) ;
117+ function testEdit ( position : number , deleteLength : number , insertString : string ) : void {
118+ var checkText = editFlat ( position , deleteLength , insertString , content ) ;
119+ snapshot = lineIndex . edit ( position , deleteLength , insertString ) ;
120+ var editedText = snapshot . getText ( 0 , snapshot . getLength ( ) ) ;
122121
123122 assert . equal ( editedText , checkText ) ;
123+ }
124+
125+ it ( 'Case VII: insert at end of file' , ( ) => {
126+ insertString = "hmmmm...\r\n" ;
127+ testEdit ( content . length , 0 , insertString ) ;
124128 } ) ;
125129
126130 it ( 'Case IV: unusual line endings merge' , ( ) => {
127- snapshot = lineIndex . edit ( lines [ 0 ] . length - 1 , lines [ 1 ] . length , "" ) ;
128- editedText = snapshot . getText ( 0 , content . length - lines [ 1 ] . length ) ;
129- checkText = editFlat ( lines [ 0 ] . length - 1 , lines [ 1 ] . length , "" , content ) ;
130-
131- assert . equal ( editedText , checkText ) ;
131+ testEdit ( lines [ 0 ] . length - 1 , lines [ 1 ] . length , "" ) ;
132132 } ) ;
133133
134134 it ( 'Case VIIa: delete whole line and nothing but line (last line)' , ( ) => {
135135 var llpos = lineMap [ lineMap . length - 2 ] ;
136- snapshot = lineIndex . edit ( llpos , lines [ lines . length - 1 ] . length , "" ) ;
137- checkText = editFlat ( llpos , lines [ lines . length - 1 ] . length , "" , content ) ;
138- editedText = snapshot . getText ( 0 , checkText . length ) ;
139-
140- assert . equal ( editedText , checkText ) ;
136+ testEdit ( llpos , lines [ lines . length - 1 ] . length , "" ) ;
141137 } ) ;
142138
143139 it ( 'Case VIIb: delete whole line and nothing but line (first line)' , ( ) => {
144- snapshot = lineIndex . edit ( 0 , lines [ 0 ] . length , "" ) ;
145- editedText = snapshot . getText ( 0 , content . length - lines [ 0 ] . length ) ;
146- checkText = editFlat ( 0 , lines [ 0 ] . length , "" , content ) ;
147-
148- assert . equal ( editedText , checkText ) ;
140+ testEdit ( 0 , lines [ 0 ] . length , "" ) ;
149141 } ) ;
150142
151143 it ( 'Case VIIc: delete whole line (first line) and insert with no line breaks' , ( ) => {
152144 insertString = "moo, moo, moo! " ;
153- snapshot = lineIndex . edit ( 0 , lines [ 0 ] . length , insertString ) ;
154- editedText = snapshot . getText ( 0 , content . length - lines [ 0 ] . length + insertString . length ) ;
155- checkText = editFlat ( 0 , lines [ 0 ] . length , insertString , content ) ;
156-
157- assert . equal ( editedText , checkText ) ;
145+ testEdit ( 0 , lines [ 0 ] . length , insertString ) ;
158146 } ) ;
159147
160148 it ( 'Case VIIc: delete whole line (first line) and insert with multiple line breaks' , ( ) => {
161149 insertString = "moo, \r\nmoo, \r\nmoo! " ;
162- snapshot = lineIndex . edit ( 0 , lines [ 0 ] . length , insertString ) ;
163- editedText = snapshot . getText ( 0 , content . length - lines [ 0 ] . length + insertString . length ) ;
164- checkText = editFlat ( 0 , lines [ 0 ] . length , insertString , content ) ;
165-
166- assert . equal ( editedText , checkText ) ;
150+ testEdit ( 0 , lines [ 0 ] . length , insertString ) ;
167151 } ) ;
168152
169153 it ( 'Case VIId: delete multiple lines and nothing but lines (first and second lines)' , ( ) => {
170- snapshot = lineIndex . edit ( 0 , lines [ 0 ] . length + lines [ 1 ] . length , "" ) ;
171- editedText = snapshot . getText ( 0 , content . length - ( lines [ 0 ] . length + lines [ 1 ] . length ) ) ;
172- checkText = editFlat ( 0 , lines [ 0 ] . length + lines [ 1 ] . length , "" , content ) ;
173-
174- assert . equal ( editedText , checkText ) ;
154+ testEdit ( 0 , lines [ 0 ] . length + lines [ 1 ] . length , "" ) ;
175155 } ) ;
176156
177157 it ( 'Case VIIe: delete multiple lines and nothing but lines (second and third lines)' , ( ) => {
178- snapshot = lineIndex . edit ( lines [ 0 ] . length , lines [ 1 ] . length + lines [ 2 ] . length , "" ) ;
179-
180- editedText = snapshot . getText ( 0 , content . length - ( lines [ 1 ] . length + lines [ 2 ] . length ) ) ;
181- checkText = editFlat ( lines [ 0 ] . length , lines [ 1 ] . length + lines [ 2 ] . length , "" , content ) ;
182-
183- assert . equal ( editedText , checkText ) ;
158+ testEdit ( lines [ 0 ] . length , lines [ 1 ] . length + lines [ 2 ] . length , "" ) ;
184159 } ) ;
185160
186161 it ( 'Case VI: insert multiple line breaks' , ( ) => {
187162 insertString = "cr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr...\r\ncr" ;
188- snapshot = lineIndex . edit ( 21 , 1 , insertString ) ;
189- editedText = snapshot . getText ( 0 , content . length + insertString . length - 1 ) ;
190- checkText = editFlat ( 21 , 1 , insertString , content ) ;
191-
192- assert . equal ( editedText , checkText ) ;
163+ testEdit ( 21 , 1 , insertString ) ;
193164 } ) ;
194165
195166 it ( 'Case VIb: insert multiple line breaks' , ( ) => {
196-
197167 insertString = "cr...\r\ncr...\r\ncr" ;
198- snapshot = lineIndex . edit ( 21 , 1 , insertString ) ;
199- editedText = snapshot . getText ( 0 , content . length + insertString . length - 1 ) ;
200- checkText = editFlat ( 21 , 1 , insertString , content ) ;
201-
202- assert . equal ( editedText , checkText ) ;
168+ testEdit ( 21 , 1 , insertString ) ;
203169 } ) ;
204170
205171 it ( 'Case VIc: insert multiple line breaks with leading \\n' , ( ) => {
206172 insertString = "\ncr...\r\ncr...\r\ncr" ;
207- snapshot = lineIndex . edit ( 21 , 1 , insertString ) ;
208- editedText = snapshot . getText ( 0 , content . length + insertString . length - 1 ) ;
209- checkText = editFlat ( 21 , 1 , insertString , content ) ;
210-
211- assert . equal ( editedText , checkText ) ;
173+ testEdit ( 21 , 1 , insertString ) ;
212174 } ) ;
213175
214176 it ( 'Case I: single line no line breaks deleted or inserted, delete 1 char' , ( ) => {
215- snapshot = lineIndex . edit ( 21 , 1 ) ;
216- editedText = snapshot . getText ( 0 , content . length - 1 ) ;
217- checkText = editFlat ( 21 , 1 , "" , content ) ;
218-
219- assert . equal ( editedText , checkText ) ;
177+ testEdit ( 21 , 1 , "" ) ;
220178 } ) ;
221179
222180 it ( 'Case Ib: single line no line breaks deleted or inserted, insert 1 char' , ( ) => {
223- snapshot = lineIndex . edit ( 21 , 0 , "b" ) ;
224- editedText = snapshot . getText ( 0 , content . length + 1 ) ;
225- checkText = editFlat ( 21 , 0 , "b" , content ) ;
226-
227- assert . equal ( editedText , checkText ) ;
181+ testEdit ( 21 , 0 , "b" ) ;
228182 } ) ;
229183
230184 it ( 'Case Ib: single line no line breaks deleted or inserted, delete 1, insert 2 chars' , ( ) => {
231- snapshot = lineIndex . edit ( 21 , 1 , "cr" ) ;
232- editedText = snapshot . getText ( 0 , content . length + 1 ) ;
233- checkText = editFlat ( 21 , 1 , "cr" , content ) ;
234-
235- assert . equal ( editedText , checkText ) ;
185+ testEdit ( 21 , 1 , "cr" ) ;
236186 } ) ;
237187
238188 it ( 'Case II: delete across line break (just the line break)' , ( ) => {
239- snapshot = lineIndex . edit ( 21 , 22 ) ;
240- editedText = snapshot . getText ( 0 , content . length - 22 ) ;
241- checkText = editFlat ( 21 , 22 , "" , content ) ;
242-
243- assert . equal ( editedText , checkText ) ;
189+ testEdit ( 21 , 22 , "" ) ;
244190 } ) ;
245191
246192 it ( 'Case IIb: delete across line break' , ( ) => {
247-
248- snapshot = lineIndex . edit ( 21 , 32 ) ;
249- editedText = snapshot . getText ( 0 , content . length - 32 ) ;
250- checkText = editFlat ( 21 , 32 , "" , content ) ;
251-
252- assert . equal ( editedText , checkText ) ;
193+ testEdit ( 21 , 32 , "" ) ;
253194 } ) ;
254195
255196 it ( 'Case III: delete across multiple line breaks and insert no line breaks' , ( ) => {
256- snapshot = lineIndex . edit ( 21 , 42 ) ;
257- editedText = snapshot . getText ( 0 , content . length - 42 ) ;
258- checkText = editFlat ( 21 , 42 , "" , content ) ;
259-
260- assert . equal ( editedText , checkText ) ;
197+ testEdit ( 21 , 42 , "" ) ;
261198 } ) ;
262199
263200 it ( 'Case IIIb: delete across multiple line breaks and insert text' , ( ) => {
264- snapshot = lineIndex . edit ( 21 , 42 , "slithery " ) ;
265- editedText = snapshot . getText ( 0 , content . length - 33 ) ;
266- checkText = editFlat ( 21 , 42 , "slithery " , content ) ;
267-
268- assert . equal ( editedText , checkText ) ;
201+ testEdit ( 21 , 42 , "slithery " ) ;
269202 } ) ;
270203 } ) ;
271204
0 commit comments