@@ -3,69 +3,82 @@ import * as Diff3 from '../index.mjs';
33
44test ( 'mergeDiff3' , t => {
55
6+ t . test ( 'returns conflict: false if no conflicts' , t => {
7+ const o = [ 'AA' ] ;
8+ const a = [ 'AA' ] ;
9+ const b = [ 'AA' ] ;
10+ const expected = [ 'AA' ] ;
11+
12+ const r = Diff3 . mergeDiff3 ( a , o , b ) ;
13+ t . notOk ( r . conflict ) ;
14+ t . same ( r . result , expected ) ;
15+ t . end ( ) ;
16+ } ) ;
17+
18+
619 t . test ( 'performs merge diff3 on arrays' , t => {
720 const o = [ 'AA' , 'ZZ' , '00' , 'M' , '99' ] ;
821 const a = [ 'AA' , 'a' , 'b' , 'c' , 'ZZ' , 'new' , '00' , 'a' , 'a' , 'M' , '99' ] ;
922 const b = [ 'AA' , 'a' , 'd' , 'c' , 'ZZ' , '11' , 'M' , 'z' , 'z' , '99' ] ;
10- const result = Diff3 . mergeDiff3 ( a , o , b , { label : { a : 'a' , o : 'o' , b : 'b' } } ) ;
23+ const expected = [
24+ 'AA' ,
25+ '<<<<<<< a' ,
26+ 'a' ,
27+ 'b' ,
28+ 'c' ,
29+ '||||||| o' ,
30+ '=======' ,
31+ 'a' ,
32+ 'd' ,
33+ 'c' ,
34+ '>>>>>>> b' ,
35+ 'ZZ' ,
36+ '<<<<<<< a' ,
37+ 'new' ,
38+ '00' ,
39+ 'a' ,
40+ 'a' ,
41+ '||||||| o' ,
42+ '00' ,
43+ '=======' ,
44+ '11' ,
45+ '>>>>>>> b' ,
46+ 'M' ,
47+ 'z' ,
48+ 'z' ,
49+ '99'
50+ ] ;
51+
52+ const r = Diff3 . mergeDiff3 ( a , o , b , { label : { a : 'a' , o : 'o' , b : 'b' } } ) ;
53+ t . ok ( r . conflict ) ;
54+ t . same ( r . result , expected ) ;
55+ t . end ( ) ;
56+ } ) ;
1157
12- /*
13- AA
14- <<<<<<< a
15- a
16- b
17- c
18- ||||||| o
19- =======
20- a
21- d
22- c
23- >>>>>>> b
24- ZZ
25- <<<<<<< a
26- new
27- 00
28- a
29- a
30- ||||||| o
31- 00
32- =======
33- 11
34- >>>>>>> b
35- M
36- z
37- z
38- 99
39- */
4058
41- t . same ( result . conflict , true ) ;
42- t . same ( result . result [ 0 ] , 'AA' ) ;
43- t . same ( result . result [ 1 ] , '<<<<<<< a' ) ;
44- t . same ( result . result [ 2 ] , 'a' ) ;
45- t . same ( result . result [ 3 ] , 'b' ) ;
46- t . same ( result . result [ 4 ] , 'c' ) ;
47- t . same ( result . result [ 5 ] , '||||||| o' ) ;
48- t . same ( result . result [ 6 ] , '=======' ) ;
49- t . same ( result . result [ 7 ] , 'a' ) ;
50- t . same ( result . result [ 8 ] , 'd' ) ;
51- t . same ( result . result [ 9 ] , 'c' ) ;
52- t . same ( result . result [ 10 ] , '>>>>>>> b' ) ;
53- t . same ( result . result [ 11 ] , 'ZZ' ) ;
54- t . same ( result . result [ 12 ] , '<<<<<<< a' ) ;
55- t . same ( result . result [ 13 ] , 'new' ) ;
56- t . same ( result . result [ 14 ] , '00' ) ;
57- t . same ( result . result [ 15 ] , 'a' ) ;
58- t . same ( result . result [ 16 ] , 'a' ) ;
59- t . same ( result . result [ 17 ] , '||||||| o' ) ;
60- t . same ( result . result [ 18 ] , '00' ) ;
61- t . same ( result . result [ 19 ] , '=======' ) ;
62- t . same ( result . result [ 20 ] , '11' ) ;
63- t . same ( result . result [ 21 ] , '>>>>>>> b' ) ;
64- t . same ( result . result [ 22 ] , 'M' ) ;
65- t . same ( result . result [ 23 ] , 'z' ) ;
66- t . same ( result . result [ 24 ] , 'z' ) ;
67- t . same ( result . result [ 25 ] , '99' ) ;
59+ t . test ( 'yaml comparison - issue #46' , t => {
60+ const o = `title: "title"
61+ description: "description"` ;
62+ const a = `title: "title"
63+ description: "description changed"` ;
64+ const b = `title: "title changed"
65+ description: "description"` ;
66+ const expected = [
67+ '<<<<<<< a' ,
68+ 'title: "title"' ,
69+ 'description: "description changed"' ,
70+ '||||||| o' ,
71+ 'title: "title"' ,
72+ 'description: "description"' ,
73+ '=======' ,
74+ 'title: "title changed"' ,
75+ 'description: "description"' ,
76+ '>>>>>>> b'
77+ ] ;
6878
79+ const r = Diff3 . mergeDiff3 ( a , o , b , { label : { a : 'a' , o : 'o' , b : 'b' } , stringSeparator : / [ \r \n ] + / } ) ;
80+ t . ok ( r . conflict ) ;
81+ t . same ( r . result , expected ) ;
6982 t . end ( ) ;
7083 } ) ;
7184
0 commit comments