describe('linenumbering', function () {
beforeEach(module('OpenSlidesApp.motions.diff'));
var diffService, baseHtml1, baseHtmlDom1, baseHtml2, baseHtmlDom2, baseHtml3, baseHtmlDom3,
brMarkup = function (no) {
return '
' +
' ';
},
noMarkup = function (no) {
return ' ';
};
beforeEach(inject(function (_diffService_) {
diffService = _diffService_;
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
'; baseHtmlDom1 = diffService.htmlToFragment(baseHtml1); 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.
'; baseHtmlDom2 = diffService.htmlToFragment(baseHtml2); baseHtml3 = 'Line 1 '); expect(diff.outerContextStart).toBe(''); expect(diff.outerContextEnd).toBe(''); }); it('extracts lines from nested UL/LI-structures', function () { var diff = diffService.extractRangeByLineNumbers(baseHtml1, 7, 9); expect(diff.html).toBe('Line 7
'); 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)', function () { var diff = diffService.extractRangeByLineNumbers(baseHtml3, 5, 7, true); 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', function () { var merged = diffService.replaceLines(baseHtml1, 'Line 1 Line 2 Line 3
Line 4 Line 5
Line 10 Line 11
'); }); it('breaks up a paragraph into two', function() { var merged = diffService.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', function() { var merged = diffService.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', function() { // The newlines between UL and LI are the problem here var merged = diffService.replaceLines(baseHtml1, 'Test 1
', htmlAfter = 'Test 1 Test 2
' + "\n" + 'Test 3
'; var calculatedType = diffService.detectReplacementType(htmlBefore, htmlAfter); expect(calculatedType).toBe(diffService.TYPE_INSERTION); }); it('detects a simple insertion, ignoring case of tags', function () { var htmlBefore = 'Test 1
', htmlAfter = 'Test 1 Test 2
' + "\n" + 'Test 3
'; var calculatedType = diffService.detectReplacementType(htmlBefore, htmlAfter); expect(calculatedType).toBe(diffService.TYPE_INSERTION); }); it('detects a simple insertion, ignoring trailing whitespaces', function () { var htmlBefore = 'Lorem ipsum dolor sit amet, sed diam voluptua. At
', htmlAfter = 'Lorem ipsum dolor sit amet, sed diam voluptua. At2
'; var calculatedType = diffService.detectReplacementType(htmlBefore, htmlAfter); expect(calculatedType).toBe(diffService.TYPE_INSERTION); }); it('detects a simple insertion, ignoring spaces between UL and LI', function () { var htmlBefore = 'dsds dsfsdfsdf sdf sdfs dds sdf dsds dsfsdfsdf
', htmlAfter = 'dsds dsfsdfsdf sdf sdfs dds sd345 3453 45f dsds dsfsdfsdf
'; var calculatedType = diffService.detectReplacementType(htmlBefore, htmlAfter); expect(calculatedType).toBe(diffService.TYPE_INSERTION); }); it('detects a simple deletion', function () { var htmlBefore = 'Test 1 Test 2
' + "\n" + 'Test 3
', htmlAfter = 'Test 1
'; var calculatedType = diffService.detectReplacementType(htmlBefore, htmlAfter); expect(calculatedType).toBe(diffService.TYPE_DELETION); }); it('detects a simple deletion, ignoring case of tags', function () { var htmlBefore = 'Test 1 Test 2
' + "\n" + 'Test 3
', htmlAfter = 'Test 1
'; var calculatedType = diffService.detectReplacementType(htmlBefore, htmlAfter); expect(calculatedType).toBe(diffService.TYPE_DELETION); }); it('detects a simple deletion, ignoring trailing whitespaces', function () { var htmlBefore = 'Lorem ipsum dolor sit amet, sed diam voluptua. At2
', htmlAfter = 'Lorem ipsum dolor sit amet, sed diam voluptua. At
'; var calculatedType = diffService.detectReplacementType(htmlBefore, htmlAfter); expect(calculatedType).toBe(diffService.TYPE_DELETION); }); it('detects a simple replacement', function () { var htmlBefore = 'Test 1 Test 2
' + "\n" + 'Test 3
', htmlAfter = 'Test 1
' + "\n" + 'Test 2
' + "\n" + 'Test 3
'; var calculatedType = diffService.detectReplacementType(htmlBefore, htmlAfter); expect(calculatedType).toBe(diffService.TYPE_REPLACEMENT); }); }); describe('the core diff algorithm', function() { it('acts as documented by the official documentation', function () { var before = "The red brown fox jumped over the rolling log.", after = "The brown spotted fox leaped over the rolling log."; var diff = diffService.diff(before, after); expect(diff).toBe('TheTest1 Test2
", after = "Test1 Test2
"; var diff = diffService.diff(before, after); expect(diff).toBe("Test1 Test2
Test1 Test2
"); }); it('handles inserted paragraphs', function () { var 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
"; var diff = diffService.diff(before, after); expect(diff).toBe("liebliche Stimme, aber deine Stimme ist rauh; du bist der Wolf.' 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 gieng der
Ihr könnt ohne Sorge fortgehen.'Da meckerte die Alte und machte sich getrost auf den Weg.
", after = ""; var diff = diffService.diff(before, after); expect(diff).toBe("Ihr könnt ohne Sorge fortgehen.'Da meckerte die Alte und machte sich getrost auf den Weg.