import { TestBed, inject } from '@angular/core/testing';
import { DiffService, ModificationType } from './diff.service';
import { LinenumberingService } from './linenumbering.service';
describe('DiffService', () => {
const brMarkup = (no: number): string => {
return (
'
' +
' '
);
};
const noMarkup = (no: number): string => {
return (
' '
);
};
const baseHtml1 =
'
' +
noMarkup(1) +
'Line 1 ' +
brMarkup(2) +
'Line 2 ' +
brMarkup(3) +
'Line 3
' +
noMarkup(4) +
'Line 4 ' +
brMarkup(5) +
'Line 5
' + noMarkup(10) + 'Line 10 ' + brMarkup(11) + 'Line 11
'; let baseHtmlDom1: DocumentFragment; const baseHtml2 = '' + noMarkup(1) + 'Single text line
\' + noMarkup(2) + 'sdfsdfsdfsdf dsfsdfsdfdsflkewjrl ksjfl ksdjf klnlkjBavaria ipsum dolor sit amet Biazelt Auffisteign ' + brMarkup(3) + 'Schorsch mim Radl foahn Ohrwaschl Steckerleis wann griagd ma nacha wos z’dringa glacht Mamalad, ' + brMarkup(4) + 'muass? I bin a woschechta Bayer sowos oamoi und sei und glei wirds no fui lustiga: Jo mei khkhis des ' + brMarkup(5) + 'schee middn ognudelt, Trachtnhuat Biawambn gscheid: Griasd eich midnand etza nix Gwiass woass ma ned ' + brMarkup(6) + 'owe. Dahoam gscheckate middn Spuiratz des is a gmahde Wiesn. Des is schee so Obazda san da, Haferl ' + brMarkup(7) + 'pfenningguat schoo griasd eich midnand.
\' + noMarkup(14) + 'I waar soweid Blosmusi es nomoi. Broadwurschtbudn des is a gmahde Wiesn Kirwa mogsd a Bussal ' + brMarkup(15) + 'Guglhupf schüds nei. Luja i moan oiwei Baamwach Watschnbaam, wiavui baddscher! Biakriagal a fescha ' + brMarkup(16) + '1Bua Semmlkneedl iabaroi oba um Godds wujn Ledahosn wui Greichats. Geh um Godds wujn luja heid ' + brMarkup(17) + 'greaßt eich nachad woaß Breihaus eam! De om auf’n Gipfe auf gehds beim Schichtl mehra Baamwach a ' + brMarkup(18) + 'bissal wos gehd ollaweil gscheid:
\\\' + noMarkup(19) + 'Scheans Schdarmbeaga See i hob di narrisch gean i jo mei is des schee! Nia eam ' + brMarkup(20) + 'hod vasteh i sog ja nix, i red ja bloß sammawiedaguad, umma eana obandeln! Zwoa ' + brMarkup(21) + 'jo mei scheans amoi, san und hoggd Milli barfuaßat gscheit. Foidweg vui huift ' + brMarkup(22) + 'vui singan, mehra Biakriagal om auf’n Gipfe! Ozapfa sodala Charivari greaßt eich ' + brMarkup(23) + 'nachad Broadwurschtbudn do middn liberalitas Bavariae sowos Leonhardifahrt:
\
' + noMarkup(24) + 'Wui helfgod Wiesn, ognudelt schaugn: Dahoam gelbe Rüam Schneid singan wo hi sauba i moan scho aa no ' + brMarkup(25) + 'a Maß a Maß und no a Maß nimma. Is umananda a ganze Hoiwe zwoa, Schneid. Vui huift vui Brodzeid kumm ' + brMarkup(26) + 'geh naa i daad vo de allerweil, gor. Woaß wia Gams, damischa. A ganze Hoiwe Ohrwaschl Greichats ' + brMarkup(27) + 'iabaroi Prosd Engelgwand nix Reiwadatschi.Weibaleid ognudelt Ledahosn noch da Giasinga Heiwog i daad ' + brMarkup(28) + 'Almrausch, Ewig und drei Dog nackata wea ko, dea ko. Meidromml Graudwiggal nois dei, nackata. No ' + brMarkup(29) + 'Diandldrahn nix Gwiass woass ma ned hod boarischer: Samma sammawiedaguad wos, i hoam Brodzeid. Jo ' + brMarkup(30) + 'mei Sepp Gaudi, is ma Wuascht do Hendl Xaver Prosd eana an a bravs. Sauwedda an Brezn, abfieseln.
'; let baseHtmlDom2: DocumentFragment; const baseHtml3 = 'Line 1 '); expect(diff.outerContextStart).toBe(''); expect(diff.outerContextEnd).toBe(''); })); it('extracts lines from nested UL/LI-structures', inject([DiffService], (service: DiffService) => { const diff = service.extractRangeByLineNumbers(baseHtml1, 7, 9); expect(diff.html).toBe( 'Line 7
' + noMarkup(1) + 'Line 1
' + '' + noMarkup(2) + 'Line 2' + brMarkup(3) + 'Line 3' + brMarkup(4) + 'Line 5
' ); expect(diff.outerContextEnd).toBe('
' ); })); it('extracts lines from double-nested UL/LI-structures (2)', inject([DiffService], (service: DiffService) => { const html = '
' + noMarkup(1) + 'Line 1
' + '' + noMarkup(2) + 'Line 2' + brMarkup(3) + 'Line 3' + brMarkup(4) + '
Line 2' ); expect(diff.outerContextStart).toBe(''); expect(diff.outerContextEnd).toBe(''); expect(diff.innerContextStart).toBe(''); expect(diff.innerContextEnd).toBe('
'); })); it('extracts a single line right before a UL/LI', inject( [DiffService, LinenumberingService], (service: DiffService, lineNumbering: LinenumberingService) => { // Test case for https://github.com/OpenSlides/OpenSlides/issues/3226 let html = '
A line
Another line
\nAnother line
\n'); } )); it('extracts lines from a more complex example', inject([DiffService], (service: DiffService) => { const diff = service.extractRangeByLineNumbers(baseHtml2, 6, 11); expect(diff.html).toBe( 'owe. Dahoam gscheckate middn Spuiratz des is a gmahde Wiesn. Des is schee so Obazda san da, Haferl pfenningguat schoo griasd eich midnand.'); expect(diff.innerContextEnd).toBe('
'); expect(diff.innerContextEnd).toBe(''); expect(diff.previousHtmlEndSnippet).toBe('
'); expect(diff.followingHtml).toBe(''); expect(diff.followingHtmlStartSnippet).toBe(''); })); it('preserves the numbering of OLs (1)', inject([DiffService], (service: DiffService) => { const diff = service.extractRangeByLineNumbers(baseHtml3, 5, 7); expect(diff.html).toBe('' + noMarkup(2) + 'Another line
'; const diff = service.extractRangeByLineNumbers(inHtml, 1, 2); expect(diff.html).toBe('Replaced a UL by a P
', 6, 9); expect(merged).toBe( 'Line 1 Line 2 Line 3
Line 4 Line 5
Replaced a UL by a P
Line 10 Line 11
' ); })); it('replaces LIs by another LI', inject([DiffService], (service: DiffService) => { const merged = service.replaceLines(baseHtml1, 'Line 1 Line 2 Line 3
Line 4 Line 5
Line 10 Line 11
' ); })); it('breaks up a paragraph into two', inject([DiffService], (service: DiffService) => { const merged = service.replaceLines(baseHtml1, 'Replaced Line 10
Inserted Line 11
', 10, 11); expect(merged).toBe( 'Line 1 Line 2 Line 3
Line 4 Line 5
Replaced Line 10
Inserted Line 11 Line 11
' ); })); it('does not accidently merge two separate words', inject([DiffService], (service: DiffService) => { const merged = service.replaceLines(baseHtml1, 'Line 1INSERTION
', 1, 2), containsError = merged.indexOf('Line 1INSERTIONLine 2'), containsCorrectVersion = merged.indexOf('Line 1INSERTION Line 2'); expect(containsError).toBe(-1); expect(containsCorrectVersion).toBe(3); })); it('does not accidently merge two separate words, even in lists', inject( [DiffService], (service: DiffService) => { // The newlines between UL and LI are the problem here const merged = service.replaceLines( baseHtml1, '' + noMarkup(1) + 'foo & bar
', after = '' + noMarkup(1) + 'foo & bar ins
'; const merged = service.replaceLines(pre, after, 1, 2); expect(merged).toBe('foo & bar ins
'); })); }); describe('detecting the type of change', () => { it('detects a simple insertion', inject([DiffService], (service: DiffService) => { const htmlBefore = 'Test 1
', htmlAfter = 'Test 1 Test 2
' + '\n' + 'Test 3
'; const calculatedType = service.detectReplacementType(htmlBefore, htmlAfter); expect(calculatedType).toBe(ModificationType.TYPE_INSERTION); })); it('detects a simple insertion, ignoring case of tags', inject([DiffService], (service: DiffService) => { const htmlBefore = 'Test 1
', htmlAfter = 'Test 1 Test 2
' + '\n' + 'Test 3
'; const calculatedType = service.detectReplacementType(htmlBefore, htmlAfter); expect(calculatedType).toBe(ModificationType.TYPE_INSERTION); })); it('detects a simple insertion, ignoring trailing whitespaces', inject( [DiffService], (service: DiffService) => { const htmlBefore = 'Lorem ipsum dolor sit amet, sed diam voluptua. At
', htmlAfter = 'Lorem ipsum dolor sit amet, sed diam voluptua. At2
'; const calculatedType = service.detectReplacementType(htmlBefore, htmlAfter); expect(calculatedType).toBe(ModificationType.TYPE_INSERTION); } )); it('detects a simple insertion, ignoring spaces between UL and LI', inject( [DiffService], (service: DiffService) => { const htmlBefore = 'dsds dsfsdfsdf sdf sdfs dds sdf dsds dsfsdfsdf
', htmlAfter = 'dsds dsfsdfsdf sdf sdfs dds sd345 3453 45f dsds dsfsdfsdf
'; const calculatedType = service.detectReplacementType(htmlBefore, htmlAfter); expect(calculatedType).toBe(ModificationType.TYPE_INSERTION); })); it('detects a simple deletion', inject([DiffService], (service: DiffService) => { const htmlBefore = 'Test 1 Test 2
' + '\n' + 'Test 3
', htmlAfter = 'Test 1
'; const calculatedType = service.detectReplacementType(htmlBefore, htmlAfter); expect(calculatedType).toBe(ModificationType.TYPE_DELETION); })); it('detects a simple deletion, ignoring case of tags', inject([DiffService], (service: DiffService) => { const htmlBefore = 'Test 1 Test 2
' + '\n' + 'Test 3
', htmlAfter = 'Test 1
'; const calculatedType = service.detectReplacementType(htmlBefore, htmlAfter); expect(calculatedType).toBe(ModificationType.TYPE_DELETION); })); it('detects a simple deletion, ignoring trailing whitespaces', inject([DiffService], (service: DiffService) => { const htmlBefore = 'Lorem ipsum dolor sit amet, sed diam voluptua. At2
', htmlAfter = 'Lorem ipsum dolor sit amet, sed diam voluptua. At
'; const calculatedType = service.detectReplacementType(htmlBefore, htmlAfter); expect(calculatedType).toBe(ModificationType.TYPE_DELETION); })); it('detects a simple replacement', inject([DiffService], (service: DiffService) => { const htmlBefore = 'Test 1 Test 2
' + '\n' + 'Test 3
', htmlAfter = 'Test 1
' + '\n' + 'Test 2
' + '\n' + 'Test 3
'; const calculatedType = service.detectReplacementType(htmlBefore, htmlAfter); expect(calculatedType).toBe(ModificationType.TYPE_REPLACEMENT); })); }); describe('diff normalization', () => { it('uppercases normal HTML tags', inject([DiffService], (service: DiffService) => { const unnormalized = 'The brown fox', normalized = service.normalizeHtmlForDiff(unnormalized); expect(normalized).toBe('The brown fox'); })); it('uppercases the names of html attributes, but not the values, and sort the attributes', inject( [DiffService], (service: DiffService) => { const unnormalized = 'This is our cool home page - have a look! ' + '', normalized = service.normalizeHtmlForDiff(unnormalized); expect(normalized).toBe( 'This is our cool home page - have a look! ' + '' ); } )); it('strips unnecessary spaces', inject([DiffService], (service: DiffService) => { const unnormalized = 'Test
", normalized = service.normalizeHtmlForDiff(unnormalized); expect(normalized).toBe("Test
"); })); it('treats newlines like spaces', inject([DiffService], (service: DiffService) => { const unnormalized = 'Test line\n\t 2
', normalized = service.normalizeHtmlForDiff(unnormalized); expect(normalized).toBe('Test line 2
'); })); }); describe('the core diff algorithm', () => { it('acts as documented by the official documentation', inject([DiffService], (service: DiffService) => { const before = 'The red brown fox jumped over the rolling log.', after = 'The brown spotted fox leaped over the rolling log.'; const diff = service.diff(before, after); expect(diff).toBe( 'The' + noMarkup(1) + 'Hendl Kirwa hod Maßkruag
' + noMarkup(2) + 'gmahde Wiesn
Hendl Kirwa hod Maßkruag
\ngmahde Wiesn
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
', after = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
\n' + '\n' + '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.
'; const diff = service.diff(before, after); expect(diff).toBe( 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
\n' + '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.
' ); } )); it('does not result in separate paragraphs when only the first word has changed', inject( [DiffService], (service: DiffService) => { const before = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
', after = 'Bla ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
'; const diff = service.diff(before, after); expect(diff).toBe( ' LoremBla ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
Test1 Test2
", after = "Test1 Test2
"; const diff = service.diff(before, after); expect(diff).toBe('Test1 Test2
Test1 Test2
'); })); it('handles inserted paragraphs', inject([DiffService], (service: DiffService) => { const before = "liebliche Stimme, aber deine Stimme ist rauh; du bist der Wolf.' Da gieng der
", after = "liebliche Stimme, aber deine Stimme ist rauh; du bist der Wolf.'
\ \Der Wolf hatte danach richtig schlechte laune, trank eine Flasche Rum,
\ \machte eine Weltreise und kam danach wieder um die Ziegen zu fressen. Da ging der
", expected = 'liebliche Stimme, aber deine Stimme ist rauh; du bist der Wolf.\' Da gieng der
' + 'liebliche Stimme, aber deine Stimme ist rauh; du bist der Wolf.\'
' + 'Der Wolf hatte danach richtig schlechte laune, trank eine Flasche Rum,
' + 'machte eine Weltreise und kam danach wieder um die Ziegen zu fressen. Da ging der
'; const diff = service.diff(before, after); expect(diff).toBe(expected); })); it('handles inserted paragraphs (2)', inject([DiffService], (service: DiffService) => { // Specifically, Noch should not be enclosed by ..., as Noch would be seriously broken const before = "rief sie alle sieben herbei und sprach 'liebe Kinder, ich will hinaus in den Wald, seid
", after = "rief sie alle sieben herbei und sprach 'liebe Kinder, ich will hinaus in den Wald, seid Noch
" + 'Test 123
', expected = "rief sie alle sieben herbei und sprach 'liebe Kinder, ich will hinaus in den Wald, seid Noch
" + 'Test 123
'; const diff = service.diff(before, after); expect(diff).toBe(expected); })); it('handles insterted paragraphs (3)', inject([DiffService], (service: DiffService) => { // Hint: os-split-after should be moved from the first paragraph to the second one const before = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
', after = '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.
\n' + '\n' + 'Stet clita kasd gubergren, no sea takimata sanctus est.
', expected = '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.
\n' + 'Stet clita kasd gubergren, no sea takimata sanctus est.
'; const diff = service.diff(before, after); expect(diff).toBe(expected); })); it('handles inserted paragraphs (4)', inject([DiffService], (service: DiffService) => { const before = 'This is a random first line that remains unchanged.
', after = 'This is a random first line that remains unchanged.
' + 'Inserting this line should not make any troubles, especially not affect the first line
' + 'Neither should this line
', expected = 'This is a random first line that remains unchanged.
' + 'Inserting this line should not make any troubles, especially not affect the first line
' + 'Neither should this line
'; const diff = service.diff(before, after); expect(diff).toBe(expected); })); it('handles completely deleted paragraphs', inject([DiffService], (service: DiffService) => { const before = "Ihr könnt ohne Sorge fortgehen.'Da meckerte die Alte und machte sich getrost auf den Weg.
", after = ''; const diff = service.diff(before, after); expect(diff).toBe( 'Ihr könnt ohne Sorge fortgehen.\'Da meckerte die Alte und machte sich getrost auf den Weg.
' ); })); it('does not repeat the last word (1)', inject([DiffService], (service: DiffService) => { const before = 'sem. Nulla consequat massa quis enim.
', after = 'sem. Nulla consequat massa quis enim. TEST
\nTEST
sem. Nulla consequat massa quis enim. TEST
TEST
...so frißt er Euch alle mit Haut und Haar.
', after = '...so frißt er Euch alle mit Haut und Haar und Augen und Därme und alles.
'; const diff = service.diff(before, after); expect(diff).toBe( '...so frißt er Euch alle mit Haut und Haar und Augen und Därme und alles.
' ); })); it('does not break when an insertion followes a beginning tag occuring twice', inject( [DiffService], (service: DiffService) => { const before = '...so frißt er Euch alle mit Haut und Haar.
\nTest
', after = 'Einfügung 1 ...so frißt er Euch alle mit Haut und Haar und Augen und Därme und alles.
\nTest
'; const diff = service.diff(before, after); expect(diff).toBe( 'Einfügung 1 ...so frißt er Euch alle mit Haut und Haar und Augen und Därme und alles.
\nTest
' ); } )); it('does not lose formattings when multiple lines are deleted', inject( [DiffService], (service: DiffService) => { const before = '' + noMarkup(13) + 'diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd ' + brMarkup(14) + 'gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
', after = 'Test
'; const diff = service.diff(before, after).toLowerCase(), expected = '' +
noMarkup(13) +
'diam voluptua. at vero eos et accusam et justo duo dolores et ea rebum. stet clita kasd ' +
brMarkup(14) +
'gubergren, no sea takimata sanctus est lorem ipsum dolor sit amet.' +
'test
...so frißt er Euch alle mit Haut und Haar.
', after = "...so frißt er Euch alle mit Haut und Haar.
"; const diff = service.diff(before, after); expect(diff).toBe( '...so frißt er Euch alle mit Haut und Haar.
...so frißt er Euch alle mit Haut und Haar.
' ); })); it('removed inline colors in inserted/deleted parts (2)', inject([DiffService], (service: DiffService) => { const before = '...so frißt er Euch alle mit Haut und Haar.
', after = "...so frißt er Euch alle mit Haut und Haar.
"; const diff = service.diff(before, after); expect(diff).toBe( '...so frißt er Euch alle mit Haut und Haar.
...so frißt er Euch alle mit Haut und Haar.
' ); })); it('marks a single moved word as deleted and inserted again', inject([DiffService], (service: DiffService) => { const before = '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.
', after = '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.
'; const diff = service.diff(before, after); expect(diff).toBe( '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 gubergren sit amet.
sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing
', after = 'sanctus est Lorem ipsum dolor sit amet. Test Lorem ipsum dolor sit amet, consetetur sadipscing
'; const diff = service.diff(before, after); expect(diff).toBe( 'sanctus est Lorem ipsum dolor sit amet. Test Lorem ipsum dolor sit amet, consetetur sadipscing
' ); })); it('does not lose words when changes are moved X-wise', inject([DiffService], (service: DiffService) => { const before = 'elitr. einsetzt. VERSCHLUCKT noch die sog. Gleichbleibend (Wird gelöscht).', after = 'elitr, Einfügung durch Änderung der Gleichbleibend, einsetzt.'; const diff = service.diff(before, after); expect(diff).toBe( 'elitrLorem ipsum dolor sit amet, consetetur
sadipscing elitr.
Bavaria ipsum dolor sit amet o’ha wea nia ausgähd
kummt nia hoam i hob di narrisch gean
Lorem ipsum dolor sit amet, consetetur sadipscing elitr. Sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua..
\n' +
'Bavaria ipsum dolor sit amet o’ha wea nia ausgähd
\n' +
'Autonomie erfährt ihre Grenzen
Lorem ipsum dolor sit amet, consetetur sadipscing elitr. Sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua..
Bavaria ipsum dolor sit amet o’ha wea nia ausgähdkummt nia hoam i hob di narrisch geanAutonomie erfährt ihre Grenzen
This is the text before
', after = "This is the text before
\nThis is one added line
\nAnother added line
"; const diff = service.diff(before, after); expect(diff).toBe("This is the text before
\nThis is one added line
\nAnother added line
"); } )); it('does not a change in a very specific case', inject([DiffService], (service: DiffService) => { // See diff._fixWrongChangeDetection const inHtml = 'Test 123
wir strikt ab. lehnen wir ' +
brMarkup(1486) +
'ab.
' +
noMarkup(1487) +
'Gegenüber
Test 123
\n' + 'wir strikt ab. lehnen wir ab.
\n' + 'Gegenüber
Test 123
wir strikt ab. lehnen wir ' +
brMarkup(1486) +
'ab.
' +
noMarkup(1487) +
'Gegenüber
...so frißt er Euch alle mit Haut und Haar.
'; const after = '...so frißt er Euch alle mit Haut und Haar und Augen und Därme und alles.
'; before = lineNumbering.insertLineNumbers(before, 15, null, null, 2); const diff = service.diff(before, after); expect(diff).toBe( '' + noMarkup(2) + '...so frißt er ' + brMarkup(3) + 'Euch alle mit ' + brMarkup(4) + 'Haut und Haar und Augen und Därme und alles.
' ); } )); it('works with an inserted paragraph', inject( [DiffService, LinenumberingService], (service: DiffService, lineNumbering: LinenumberingService) => { let before = 'their grammar, their pronunciation and their most common words. Everyone realizes why a
'; const after = 'their grammar, their pronunciation and their most common words. Everyone realizes why a
\n' + 'NEW PARAGRAPH 2.
'; before = lineNumbering.insertLineNumbers(before, 80, null, null, 2); const diff = service.diff(before, after); expect(diff).toBe( '' + noMarkup(2) + 'their grammar, their pronunciation and their most common words. Everyone ' + brMarkup(3) + 'realizes why a
\n' + 'NEW PARAGRAPH 2.
' ); } )); it('works with two inserted paragraphs', inject( [DiffService, LinenumberingService], (service: DiffService, lineNumbering: LinenumberingService) => { // Hint: If the last paragraph is a P again, the Diff still fails and falls back to paragraph-based diff // This leaves room for future improvements let before = 'their grammar, their pronunciation and their most common words. Everyone realizes why a
\ntheir grammar, their pronunciation and their most common words. Everyone realizes why a
\n' + 'NEW PARAGRAPH 1.
\n' + 'NEW PARAGRAPH 2.
\n' + '' + noMarkup(2) + 'their grammar, their pronunciation and their most common words. Everyone ' + brMarkup(3) + 'realizes why a
\n' + 'NEW PARAGRAPH 1.
\n' + 'NEW PARAGRAPH 2.
\n' + 'At vero eos et accusam et justo duo dolores et ea rebum.
\nAt vero eos et accusam et justo duo dolores et ea rebum.
\nholen, da rief sie alle sieben herbei und sprach:
\n\n "Liebe Kinder, ich will hinaus in den Wald, seid auf der Hut vor dem Wolf! Wenn er
hereinkommt, frisst er euch alle mit Haut und Haar. Der Bösewicht verstellt sich oft, aber
an der rauen Stimme und an seinen schwarzen Füßen werdet ihr ihn schon erkennen."
Die Geißlein sagten: " Liebe Mutter, wir wollen uns schon in acht nehmen, du kannst ohne
', after = 'holen, da rief sie alle sieben herbei und sprach:
\n\nHello
\n\nWorld
\n\nYa
\n\nDie Geißlein sagten: " Liebe Mutter, wir wollen uns schon in acht nehmen, du kannst ohne
'; const diff = service.diff(before, after); expect(diff).toBe( 'holen, da rief sie alle sieben herbei und sprach:
"Liebe Kinder, ich will hinaus in den Wald, seid auf der Hut vor dem Wolf! Wenn er
hereinkommt, frisst er euch alle mit Haut und Haar. Der Bösewicht verstellt sich oft, aber
an der rauen Stimme und an seinen schwarzen Füßen werdet ihr ihn schon erkennen."
Die Geißlein sagten: " Liebe Mutter, wir wollen uns schon in acht nehmen, du kannst ohne
' + 'holen, da rief sie alle sieben herbei und sprach:
\n\n' + 'Hello
\n\n' + 'World
\n\n' + 'Ya
\n\n' + 'Die Geißlein sagten: " Liebe Mutter, wir wollen uns schon in acht nehmen, du kannst ohne
' ); })); it('line breaks at dashes does not delete/insert the last/first word of the split lines', inject( [DiffService, LinenumberingService], (service: DiffService, lineNumbering: LinenumberingService) => { let before = '' + noMarkup(1) + 'foo & bar' + brMarkup(2) + 'Another line' + brMarkup(3) + 'This will be changed' + brMarkup(4) + 'This, too' + brMarkup(5) + 'End
', after = '' + noMarkup(1) + 'foo & bar' + brMarkup(2) + 'Another line' + brMarkup(3) + 'This has been changed' + brMarkup(4) + 'End
'; const diff = service.diff(before, after); const affected = service.detectAffectedLineRange(diff); expect(affected).toEqual({ from: 3, to: 5 }); })); it('detects changed line numbers at the beginning', inject( [DiffService, LinenumberingService], (service: DiffService, lineNumbering: LinenumberingService) => { let before = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat
'; const after = 'sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat
'; before = lineNumbering.insertLineNumbers(before, 20); const diff = service.diff(before, after); const affected = service.detectAffectedLineRange(diff); expect(affected).toEqual({ from: 1, to: 2 }); } )); }); describe('stripping ins/del-styles/tags', () => { it('deletes to be deleted nodes', inject([DiffService], (service: DiffService) => { const inHtml = 'Test Test 2 Another test Test 3
Test 4
'; const stripped = service.diffHtmlToFinalText(inHtml); expect(stripped).toBe('Test Another test
'); })); it('produces empty paragraphs, if necessary', inject([DiffService], (service: DiffService) => { const inHtml = 'Test Test 2 Another test Test 3
Test 4
'; const stripped = service.diffHtmlToFinalText(inHtml); expect(stripped).toBe(''); })); it('Removes INS-tags', inject([DiffService], (service: DiffService) => { const inHtml = 'Test Test 2 Another test
'; const stripped = service.diffHtmlToFinalText(inHtml); expect(stripped).toBe('Test Test 2 Another test
'); })); it('Removes .insert-classes', inject([DiffService], (service: DiffService) => { const inHtml = 'Test 1
Test 2
'; const stripped = service.diffHtmlToFinalText(inHtml); expect(stripped).toBe('Test 1
Test 2
'); })); }); });