'owe. Dahoam gscheckate middn Spuiratz des is a gmahde Wiesn. Des is schee so Obazda san da, Haferl pfenningguat schoo griasd eich midnand.</P><UL class="os-split-after"><LI>Auffi Gamsbart nimma de Sepp Ledahosn Ohrwaschl um Godds wujn Wiesn Deandlgwand Mongdratzal! Jo leck mi Mamalad i daad mechad?</LI><LI>Do nackata Wurscht i hob di narrisch gean, Diandldrahn Deandlgwand vui huift vui woaß?</LI>'
'Diandldrahn nix Gwiass woass ma ned hod boarischer: Samma sammawiedaguad wos, i hoam Brodzeid. Jo mei Sepp Gaudi, is ma Wuascht do Hendl Xaver Prosd eana an a bravs. Sauwedda an Brezn, abfieseln.</P>'
describe('replacing lines in the original motion',()=>{
it('replaces LIs by a P',inject([DiffService],(service: DiffService)=>{
constmerged=service.replaceLines(baseHtml1,'<p>Replaced a UL by a P</p>',6,9);
expect(merged).toBe(
'<P>Line 1 Line 2 Line <STRONG>3<BR>Line 4 Line</STRONG> 5</P><P>Replaced a UL by a P</P><UL class="ul-class"><LI class="li-class"><UL><LI>Level 2 LI 9</LI></UL></LI></UL><P>Line 10 Line 11</P>'
);
}));
it('replaces LIs by another LI',inject([DiffService],(service: DiffService)=>{
constmerged=service.replaceLines(baseHtml1,'<UL class="ul-class"><LI>A new LI</LI></UL>',6,9);
expect(merged).toBe(
'<P>Line 1 Line 2 Line <STRONG>3<BR>Line 4 Line</STRONG> 5</P><UL class="ul-class"><LI>A new LI<UL><LI>Level 2 LI 9</LI></UL></LI></UL><P>Line 10 Line 11</P>'
);
}));
it('breaks up a paragraph into two',inject([DiffService],(service: DiffService)=>{
constmerged=service.replaceLines(baseHtml1,'<P>Replaced Line 10</P><P>Inserted Line 11 </P>',10,11);
expect(merged).toBe(
'<P>Line 1 Line 2 Line <STRONG>3<BR>Line 4 Line</STRONG> 5</P><UL class="ul-class"><LI class="li-class">Line 6 Line 7</LI><LI class="li-class"><UL><LI>Level 2 LI 8</LI><LI>Level 2 LI 9</LI></UL></LI></UL><P>Replaced Line 10</P><P>Inserted Line 11 Line 11</P>'
);
}));
it('does not accidently merge two separate words',inject([DiffService],(service: DiffService)=>{
it('does not mark the last line of a paragraph as change if a long new one is appended',inject(
[DiffService],
(service: DiffService)=>{
constbefore=
'<p><span class="os-line-number line-number-5" data-line-number="5" contenteditable="false"> </span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>',
after=
'<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>\n'+
'\n'+
'<p>Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</p>';
constdiff=service.diff(before,after);
expect(diff).toBe(
'<p><span class="line-number-5 os-line-number" contenteditable="false" data-line-number="5"> </span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>\n'+
'<p class="insert">Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</p>'
it('detects insertions and deletions in a word (2)',inject([DiffService],(service: DiffService)=>{
constbefore='Test Test',
after='Test Testappend';
constdiff=service.diff(before,after);
expect(diff).toBe('Test Test<ins>append</ins>');
}));
it('recognizes commas as a word separator',inject([DiffService],(service: DiffService)=>{
constbefore=
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat',
after=
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat';
constdiff=service.diff(before,after);
expect(diff).toBe(
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr<del> sed</del><ins>,</ins> diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat'
// Hint: os-split-after should be moved from the first paragraph to the second one
constbefore=
'<p class="os-split-after"><span class="os-line-number line-number-1" data-line-number="1" contenteditable="false"> </span>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, </p>',
after=
'<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.</p>\n'+
'\n'+
'<p>Stet clita kasd gubergren, no sea takimata sanctus est.</p>',
expected=
'<p><span class="line-number-1 os-line-number" contenteditable="false" data-line-number="1"> </span>Lorem ipsum dolor sit amet, consetetur sadipscing elitr,<ins> sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.</ins></p>\n'+
constbefore='<p>This is a random first line that remains unchanged.</p>',
after=
'<p>This is a random first line that remains unchanged.</p>'+
'<p style="text-align: justify;"><span style="color: #000000;">Inserting this line should not make any troubles, especially not affect the first line</span></p>'+
'<p style="text-align: justify;"><span style="color: #000000;">Neither should this line</span></p>',
expected=
'<p>This is a random first line that remains unchanged.</p>'+
'<p style="text-align: justify;" class="insert"><span style="color: #000000;">Inserting this line should not make any troubles, especially not affect the first line</span></p>'+
'<p style="text-align: justify;" class="insert"><span style="color: #000000;">Neither should this line</span></p>';
it('does not like splitting paragraphs too much, but respects line breaks between paragraphs',inject(
[DiffService],
(service: DiffService)=>{
constbefore=
'<P>Bavaria ipsum dolor sit amet o’ha wea nia ausgähd, kummt nia hoam i hob di narrisch gean helfgod ebba ded baddscher. Des so so, nia Biawambn back mas? Kaiwe Hetschapfah Trachtnhuat, a bravs.</P>',
after=
'<p>Bavaria ipsum dolor sit amet o’ha wea nia ausgähd, kummt nia hoam i hob di narrisch gean helfgod ebba ded baddscher.</p>\n<p>Des so so, nia Biawambn back mas? Kaiwe Hetschapfah Trachtnhuat, a bravs.';
constdiff=service.diff(before,after);
expect(diff).toBe(
'<P class="delete">Bavaria ipsum dolor sit amet o’ha wea nia ausgähd, kummt nia hoam i hob di narrisch gean helfgod ebba ded baddscher. Des so so, nia Biawambn back mas? Kaiwe Hetschapfah Trachtnhuat, a bravs.</P>'+
'<P class="insert">Bavaria ipsum dolor sit amet o’ha wea nia ausgähd, kummt nia hoam i hob di narrisch gean helfgod ebba ded baddscher.</P>'+
'<INS>\n</INS>'+
'<P class="insert">Des so so, nia Biawambn back mas? Kaiwe Hetschapfah Trachtnhuat, a bravs.</P>'
'<del>diam voluptua. at vero eos et accusam et justo duo dolores et ea rebum. stet clita kasd </del>'+
brMarkup(14)+
'<del>gubergren, no sea takimata sanctus est lorem ipsum dolor sit amet.</del>'+
'<ins>test</ins></p>';
expect(diff).toBe(expected.toLowerCase());
}
));
it('removed inline colors in inserted/deleted parts (1)',inject([DiffService],(service: DiffService)=>{
constbefore='<P>...so frißt er Euch alle mit Haut und Haar.</P>',
after="<P>...so frißt er <span style='color: #000000;'>Euch alle</span> mit Haut und Haar.</P>";
constdiff=service.diff(before,after);
expect(diff).toBe(
'<P class="delete">...so frißt er Euch alle mit Haut und Haar.</P><P class="insert">...so frißt er <SPAN>Euch alle</SPAN> mit Haut und Haar.</P>'
);
}));
it('removed inline colors in inserted/deleted parts (2)',inject([DiffService],(service: DiffService)=>{
constbefore='<P>...so frißt er Euch alle mit Haut und Haar.</P>',
after=
"<P>...so frißt er <span style='font-size: 2em; color: #000000; opacity: 0.5'>Euch alle</span> mit Haut und Haar.</P>";
constdiff=service.diff(before,after);
expect(diff).toBe(
'<P class="delete">...so frißt er Euch alle mit Haut und Haar.</P><P class="insert">...so frißt er <SPAN style="font-size: 2em; opacity: 0.5">Euch alle</SPAN> mit Haut und Haar.</P>'
);
}));
it('marks a single moved word as deleted and inserted again',inject([DiffService],(service: DiffService)=>{
constbefore=
'<p>tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren bla, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>',
after=
'<p>tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd bla, no sea takimata sanctus est Lorem ipsum dolor gubergren sit amet.</p>';
constdiff=service.diff(before,after);
expect(diff).toBe(
'<p>tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd <del>gubergren </del>bla, no sea takimata sanctus est Lorem ipsum dolor <ins>gubergren </ins>sit amet.</p>'
);
}));
it('works with style-tags in spans',inject([DiffService],(service: DiffService)=>{
constbefore=
'<p class="os-split-before os-split-after"><span class="os-line-number line-number-4" data-line-number="4" contenteditable="false"> </span><span style="color: #0000ff;" class="os-split-before os-split-after">sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing </span></p>',
after=
'<p class="os-split-after os-split-before"><span class="os-split-after os-split-before" style="color: #0000ff;">sanctus est Lorem ipsum dolor sit amet. Test Lorem ipsum dolor sit amet, consetetur sadipscing </span></p>';
constdiff=service.diff(before,after);
expect(diff).toBe(
'<p class="os-split-after os-split-before"><span class="line-number-4 os-line-number" contenteditable="false" data-line-number="4"> </span><span class="os-split-after os-split-before" style="color: #0000ff;">sanctus est Lorem ipsum dolor sit amet. <ins>Test </ins>Lorem ipsum dolor sit amet, consetetur sadipscing </span></p>'
);
}));
it('does not lose words when changes are moved X-wise',inject([DiffService],(service: DiffService)=>{
constbefore='elitr. einsetzt. VERSCHLUCKT noch die sog. Gleichbleibend (Wird gelöscht).',
after='elitr, Einfügung durch Änderung der Gleichbleibend, einsetzt.';
constdiff=service.diff(before,after);
expect(diff).toBe(
'elitr<del>. einsetzt. VERSCHLUCKT noch die sog.</del><ins>, Einfügung durch Änderung der</ins> Gleichbleibend<del> (Wird gelöscht).</del><ins>, einsetzt.</ins>'
);
}));
it('does not fall back to block level replacement when BRs are inserted/deleted',inject(
[DiffService],
(service: DiffService)=>{
constbefore=
'<p>Lorem ipsum dolor sit amet, consetetur <br>sadipscing elitr.<br>Bavaria ipsum dolor sit amet o’ha wea nia ausgähd<br>kummt nia hoam i hob di narrisch gean</p>',
after=
'<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr. Sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua..<br>\n'+
'Bavaria ipsum dolor sit amet o’ha wea nia ausgähd<br>\n'+
'Autonomie erfährt ihre Grenzen</p>';
constdiff=service.diff(before,after);
expect(diff).toBe(
'<p>Lorem ipsum dolor sit amet, consetetur <del><br></del>sadipscing elitr.<ins> Sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua..</ins><br>Bavaria ipsum dolor sit amet o’ha wea nia ausgähd<br><del>kummt nia hoam i hob di narrisch gean</del><ins>Autonomie erfährt ihre Grenzen</ins></p>'
'<ul class="os-split-before"><li>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</li>\n'+
'<li>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</li>\n'+
'<li class="testclass">At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</li>\n'+
'<li>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</li>'+
'<li class="testclass insert">At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</li>'+
it('detects broken HTML and lowercases class names',inject([DiffService],(service: DiffService)=>{
constbefore=
'<p><span class="line-number-3 os-line-number" data-line-number="3" contenteditable="false"> </span>holen, da rief sie alle sieben herbei und sprach:</p>\n\n<p><span class="line-number-4 os-line-number" data-line-number="4" contenteditable="false"> </span><span style="color: #000000;">"Liebe Kinder, ich will hinaus in den Wald, seid auf der Hut vor dem Wolf! Wenn er <br class="os-line-break"><span class="line-number-5 os-line-number" data-line-number="5" contenteditable="false"> </span>hereinkommt, frisst er euch alle mit Haut und Haar. Der Bösewicht verstellt sich oft, aber <br class="os-line-break"><span class="line-number-6 os-line-number" data-line-number="6" contenteditable="false"> </span>an der rauen Stimme und an seinen schwarzen Füßen werdet ihr ihn schon erkennen."</span></p>\n\n<p><span class="line-number-7 os-line-number" data-line-number="7" contenteditable="false"> </span>Die Geißlein sagten: " Liebe Mutter, wir wollen uns schon in acht nehmen, du kannst ohne </p>',
after=
'<p>holen, da rief sie alle sieben herbei und sprach:</p>\n\n<p><span style="color: #000000;">Hello</span></p>\n\n<p><span style="color: #000000;">World</span></p>\n\n<p><span style="color: #000000;">Ya</span></p>\n\n<p>Die Geißlein sagten: " Liebe Mutter, wir wollen uns schon in acht nehmen, du kannst ohne</p>';
constdiff=service.diff(before,after);
expect(diff).toBe(
'<P class="delete"><SPAN class="line-number-3 os-line-number" data-line-number="3" contenteditable="false"></SPAN>holen, da rief sie alle sieben herbei und sprach:</P><DEL>\n\n</DEL>'+
'<P class="delete"><SPAN class="line-number-4 os-line-number" data-line-number="4" contenteditable="false"></SPAN><SPAN>"Liebe Kinder, ich will hinaus in den Wald, seid auf der Hut vor dem Wolf! Wenn er <BR class="os-line-break"><SPAN class="line-number-5 os-line-number" data-line-number="5" contenteditable="false"></SPAN>hereinkommt, frisst er euch alle mit Haut und Haar. Der Bösewicht verstellt sich oft, aber <BR class="os-line-break"><SPAN class="line-number-6 os-line-number" data-line-number="6" contenteditable="false"></SPAN>an der rauen Stimme und an seinen schwarzen Füßen werdet ihr ihn schon erkennen."</SPAN></P><DEL>\n\n</DEL><P class="delete"><SPAN class="line-number-7 os-line-number" data-line-number="7" contenteditable="false"></SPAN>Die Geißlein sagten: " Liebe Mutter, wir wollen uns schon in acht nehmen, du kannst ohne </P>'+
'<P class="insert">holen, da rief sie alle sieben herbei und sprach:</P><INS>\n\n</INS>'+
'<ul><li>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy ei rmodtem-Porinv idunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</li></ul>';
constafter=
'<ul><li>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy ei rmodtem-Porinv idunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</li></ul>';
'<ul class="os-split-before os-split-after"><li class="os-split-before"><ul class="os-split-before os-split-after"><li class="os-split-before">...here it goes on</li><li class="os-split-before">This has been added</li></ul></li></ul>',
'<UL class="os-split-before os-split-after"><LI class="os-split-before"><UL class="os-split-before os-split-after"><LI class="os-split-before">...here it goes on</LI><LI>This has been added</LI></UL></LI></UL>'
);
}));
});
describe('detecting changed line number range',()=>{
it('detects changed line numbers in the middle',inject([DiffService],(service: DiffService)=>{