[duplicates] enable duplicates analysis in PyCharm/WebStorm/PhpStorm/RubyMine
[idea/community.git] / platform / diff-impl / tests / testSrc / com / intellij / diff / merge / MergeTest.kt
1 /*
2  * Copyright 2000-2015 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.intellij.diff.merge
17
18 import com.intellij.diff.merge.MergeTestBase.SidesState.*
19 import com.intellij.diff.tools.util.base.IgnorePolicy
20 import com.intellij.diff.util.Side
21 import com.intellij.diff.util.TextDiffType.*
22 import com.intellij.diff.util.ThreeSide
23 import com.intellij.util.ui.UIUtil
24
25 class MergeTest : MergeTestBase() {
26   fun testChangeTypes() {
27     test("", "", "", 0) {
28     }
29
30     test("x", "x", "x", 0) {
31     }
32
33     test("x_y_z a x", "x_y_z a x", "x_y_z a x", 0) {
34     }
35
36     test1("x", "x", "y") {
37       0.assertType(MODIFIED, RIGHT)
38       0.assertContent("x", 0, 1)
39       0.assertResolved(NONE)
40     }
41
42     test1("x", "y", "x") {
43       0.assertType(MODIFIED, BOTH)
44       0.assertContent("y", 0, 1)
45       0.assertResolved(NONE)
46     }
47
48     test2("x_Y", "Y", "Y_z") {
49       0.assertType(INSERTED, LEFT)
50       0.assertContent("", 0, 0)
51       0.assertResolved(NONE)
52
53       1.assertType(INSERTED, RIGHT)
54       1.assertContent("", 1, 1)
55       1.assertResolved(NONE)
56     }
57
58     test2("Y_z", "x_Y_z", "x_Y") {
59       0.assertType(DELETED, LEFT)
60       0.assertContent("x", 0, 1)
61       0.assertResolved(NONE)
62
63       1.assertType(DELETED, RIGHT)
64       1.assertContent("z", 2, 3)
65       1.assertResolved(NONE)
66     }
67
68     test1("X_Z", "X_y_Z", "X_Z") {
69       0.assertType(DELETED, BOTH)
70       0.assertContent("y", 1, 2)
71       0.assertResolved(NONE)
72     }
73
74     test1("X_y_Z", "X_Z", "X_y_Z") {
75       0.assertType(INSERTED, BOTH)
76       0.assertContent("", 1, 1)
77       0.assertResolved(NONE)
78     }
79
80     test1("x", "y", "z") {
81       0.assertType(CONFLICT, BOTH)
82       0.assertContent("y", 0, 1)
83       0.assertResolved(NONE)
84     }
85
86     test1("z_Y", "x_Y", "Y") {
87       0.assertType(CONFLICT, BOTH)
88       0.assertContent("x", 0, 1)
89       0.assertResolved(NONE)
90     }
91
92     test1("z_Y", "x_Y", "k_x_Y") {
93       0.assertType(CONFLICT, BOTH)
94       0.assertContent("x", 0, 1)
95       0.assertResolved(NONE)
96     }
97
98     test1("x_Y", "Y", "z_Y") {
99       0.assertType(CONFLICT, BOTH)
100       0.assertContent("", 0, 0)
101       0.assertResolved(NONE)
102     }
103
104     test1("x_Y", "Y", "z_x_Y") {
105       0.assertType(CONFLICT, BOTH)
106       0.assertContent("", 0, 0)
107       0.assertResolved(NONE)
108     }
109
110     test1("x_Y", "x_z_Y", "z_Y") {
111       0.assertType(CONFLICT, BOTH)
112       0.assertContent("x_z", 0, 2)
113       0.assertResolved(NONE)
114     }
115   }
116
117   fun testLastLine() {
118     test1("x", "x_", "x") {
119       0.assertType(DELETED, BOTH)
120       0.assertContent("", 1, 2)
121       0.assertResolved(NONE)
122     }
123
124     test1("x_", "x_", "x") {
125       0.assertType(DELETED, RIGHT)
126       0.assertContent("", 1, 2)
127       0.assertResolved(NONE)
128     }
129
130     test1("x_", "x_", "x_y") {
131       0.assertType(MODIFIED, RIGHT)
132       0.assertContent("", 1, 2)
133       0.assertResolved(NONE)
134     }
135
136     test1("x", "x_", "x_y") {
137       0.assertType(CONFLICT, BOTH)
138       0.assertContent("", 1, 2)
139       0.assertResolved(NONE)
140     }
141
142     test1("x_", "x", "x_y") {
143       0.assertType(CONFLICT, BOTH)
144       0.assertContent("", 1, 1)
145       0.assertResolved(NONE)
146     }
147   }
148
149   fun testModifications() {
150     test1("x", "x", "y") {
151       0.apply(Side.RIGHT)
152       0.assertResolved(BOTH)
153       0.assertContent("y")
154
155       assertContent("y")
156     }
157
158     test1("x", "x", "y") {
159       0.apply(Side.LEFT)
160       0.assertResolved(BOTH)
161       0.assertContent("x")
162
163       assertContent("x")
164     }
165
166     test1("X_x_Z", "X_x_Z", "X_y_Z") {
167       0.apply(Side.RIGHT)
168       0.assertResolved(BOTH)
169       0.assertContent("y")
170
171       assertContent("X_y_Z")
172     }
173
174     test1("z", "x", "y") {
175       0.apply(Side.RIGHT)
176       0.assertResolved(RIGHT)
177       0.assertContent("y")
178
179       0.apply(Side.LEFT)
180       0.assertResolved(BOTH)
181       0.assertContent("y_z")
182
183       assertContent("y_z")
184     }
185
186     test1("z", "x", "y") {
187       0.apply(Side.LEFT)
188       0.assertResolved(LEFT)
189       0.assertContent("z")
190
191       0.apply(Side.RIGHT)
192       0.assertResolved(BOTH)
193       0.assertContent("z_y")
194
195       assertContent("z_y")
196     }
197
198     test1("X", "X", "X_y") {
199       0.apply(Side.RIGHT)
200       0.assertResolved(BOTH)
201       0.assertContent("y")
202
203       assertContent("X_y")
204     }
205
206     test1("X", "X", "X_y") {
207       0.apply(Side.LEFT)
208       0.assertResolved(BOTH)
209       0.assertContent("")
210
211       assertContent("X")
212     }
213
214     test1("X_z", "X", "X_y") {
215       0.apply(Side.RIGHT)
216       0.assertResolved(RIGHT)
217       0.assertContent("y")
218
219       0.apply(Side.LEFT)
220       0.assertResolved(BOTH)
221       0.assertContent("y_z")
222
223       assertContent("X_y_z")
224     }
225
226     test1("X_z", "X_y", "X") {
227       0.apply(Side.LEFT)
228       0.assertResolved(BOTH)
229       0.assertContent("z")
230
231       assertContent("X_z")
232     }
233
234     test1("X_z", "X_y", "X") {
235       0.apply(Side.RIGHT)
236       0.assertResolved(RIGHT)
237       0.assertContent("")
238
239       0.apply(Side.LEFT)
240       0.assertResolved(BOTH)
241       0.assertContent("z")
242
243       assertContent("X_z")
244     }
245   }
246
247   fun testModificationsIgnore() {
248     test1("x", "x", "y") {
249       0.ignore(Side.RIGHT)
250       0.assertResolved(BOTH)
251       0.assertContent("x")
252
253       assertContent("x")
254     }
255
256     test1("x", "x", "y") {
257       0.ignore(Side.LEFT)
258       0.assertResolved(BOTH)
259       0.assertContent("x")
260
261       assertContent("x")
262     }
263
264     test1("z", "x", "y") {
265       0.ignore(Side.RIGHT)
266       0.assertResolved(RIGHT)
267       0.assertContent("x")
268
269       0.ignore(Side.LEFT)
270       0.assertResolved(BOTH)
271       0.assertContent("x")
272
273       assertContent("x")
274     }
275
276     test1("z", "x", "y") {
277       0.apply(Side.RIGHT)
278       0.assertResolved(RIGHT)
279       0.assertContent("y")
280
281       0.ignore(Side.LEFT)
282       0.assertResolved(BOTH)
283       0.assertContent("y")
284
285       assertContent("y")
286     }
287
288     test1("z", "x", "y") {
289       0.ignore(Side.RIGHT)
290       0.assertResolved(RIGHT)
291       0.assertContent("x")
292
293       0.apply(Side.LEFT)
294       0.assertResolved(BOTH)
295       0.assertContent("z")
296
297       assertContent("z")
298     }
299
300     test1("X_z", "X_y", "X") {
301       0.ignore(Side.RIGHT)
302       0.assertResolved(RIGHT)
303       0.assertContent("y")
304
305       0.apply(Side.LEFT)
306       0.assertResolved(BOTH)
307       0.assertContent("z")
308
309       assertContent("X_z")
310     }
311
312     test1("X_z", "X_y", "X") {
313       0.ignore(Side.LEFT)
314       0.assertResolved(LEFT)
315       0.assertContent("y")
316
317       0.apply(Side.RIGHT)
318       0.assertResolved(BOTH)
319       0.assertContent("")
320
321       assertContent("X")
322     }
323   }
324
325   fun testModificationsModifiers() {
326     test1("x", "x", "y") {
327       0.apply(Side.RIGHT, true)
328       0.assertResolved(BOTH)
329       0.assertContent("y")
330
331       assertContent("y")
332     }
333
334     test1("x", "x", "y") {
335       0.ignore(Side.RIGHT, true)
336       0.assertResolved(BOTH)
337       0.assertContent("x")
338
339       assertContent("x")
340     }
341
342     test1("z", "x", "y") {
343       0.apply(Side.RIGHT, true)
344       0.assertResolved(BOTH)
345       0.assertContent("y")
346
347       assertContent("y")
348     }
349
350     test1("z", "x", "y") {
351       0.ignore(Side.RIGHT, true)
352       0.assertResolved(BOTH)
353       0.assertContent("x")
354
355       assertContent("x")
356     }
357   }
358
359   fun testResolve() {
360     test1("y z", "x y z", "x y") {
361       0.resolve()
362       0.assertResolved(BOTH)
363       0.assertContent("y")
364
365       assertContent("y")
366     }
367
368     test2("y z_Y_x y", "x y z_Y_x y z", "x y_Y_y z") {
369       0.resolve()
370       0.assertResolved(BOTH)
371       0.assertContent("y")
372
373       1.resolve()
374       1.assertResolved(BOTH)
375       1.assertContent("y")
376
377       assertContent("y_Y_y")
378     }
379
380     test2("y z_Y_x y", "x y z_Y_x y z", "x y_Y_y z") {
381       0.apply(Side.LEFT, true)
382       0.assertResolved(BOTH)
383       0.assertContent("y z")
384
385       1.resolve()
386       1.assertResolved(BOTH)
387       1.assertContent("y")
388
389       assertContent("y z_Y_y")
390     }
391
392     test1("y z", "x y z", "x y") {
393       assertTrue(0.canResolveConflict())
394
395       replaceText(2, 3, "U")
396       assertContent("x U z")
397
398       assertFalse(0.canResolveConflict())
399     }
400
401     test2("y z_Y_x y", "x y z_Y_x y z", "x y_Y_y z") {
402       assertTrue(0.canResolveConflict())
403       assertTrue(1.canResolveConflict())
404
405
406       replaceText(2, 3, "U")
407
408       assertFalse(0.canResolveConflict())
409       assertTrue(1.canResolveConflict())
410       assertContent("x U z_Y_x y z")
411
412
413       checkUndo(1) {
414         1.resolve()
415       }
416       1.assertResolved(BOTH)
417       1.assertContent("y")
418
419       assertFalse(0.canResolveConflict())
420       assertFalse(1.canResolveConflict())
421       assertContent("x U z_Y_y")
422
423
424       replaceText(2, 3, "y")
425
426       assertTrue(0.canResolveConflict())
427       assertFalse(1.canResolveConflict())
428
429
430       checkUndo(1) {
431         0.resolve()
432       }
433
434       assertFalse(0.canResolveConflict())
435       assertFalse(1.canResolveConflict())
436       assertContent("y_Y_y")
437     }
438   }
439
440   fun testUndoSimple() {
441     test1("x", "y", "z") {
442       checkUndo(1) {
443         0.apply(Side.RIGHT)
444       }
445     }
446
447     test1("x", "y", "z") {
448       checkUndo(1) {
449         0.apply(Side.RIGHT, true)
450       }
451     }
452
453     test1("x", "y", "z") {
454       checkUndo(1) {
455         0.ignore(Side.RIGHT)
456       }
457     }
458
459     test1("x", "y", "z") {
460       checkUndo(1) {
461         0.ignore(Side.RIGHT, true)
462       }
463     }
464
465     test1("x", "y", "z") {
466       checkUndo(2) {
467         0.apply(Side.RIGHT)
468         0.apply(Side.LEFT)
469       }
470     }
471
472     test1("x", "y", "z") {
473       checkUndo(2) {
474         0.apply(Side.RIGHT)
475         0.apply(Side.RIGHT)
476       }
477     }
478
479     test1("X", "X_y", "X") {
480       checkUndo(1) {
481         0.apply(Side.RIGHT)
482       }
483     }
484
485     test1("X", "X", "X_y") {
486       checkUndo(1) {
487         0.apply(Side.LEFT)
488       }
489     }
490
491     test1("X", "X", "X_y") {
492       checkUndo(1) {
493         0.apply(Side.RIGHT)
494       }
495     }
496
497     test1("X_z", "X_y", "X") {
498       checkUndo(1) {
499         0.apply(Side.LEFT)
500       }
501     }
502
503     test1("X_z", "X_y", "X") {
504       checkUndo(1) {
505         0.apply(Side.RIGHT)
506       }
507     }
508
509     test2("y_X", "X", "X_z") {
510       checkUndo(1) {
511         0.apply(Side.LEFT)
512       }
513       checkUndo(1) {
514         1.apply(Side.RIGHT)
515       }
516
517       assertContent("y_X_z")
518     }
519   }
520
521   fun testRangeModification() {
522     test1("X_x_y_z_Y", "X_a_b_c_Y", "X_x_y_z_Y") {
523       0.assertContent("a_b_c", 1, 4)
524       checkUndo(1) { replaceText(!2 - 0, !2 - 1, "D") }
525       0.assertContent("a_D_c", 1, 4)
526     }
527
528     test1("X_x_y_z_Y", "X_a_b_c_Y", "X_x_y_z_Y") {
529       0.assertContent("a_b_c", 1, 4)
530       checkUndo(1) { replaceText(!2 - -1, !2 - 2, "D") }
531       0.assertContent("aDc", 1, 2)
532     }
533
534     test1("X_x_y_z_Y", "X_a_b_c_Y", "X_x_y_z_Y") {
535       0.assertContent("a_b_c", 1, 4)
536       checkUndo(1) { replaceText("c", "u_x") }
537       0.assertContent("a_b_u_x", 1, 5)
538     }
539
540     test1("X_x_y_z_Y", "X_a_b_c_Y", "X_x_y_z_Y") {
541       0.assertContent("a_b_c", 1, 4)
542       checkUndo(1) { deleteText("c_") }
543       0.assertContent("a_b", 1, 3)
544     }
545
546     test1("X_x_y_z_Y", "X_a_b_c_Y", "X_x_y_z_Y") {
547       0.assertContent("a_b_c", 1, 4)
548       checkUndo(1) { insertTextBefore("b", "q") }
549       0.assertContent("a_qb_c", 1, 4)
550     }
551
552     test1("X_x_y_z_Y", "X_a_b_c_Y", "X_x_y_z_Y") {
553       0.assertContent("a_b_c", 1, 4)
554       checkUndo(1) { insertTextAfter("b", "q") }
555       0.assertContent("a_bq_c", 1, 4)
556     }
557
558     test1("X_x_y_z_Y", "X_a_b_c_Y", "X_x_y_z_Y") {
559       0.assertContent("a_b_c", 1, 4)
560       checkUndo(1) { insertText(0, "a_b_c_") }
561       0.assertContent("a_b_c", 4, 7)
562     }
563
564     test1("A_X_x_y_z_Y", "A_X_a_b_c_Y", "A_X_x_y_z_Y") {
565       0.assertContent("a_b_c", 2, 5)
566       checkUndo(1) { replaceText("X_a_b", "q_w_e") }
567       0.assertContent("c")
568     }
569
570     test1("X_x_y_z_Y_A", "X_a_b_c_Y_A", "X_x_y_z_Y_A") {
571       0.assertContent("a_b_c")
572       checkUndo(1) { replaceText("c_Y", "q") }
573       0.assertContent("a_b")
574     }
575
576     test1("A_X_x_Y_A", "A_X_b_Y_A", "A_X_x_z_Y_A") {
577       0.assertContent("b")
578       checkUndo(1) { replaceText("X_b_Y", "q") }
579
580       0.assertContent("", 2, 2)
581       assertContent("A_q_A")
582     }
583   }
584
585   fun testNonConflictsActions() {
586     val text1 = """
587                 1 ======
588                 insert left
589                 2 ======
590                 remove right
591                 3 ======
592                 new both
593                 4 ======
594                 modify both
595                 5 ======
596                 modify
597                 6 ======
598                 7 ======
599                 8 ======""".trimIndent()
600     val text2 = """
601                 1 ======
602                 2 ======
603                 remove right
604                 3 ======
605                 4 ======
606                 modify
607                 5 ======
608                 modify
609                 6 ======
610                 7 ======
611                 delete modify
612                 8 ======""".trimIndent()
613     val text3 = """
614                 1 ======
615                 2 ======
616                 3 ======
617                 new both
618                 4 ======
619                 modify both
620                 5 ======
621                 modify right
622                 6 ======
623                 7 ======
624                 modify
625                 8 ======""".trimIndent()
626
627     testN(text1, text2, text3) {
628       checkUndo(1) {
629         runApplyNonConflictsAction(ThreeSide.BASE)
630       }
631
632       assertChangesCount(1)
633       assertContent("""
634                     1 ======
635                     insert left
636                     2 ======
637                     3 ======
638                     new both
639                     4 ======
640                     modify both
641                     5 ======
642                     modify right
643                     6 ======
644                     7 ======
645                     delete modify
646                     8 ======""".trimIndent())
647     }
648
649     testN(text1, text2, text3) {
650       checkUndo(1) {
651         runApplyNonConflictsAction(ThreeSide.LEFT)
652       }
653
654       assertChangesCount(3)
655       assertContent("""
656                     1 ======
657                     insert left
658                     2 ======
659                     remove right
660                     3 ======
661                     new both
662                     4 ======
663                     modify both
664                     5 ======
665                     modify
666                     6 ======
667                     7 ======
668                     delete modify
669                     8 ======""".trimIndent())
670     }
671
672     testN(text1, text2, text3) {
673       checkUndo(1) {
674         runApplyNonConflictsAction(ThreeSide.RIGHT)
675       }
676
677       assertChangesCount(2)
678       assertContent("""
679                     1 ======
680                     2 ======
681                     3 ======
682                     new both
683                     4 ======
684                     modify both
685                     5 ======
686                     modify right
687                     6 ======
688                     7 ======
689                     delete modify
690                     8 ======""".trimIndent())
691     }
692
693     testN(text1, text2, text3) {
694       replaceText(!5 - 0, !5 - 0, "USER ")
695
696       checkUndo(1) {
697         runApplyNonConflictsAction(ThreeSide.BASE)
698       }
699
700       assertChangesCount(2)
701       assertContent("""
702                     1 ======
703                     insert left
704                     2 ======
705                     3 ======
706                     new both
707                     4 ======
708                     USER modify
709                     5 ======
710                     modify right
711                     6 ======
712                     7 ======
713                     delete modify
714                     8 ======""".trimIndent())
715     }
716
717     testN(text1, text2, text3) {
718       replaceText(!7 - 0, !7 - 0, "USER ")
719
720       checkUndo(1) {
721         runApplyNonConflictsAction(ThreeSide.RIGHT)
722       }
723
724       assertChangesCount(3)
725       assertContent("""
726                     1 ======
727                     2 ======
728                     3 ======
729                     new both
730                     4 ======
731                     modify both
732                     5 ======
733                     USER modify
734                     6 ======
735                     7 ======
736                     delete modify
737                     8 ======""".trimIndent())
738     }
739   }
740
741
742   fun testNoConflicts() {
743     test2("a_Ins1_b_ccc", "a_b_ccc", "a_b_dddd") {
744       0.assertRange(1, 2, 1, 1, 1, 1)
745       1.assertRange(3, 4, 2, 3, 2, 3)
746
747       0.apply(Side.LEFT)
748       0.assertRange(1, 2, 1, 2, 1, 1)
749       1.assertRange(3, 4, 3, 4, 2, 3)
750       assertContent("a_Ins1_b_ccc")
751
752       runApplyNonConflictsAction(ThreeSide.BASE)
753       0.assertRange(1, 2, 1, 2, 1, 1)
754       1.assertRange(3, 4, 3, 4, 2, 3)
755       assertContent("a_Ins1_b_dddd")
756
757       0.assertResolved(BOTH)
758       1.assertResolved(BOTH)
759     }
760   }
761
762   fun testConflictingChange() {
763     test("1_2_3_X_a_b_c_Y_Ver1_Ver12_Z",
764                "X_a_b_c_Y_" + "Ver12_Ver23_Z",
765                "X_" +  "Y_" + "Ver23_Ver3_Z", 3) {
766       0.assertType(INSERTED)
767       1.assertType(DELETED)
768       2.assertType(CONFLICT)
769
770       runApplyNonConflictsAction(ThreeSide.BASE)
771       0.assertResolved(BOTH)
772       1.assertResolved(BOTH)
773       2.assertResolved(NONE)
774
775       assertContent("1_2_3_X_Y_Ver12_Ver23_Z")
776     }
777   }
778
779   fun testApplyMergeThenUndo() {
780     test1("X_b_Y", "X_1_2_3_Y", "X_a_Y") {
781       0.assertRange(1, 2, 1, 4, 1, 2)
782
783       0.apply(Side.RIGHT)
784       0.assertRange(1, 2, 1, 2, 1, 2)
785       0.assertContent("a")
786
787       checkUndo(1) {
788         0.apply(Side.LEFT)
789         0.assertRange(1, 2, 1, 3, 1, 2)
790         0.assertContent("a_b")
791       }
792
793       assertContent("X_a_b_Y")
794     }
795   }
796
797   fun testApplyModifiedDeletedConflict() {
798     test1("X_Y", "X_1_2_3_Y", "X_a_Y") {
799       0.assertRange(1, 1, 1, 4, 1, 2)
800       0.assertContent("1_2_3")
801
802       runApplyNonConflictsAction(ThreeSide.BASE)
803       0.assertResolved(NONE)
804
805       0.apply(Side.RIGHT)
806       0.assertRange(1, 1, 1, 2, 1, 2)
807       0.assertResolved(BOTH)
808
809       assertContent("X_a_Y")
810     }
811   }
812
813   fun testInvalidatingChange() {
814     test1("X_1_2_Y", "X_1_Ins_2_Y", "X_1_2_Y") {
815       0.assertType(DELETED)
816       0.assertRange(2, 2, 2, 3, 2, 2)
817
818       deleteText("1_Ins_2_")
819       0.assertResolved(BOTH)
820       0.assertRange(2, 2, 2, 2, 2, 2)
821     }
822   }
823
824   fun testApplySeveralActions() {
825     test("X_1_Y_2_Z_3_4_U_W_",
826          "X_a_Y_b_Z_c_U_d_W_",
827          "X_a_Y_B_Z_C_U_D_W_", 4) {
828       0.assertType(MODIFIED)
829       1.assertType(CONFLICT)
830       2.assertType(CONFLICT)
831       3.assertType(CONFLICT)
832
833       0.apply(Side.LEFT)
834       0.assertResolved(BOTH)
835       0.assertResolved(BOTH)
836
837       3.apply(Side.RIGHT)
838       3.assertResolved(BOTH)
839       assertContent("X_1_Y_b_Z_c_U_D_W_")
840
841       1.apply(Side.RIGHT)
842       1.assertResolved(RIGHT)
843       assertContent("X_1_Y_B_Z_c_U_D_W_")
844
845       1.apply(Side.LEFT)
846       2.apply(Side.LEFT)
847       2.apply(Side.RIGHT)
848       1.assertResolved(BOTH)
849       2.assertResolved(BOTH)
850       assertContent("X_1_Y_B_2_Z_3_4_C_U_D_W_")
851     }
852   }
853
854   fun testIgnoreChangeAction() {
855     test2("X_1_Y_2_Z", "X_a_Y_b_Z", "X_a_Y_B_Z") {
856       0.assertType(MODIFIED)
857       1.assertType(CONFLICT)
858
859       0.ignore(Side.LEFT)
860       0.assertRange(1, 2, 1, 2, 1, 2)
861       assertContent("X_a_Y_b_Z")
862
863       0.ignore(Side.RIGHT)
864       0.assertResolved(BOTH)
865       0.assertRange(1, 2, 1, 2, 1, 2)
866       assertContent("X_a_Y_b_Z")
867
868     }
869   }
870
871   fun testLongBase() {
872     test1("X_1_2_3_Z", "X_1_b_3_d_e_f_Z", "X_a_b_c_Z") {
873       0.assertType(CONFLICT)
874       0.assertRange(1, 4, 1, 7, 1, 4)
875     }
876   }
877
878   fun testReplaceBaseWithBranch() {
879     test2("a_X_b_c", "A_X_B_c", "1_X_1_c") {
880       0.assertType(CONFLICT)
881       1.assertType(CONFLICT)
882
883       0.apply(Side.LEFT)
884       assertContent("a_X_B_c")
885
886       replaceText("a_X_B_c", "a_X_b_c")
887
888       0.assertRange(0, 1, 0, 1, 0, 1)
889       1.assertRange(2, 3, 2, 3, 2, 3)
890     }
891   }
892
893   fun testError1() {
894     testN("start_change_ a_ b",
895           "start_CHANGE_   a_   b",
896           "    }_    return new DiffFragment(notEmptyContent(buffer1), notEmptyContent(buffer2));_  }") {
897
898     }
899   }
900
901   fun testError2() {
902     test1("C_X", "C_", "C_") {
903       0.assertRange(1, 2, 1, 2, 1, 2)
904     }
905   }
906
907   fun testError3() {
908     testN("original_local_local_local_original_",
909           "original_original_original_original_original_",
910           "original_remote_remote_remote_original_") {
911
912     }
913   }
914
915   fun testIgnored() {
916     test(" x_new_y_z", "x_ y _z", "x_y _new_ z", 5, IgnorePolicy.IGNORE_WHITESPACES) {
917       0.assertRange(0, 1, 0, 1, 0, 1)
918       1.assertRange(1, 2, 1, 1, 1, 1)
919       2.assertRange(2, 3, 1, 2, 1, 2)
920       3.assertRange(3, 3, 2, 2, 2, 3)
921       4.assertRange(3, 4, 2, 3, 3, 4)
922
923       0.assertType(MODIFIED, LEFT)
924       1.assertType(INSERTED, LEFT)
925       2.assertType(MODIFIED, BOTH)
926       3.assertType(INSERTED, RIGHT)
927       4.assertType(MODIFIED, RIGHT)
928
929       checkUndo(1) {
930         runApplyNonConflictsAction(ThreeSide.BASE)
931       }
932       assertContent(" x_new_y_new_ z")
933
934       0.assertResolved(BOTH)
935       1.assertResolved(BOTH)
936       2.assertResolved(BOTH)
937       3.assertResolved(BOTH)
938       4.assertResolved(BOTH)
939
940       undo(1)
941
942       1.apply(Side.RIGHT)
943       2.apply(Side.RIGHT)
944
945       checkUndo(1) {
946         runApplyNonConflictsAction(ThreeSide.BASE)
947       }
948
949       assertContent(" x_y _new_ z")
950     }
951
952     test(" x_new_y1_z", "x_ y _z", "x_y2 _new_ z", 3, IgnorePolicy.IGNORE_WHITESPACES) {
953       0.assertRange(0, 1, 0, 1, 0, 1)
954       1.assertRange(1, 3, 1, 2, 1, 3)
955       2.assertRange(3, 4, 2, 3, 3, 4)
956
957       0.assertType(MODIFIED, LEFT)
958       1.assertType(CONFLICT, BOTH)
959       2.assertType(MODIFIED, RIGHT)
960
961       checkUndo(1) {
962         runApplyNonConflictsAction(ThreeSide.BASE)
963       }
964       assertContent(" x_ y _ z")
965
966       0.assertResolved(BOTH)
967       1.assertResolved(NONE)
968       2.assertResolved(BOTH)
969     }
970
971     test(" x_new_y_z", "x_ y _z", "x_y _new_ z", 1, IgnorePolicy.DEFAULT) {
972       0.assertRange(0, 4, 0, 3, 0, 4)
973       0.assertType(CONFLICT, BOTH)
974
975       viewer.textSettings.ignorePolicy = IgnorePolicy.IGNORE_WHITESPACES
976       UIUtil.dispatchAllInvocationEvents()
977       assertCantUndo()
978
979       0.assertRange(0, 1, 0, 1, 0, 1)
980       1.assertRange(1, 2, 1, 1, 1, 1)
981       2.assertRange(2, 3, 1, 2, 1, 2)
982       3.assertRange(3, 3, 2, 2, 2, 3)
983       4.assertRange(3, 4, 2, 3, 3, 4)
984
985       checkUndo(1) {
986         runApplyNonConflictsAction(ThreeSide.RIGHT)
987       }
988       assertContent("x_y _new_ z")
989
990       0.assertResolved(NONE)
991       1.assertResolved(NONE)
992       2.assertResolved(BOTH)
993       3.assertResolved(BOTH)
994       4.assertResolved(BOTH)
995     }
996   }
997 }