@@ -32,7 +32,7 @@ describe 'calculate_operations', ->
3232 after = ' working on it' .split ' '
3333 @res = @ cut before, after
3434
35- it ' should result in 3 operation ' , ->
35+ it ' should result in 3 operations ' , ->
3636 (expect @res .length ).to .equal 3
3737
3838 it ' should show an insert for "on"' , ->
@@ -196,3 +196,42 @@ describe 'calculate_operations', ->
196196 end_in_before : 5
197197 start_in_after : 4
198198 end_in_after : undefined
199+
200+ describe ' Action Combination' , ->
201+ describe ' Absorb single-whitespace to make contiguous replace actions' , ->
202+ beforeEach ->
203+ # There are a bunch of replaces, but, because whitespace is
204+ # tokenized, they are broken up with equals. We want to combine
205+ # them into a contiguous replace operation.
206+ before = [' I' , ' ' , ' am' , ' ' , ' awesome' ]
207+ after = [' You' , ' ' , ' are' , ' ' , ' great' ]
208+ @res = @ cut before, after
209+
210+ it ' should return 1 action' , ->
211+ (expect @res .length ).to .equal 1
212+
213+ it ' should return the correct replace action' , ->
214+ (expect @res [0 ]).eql
215+ action : ' replace'
216+ start_in_before : 0
217+ end_in_before : 4
218+ start_in_after : 0
219+ end_in_after : 4
220+
221+ describe ' but dont absorb non-single-whitespace tokens' , ->
222+ beforeEach ->
223+ before = [' I' , ' ' , ' am' , ' ' , ' awesome' ]
224+ after = [' You' , ' ' , ' are' , ' ' , ' great' ]
225+ @res = @ cut before, after
226+
227+ it ' should return 3 actions' , ->
228+ (expect @res .length ).to .equal 3
229+
230+ it ' should have a replace first' , ->
231+ (expect @res [0 ].action ).to .equal ' replace'
232+
233+ it ' should have an equal second' , ->
234+ (expect @res [1 ].action ).to .equal ' equal'
235+
236+ it ' should have a replace last' , ->
237+ (expect @res [2 ].action ).to .equal ' replace'
0 commit comments