1#
2# Copyright (c) 2009 D. Richard Hipp
3#
4# This program is free software; you can redistribute it and/or
5# modify it under the terms of the Simplified BSD License (also
6# known as the "2-Clause License" or "FreeBSD License".)
7#
8# This program is distributed in the hope that it will be useful,
9# but without any warranty; without even the implied warranty of
10# merchantability or fitness for a particular purpose.
11#
12# Author contact information:
13#   drh@hwaci.com
14#   http://www.hwaci.com/drh/
15#
16############################################################################
17#
18# Tests of the 3-way merge
19#
20
21test_setup ""
22
23proc merge-test {testid basis v1 v2 result} {
24  write_file t1 [join [string trim $basis] \n]\n
25  write_file t2 [join [string trim $v1] \n]\n
26  write_file t3 [join [string trim $v2] \n]\n
27  fossil 3-way-merge t1 t2 t3 t4
28  set x [read_file t4]
29  regsub -all {<<<<<<< BEGIN MERGE CONFLICT: local copy shown first <+} $x \
30              {MINE:} x
31  regsub -all {\|\|\|\|\|\|\| COMMON ANCESTOR content follows \|+} $x {COM:} x
32  regsub -all {======= MERGED IN content follows =+} $x {YOURS:} x
33  regsub -all {>>>>>>> END MERGE CONFLICT >+} $x {END} x
34  set x [split [string trim $x] \n]
35  set result [string trim $result]
36  if {$x!=$result} {
37    protOut "  Expected \[$result\]"
38    protOut "       Got \[$x\]"
39    test merge3-$testid 0
40  } else {
41    test merge3-$testid 1
42  }
43}
44
45merge-test 1 {
46  1 2 3 4 5 6 7 8 9
47} {
48  1 2 3b 4 5 6 7 8 9
49} {
50  1 2 3 4 5c 6 7 8 9
51} {
52  1 2 3b 4 5c 6 7 8 9
53}
54
55merge-test 2 {
56  1 2 3 4 5 6 7 8 9
57} {
58  1 2 3b 4b 5 6 7 8 9
59} {
60  1 2 3 4 5c 6 7 8 9
61} {
62  1 2 3b 4b 5c 6 7 8 9
63}
64merge-test 3 {
65  1 2 3 4 5 6 7 8 9
66} {
67  1 2 3b 4b 5b 6 7 8 9
68} {
69  1 2 3 4 5c 6 7 8 9
70} {
71  1 2 MINE: 3b 4b 5b COM: 3 4 5 YOURS: 3 4 5c END 6 7 8 9
72}
73merge-test 4 {
74  1 2 3 4 5 6 7 8 9
75} {
76  1 2 3b 4b 5b 6b 7 8 9
77} {
78  1 2 3 4 5c 6 7 8 9
79} {
80  1 2 MINE: 3b 4b 5b 6b COM: 3 4 5 6 YOURS: 3 4 5c 6 END 7 8 9
81}
82merge-test 5 {
83  1 2 3 4 5 6 7 8 9
84} {
85  1 2 3b 4b 5b 6b 7 8 9
86} {
87  1 2 3 4 5c 6c 7c 8 9
88} {
89  1 2 MINE: 3b 4b 5b 6b 7 COM: 3 4 5 6 7 YOURS: 3 4 5c 6c 7c END 8 9
90}
91merge-test 6 {
92  1 2 3 4 5 6 7 8 9
93} {
94  1 2 3b 4b 5b 6b 7 8b 9
95} {
96  1 2 3 4 5c 6c 7c 8 9
97} {
98  1 2 MINE: 3b 4b 5b 6b 7 COM: 3 4 5 6 7 YOURS: 3 4 5c 6c 7c END 8b 9
99}
100merge-test 7 {
101  1 2 3 4 5 6 7 8 9
102} {
103  1 2 3b 4b 5b 6b 7 8b 9
104} {
105  1 2 3 4 5c 6c 7c 8c 9
106} {
107  1 2 MINE: 3b 4b 5b 6b 7 8b COM: 3 4 5 6 7 8 YOURS: 3 4 5c 6c 7c 8c END 9
108}
109merge-test 8 {
110  1 2 3 4 5 6 7 8 9
111} {
112  1 2 3b 4b 5b 6b 7 8b 9b
113} {
114  1 2 3 4 5c 6c 7c 8c 9
115} {
116  1 2 MINE: 3b 4b 5b 6b 7 8b 9b COM: 3 4 5 6 7 8 9 YOURS: 3 4 5c 6c 7c 8c 9 END
117}
118merge-test 9 {
119  1 2 3 4 5 6 7 8 9
120} {
121  1 2 3b 4b 5 6 7 8b 9b
122} {
123  1 2 3 4 5c 6c 7c 8 9
124} {
125  1 2 3b 4b 5c 6c 7c 8b 9b
126}
127
128merge-test 10 {
129  1 2 3 4 5 6 7 8 9
130} {
131  1 2 3b 4b 5 6 7 8b 9b
132} {
133  1 2 3b 4b 5 6c 7c 8 9
134} {
135  1 2 3b 4b 5 6c 7c 8b 9b
136}
137merge-test 11 {
138  1 2 3 4 5 6 7 8 9
139} {
140  1 2 3b 4b 5 6 7 8b 9b
141} {
142  1 2 3b 4c 5 6c 7c 8 9
143} {
144  1 2 MINE: 3b 4b COM: 3 4 YOURS: 3b 4c END 5 6c 7c 8b 9b
145}
146merge-test 12 {
147  1 2 3 4 5 6 7 8 9
148} {
149  1 2 3b4b 5 6 7 8b 9b
150} {
151  1 2 3b4b 5 6c 7c 8 9
152} {
153  1 2 3b4b 5 6c 7c 8b 9b
154}
155
156merge-test 20 {
157  1 2 3 4 5 6 7 8 9
158} {
159  1 3 4 5 6 7 8 9
160} {
161  1 2 3 4 5 6 7 9
162} {
163  1 3 4 5 6 7 9
164}
165merge-test 21 {
166  1 2 3 4 5 6 7 8 9
167} {
168  1 4 5 6 7 8 9
169} {
170  1 2 3 4 5 6 9
171} {
172  1 4 5 6 9
173}
174merge-test 22 {
175  1 2 3 4 5 6 7 8 9
176} {
177  1 5 6 7 8 9
178} {
179  1 2 3 4 5 9
180} {
181  1 5 9
182}
183merge-test 23 {
184  1 2 3 4 5 6 7 8 9
185} {
186  1 6 7 8 9
187} {
188  1 2 3 4 5 9
189} {
190  1 9
191}
192merge-test 24 {
193  1 2 3 4 5 6 7 8 9
194} {
195  1 6 7 8 9
196} {
197  1 2 3 4 9
198} {
199  1 MINE: 6 7 8 COM: 2 3 4 5 6 7 8 YOURS: 2 3 4 END 9
200}
201merge-test 25 {
202  1 2 3 4 5 6 7 8 9
203} {
204  1 7 8 9
205} {
206  1 2 3 9
207} {
208  1 MINE: 7 8 COM: 2 3 4 5 6 7 8 YOURS: 2 3 END 9
209}
210
211merge-test 30 {
212  1 2 3 4 5 6 7 8 9
213} {
214  1 2 3 4 5 6 7 9
215} {
216  1 3 4 5 6 7 8 9
217} {
218  1 3 4 5 6 7 9
219}
220merge-test 31 {
221  1 2 3 4 5 6 7 8 9
222} {
223  1 2 3 4 5 6 9
224} {
225  1 4 5 6 7 8 9
226} {
227  1 4 5 6 9
228}
229merge-test 32 {
230  1 2 3 4 5 6 7 8 9
231} {
232  1 2 3 4 5 9
233} {
234  1 5 6 7 8 9
235} {
236  1 5 9
237}
238merge-test 33 {
239  1 2 3 4 5 6 7 8 9
240} {
241  1 2 3 4 5 9
242} {
243  1 6 7 8 9
244} {
245  1 9
246}
247merge-test 34 {
248  1 2 3 4 5 6 7 8 9
249} {
250  1 2 3 4 9
251} {
252  1 6 7 8 9
253} {
254  1 MINE: 2 3 4 COM: 2 3 4 5 6 7 8 YOURS: 6 7 8 END 9
255}
256merge-test 35 {
257  1 2 3 4 5 6 7 8 9
258} {
259  1 2 3 9
260} {
261  1 7 8 9
262} {
263  1 MINE: 2 3 COM: 2 3 4 5 6 7 8 YOURS: 7 8 END 9
264}
265
266merge-test 40 {
267  2 3 4 5 6 7 8
268} {
269  3 4 5 6 7 8
270} {
271  2 3 4 5 6 7
272} {
273  3 4 5 6 7
274}
275merge-test 41 {
276  2 3 4 5 6 7 8
277} {
278  4 5 6 7 8
279} {
280  2 3 4 5 6
281} {
282  4 5 6
283}
284merge-test 42 {
285  2 3 4 5 6 7 8
286} {
287  5 6 7 8
288} {
289  2 3 4 5
290} {
291  5
292}
293merge-test 43 {
294  2 3 4 5 6 7 8
295} {
296  6 7 8
297} {
298  2 3 4 5
299} {
300
301}
302merge-test 44 {
303  2 3 4 5 6 7 8
304} {
305  6 7 8
306} {
307  2 3 4
308} {
309  MINE: 6 7 8 COM: 2 3 4 5 6 7 8 YOURS: 2 3 4 END
310}
311merge-test 45 {
312  2 3 4 5 6 7 8
313} {
314  7 8
315} {
316  2 3
317} {
318  MINE: 7 8 COM: 2 3 4 5 6 7 8 YOURS: 2 3 END
319}
320
321merge-test 50 {
322  2 3 4 5 6 7 8
323} {
324  2 3 4 5 6 7
325} {
326  3 4 5 6 7 8
327} {
328  3 4 5 6 7
329}
330merge-test 51 {
331  2 3 4 5 6 7 8
332} {
333  2 3 4 5 6
334} {
335  4 5 6 7 8
336} {
337  4 5 6
338}
339merge-test 52 {
340  2 3 4 5 6 7 8
341} {
342  2 3 4 5
343} {
344  5 6 7 8
345} {
346  5
347}
348merge-test 53 {
349  2 3 4 5 6 7 8
350} {
351  2 3 4 5
352} {
353  6 7 8
354} {
355}
356merge-test 54 {
357  2 3 4 5 6 7 8
358} {
359  2 3 4
360} {
361  6 7 8
362} {
363  MINE: 2 3 4 COM: 2 3 4 5 6 7 8 YOURS: 6 7 8 END
364}
365merge-test 55 {
366  2 3 4 5 6 7 8
367} {
368  2 3
369} {
370  7 8
371} {
372  MINE: 2 3 COM: 2 3 4 5 6 7 8 YOURS: 7 8 END
373}
374
375merge-test 60 {
376  1 2 3 4 5 6 7 8 9
377} {
378  1 2b 3 4 5 6 7 8 9
379} {
380  1 2 3 4 5 6 7 9
381} {
382  1 2b 3 4 5 6 7 9
383}
384merge-test 61 {
385  1 2 3 4 5 6 7 8 9
386} {
387  1 2b 3b 4 5 6 7 8 9
388} {
389  1 2 3 4 5 6 9
390} {
391  1 2b 3b 4 5 6 9
392}
393merge-test 62 {
394  1 2 3 4 5 6 7 8 9
395} {
396  1 2b 3b 4b 5 6 7 8 9
397} {
398  1 2 3 4 5 9
399} {
400  1 2b 3b 4b 5 9
401}
402merge-test 63 {
403  1 2 3 4 5 6 7 8 9
404} {
405  1 2b 3b 4b 5b 6 7 8 9
406} {
407  1 2 3 4 5 9
408} {
409  1 2b 3b 4b 5b 9
410}
411merge-test 64 {
412  1 2 3 4 5 6 7 8 9
413} {
414  1 2b 3b 4b 5b 6 7 8 9
415} {
416  1 2 3 4 9
417} {
418  1 MINE: 2b 3b 4b 5b 6 7 8 COM: 2 3 4 5 6 7 8 YOURS: 2 3 4 END 9
419}
420merge-test 65 {
421  1 2 3 4 5 6 7 8 9
422} {
423  1 2b 3b 4b 5b 6b 7 8 9
424} {
425  1 2 3 9
426} {
427  1 MINE: 2b 3b 4b 5b 6b 7 8 COM: 2 3 4 5 6 7 8 YOURS: 2 3 END 9
428}
429
430merge-test 70 {
431  1 2 3 4 5 6 7 8 9
432} {
433  1 2 3 4 5 6 7 9
434} {
435  1 2b 3 4 5 6 7 8 9
436} {
437  1 2b 3 4 5 6 7 9
438}
439merge-test 71 {
440  1 2 3 4 5 6 7 8 9
441} {
442  1 2 3 4 5 6 9
443} {
444  1 2b 3b 4 5 6 7 8 9
445} {
446  1 2b 3b 4 5 6 9
447}
448merge-test 72 {
449  1 2 3 4 5 6 7 8 9
450} {
451  1 2 3 4 5 9
452} {
453  1 2b 3b 4b 5 6 7 8 9
454} {
455  1 2b 3b 4b 5 9
456}
457merge-test 73 {
458  1 2 3 4 5 6 7 8 9
459} {
460  1 2 3 4 5 9
461} {
462  1 2b 3b 4b 5b 6 7 8 9
463} {
464  1 2b 3b 4b 5b 9
465}
466merge-test 74 {
467  1 2 3 4 5 6 7 8 9
468} {
469  1 2 3 4 9
470} {
471  1 2b 3b 4b 5b 6 7 8 9
472} {
473  1 MINE: 2 3 4 COM: 2 3 4 5 6 7 8 YOURS: 2b 3b 4b 5b 6 7 8 END 9
474}
475merge-test 75 {
476  1 2 3 4 5 6 7 8 9
477} {
478  1 2 3 9
479} {
480  1 2b 3b 4b 5b 6b 7 8 9
481} {
482  1 MINE: 2 3 COM: 2 3 4 5 6 7 8 YOURS: 2b 3b 4b 5b 6b 7 8 END 9
483}
484
485merge-test 80 {
486  2 3 4 5 6 7 8
487} {
488  2b 3 4 5 6 7 8
489} {
490  2 3 4 5 6 7
491} {
492  2b 3 4 5 6 7
493}
494merge-test 81 {
495  2 3 4 5 6 7 8
496} {
497  2b 3b 4 5 6 7 8
498} {
499  2 3 4 5 6
500} {
501  2b 3b 4 5 6
502}
503merge-test 82 {
504  2 3 4 5 6 7 8
505} {
506  2b 3b 4b 5 6 7 8
507} {
508  2 3 4 5
509} {
510  2b 3b 4b 5
511}
512merge-test 83 {
513  2 3 4 5 6 7 8
514} {
515  2b 3b 4b 5b 6 7 8
516} {
517  2 3 4 5
518} {
519  2b 3b 4b 5b
520}
521merge-test 84 {
522  2 3 4 5 6 7 8
523} {
524  2b 3b 4b 5b 6 7 8
525} {
526  2 3 4
527} {
528  MINE: 2b 3b 4b 5b 6 7 8 COM: 2 3 4 5 6 7 8 YOURS: 2 3 4 END
529}
530merge-test 85 {
531  2 3 4 5 6 7 8
532} {
533  2b 3b 4b 5b 6b 7 8
534} {
535  2 3
536} {
537  MINE: 2b 3b 4b 5b 6b 7 8 COM: 2 3 4 5 6 7 8 YOURS: 2 3 END
538}
539
540merge-test 90 {
541  2 3 4 5 6 7 8
542} {
543  2 3 4 5 6 7
544} {
545  2b 3 4 5 6 7 8
546} {
547  2b 3 4 5 6 7
548}
549merge-test 91 {
550  2 3 4 5 6 7 8
551} {
552  2 3 4 5 6
553} {
554  2b 3b 4 5 6 7 8
555} {
556  2b 3b 4 5 6
557}
558merge-test 92 {
559  2 3 4 5 6 7 8
560} {
561  2 3 4 5
562} {
563  2b 3b 4b 5 6 7 8
564} {
565  2b 3b 4b 5
566}
567merge-test 93 {
568  2 3 4 5 6 7 8
569} {
570  2 3 4 5
571} {
572  2b 3b 4b 5b 6 7 8
573} {
574  2b 3b 4b 5b
575}
576merge-test 94 {
577  2 3 4 5 6 7 8
578} {
579  2 3 4
580} {
581  2b 3b 4b 5b 6 7 8
582} {
583  MINE: 2 3 4 COM: 2 3 4 5 6 7 8 YOURS: 2b 3b 4b 5b 6 7 8 END
584}
585merge-test 95 {
586  2 3 4 5 6 7 8
587} {
588  2 3
589} {
590  2b 3b 4b 5b 6b 7 8
591} {
592  MINE: 2 3 COM: 2 3 4 5 6 7 8 YOURS: 2b 3b 4b 5b 6b 7 8 END
593}
594
595merge-test 100 {
596  1 2 3 4 5 6 7 8 9
597} {
598  1 2b 3 4 5 7 8 9 a b c d e
599} {
600  1 2b 3 4 5 7 8 9 a b c d e
601} {
602  1 2b 3 4 5 7 8 9 a b c d e
603}
604merge-test 101 {
605  1 2 3 4 5 6 7 8 9
606} {
607  1 2b 3 4 5 7 8 9 a b c d e
608} {
609  1 2b 3 4 5 7 8 9
610} {
611  1 2b 3 4 5 7 8 9 a b c d e
612}
613merge-test 102 {
614  1 2 3 4 5 6 7 8 9
615} {
616  1 2b 3 4 5 7 8 9
617} {
618  1 2b 3 4 5 7 8 9 a b c d e
619} {
620  1 2b 3 4 5 7 8 9 a b c d e
621}
622merge-test 103 {
623  1 2 3 4 5 6 7 8 9
624} {
625  1 2 3 4 5 7 8 9b
626} {
627  1 2 3 4 5 7 8 9b a b c d e
628} {
629  1 2 3 4 5 7 8 MINE: 9b COM: 9 YOURS: 9b a b c d e END
630}
631merge-test 104 {
632  1 2 3 4 5 6 7 8 9
633} {
634  1 2 3 4 5 7 8 9b a b c d e
635} {
636  1 2 3 4 5 7 8 9b
637} {
638  1 2 3 4 5 7 8 MINE: 9b a b c d e COM: 9 YOURS: 9b END
639}
640
641###############################################################################
642
643test_cleanup
644