11package com .github .difflib .text ;
22
3+ import com .github .difflib .DiffUtils ;
4+ import com .github .difflib .algorithm .myers .MyersDiffWithLinearSpace ;
35import java .io .File ;
46import java .io .IOException ;
7+ import java .net .URISyntaxException ;
8+ import java .nio .file .FileSystem ;
9+ import java .nio .file .FileSystems ;
510import java .nio .file .Files ;
611import java .nio .file .Paths ;
712import java .util .Arrays ;
@@ -721,7 +726,7 @@ public void testIssue129WithDeltaDecompression() {
721726
722727assertThat (txt ).isEqualTo ("EQUAL EQUAL EQUAL CHANGE INSERT INSERT EQUAL EQUAL EQUAL" );
723728 }
724-
729+
725730@ Test
726731public void testIssue129SkipDeltaDecompression () {
727732List <String >lines1 =Arrays .asList (
@@ -743,25 +748,25 @@ public void testIssue129SkipDeltaDecompression() {
743748"banana2" ,
744749"banana3" );
745750int []entry = {1 };
746- String txt =
747- DiffRowGenerator .create ()
748- .showInlineDiffs (true )
749- .decompressDeltas (false )
750- .oldTag ((tag ,isOpening ) ->isOpening ?"==old" +tag +"==>" :"<==old==" )
751- .newTag ((tag ,isOpening ) ->isOpening ?"==new" +tag +"==>" :"<==new==" )
752- .build ()
753- .generateDiffRows (lines1 ,lines2 )
754- .stream ()
755- .map (row ->row .getTag ().toString ())
756- .collect (joining (" " ));
751+ String txt
752+ = DiffRowGenerator .create ()
753+ .showInlineDiffs (true )
754+ .decompressDeltas (false )
755+ .oldTag ((tag ,isOpening ) ->isOpening ?"==old" +tag +"==>" :"<==old==" )
756+ .newTag ((tag ,isOpening ) ->isOpening ?"==new" +tag +"==>" :"<==new==" )
757+ .build ()
758+ .generateDiffRows (lines1 ,lines2 )
759+ .stream ()
760+ .map (row ->row .getTag ().toString ())
761+ .collect (joining (" " ));
757762// .forEachOrdered(row -> {
758763// System.out.printf("%4d %-8s %-80s %-80s\n", entry[0]++,
759764// row.getTag(), row.getOldLine(), row.getNewLine());
760765// });
761766
762767assertThat (txt ).isEqualTo ("EQUAL EQUAL EQUAL CHANGE CHANGE CHANGE EQUAL EQUAL EQUAL" );
763768 }
764-
769+
765770@ Test
766771public void testIssue129SkipWhitespaceChanges ()throws IOException {
767772String original =Files .lines (Paths .get ("target/test-classes/com/github/difflib/text/issue129_1.txt" )).collect (joining ("\n " ));
@@ -780,9 +785,33 @@ public void testIssue129SkipWhitespaceChanges() throws IOException {
780785Arrays .asList (revised .split ("\n " )));
781786
782787assertThat (rows ).hasSize (13 );
783-
788+
784789rows .stream ()
785790 .filter (item ->item .getTag () !=DiffRow .Tag .EQUAL )
786791 .forEach (System .out ::println );
787792 }
793+
794+ @ Test
795+ public void testIssue188HangOnExamples ()throws IOException ,URISyntaxException {
796+ try (FileSystem zipFs =FileSystems .newFileSystem (Paths .get ("target/test-classes/com/github/difflib/text/test.zip" ),null );) {
797+ List <String >original =Files .readAllLines (zipFs .getPath ("old.html" ));
798+ List <String >revised =Files .readAllLines (zipFs .getPath ("new.html" ));
799+
800+ DiffRowGenerator generator =DiffRowGenerator .create ()
801+ .lineNormalizer (line ->line )
802+ .showInlineDiffs (true )
803+ .mergeOriginalRevised (true )
804+ .inlineDiffByWord (true )
805+ .decompressDeltas (true )
806+ .oldTag (f ->f ?"<s style=\" background-color: #bbbbbb\" >" :"</s>" )
807+ .newTag (f ->f ?"<b style=\" background-color: #aaffaa\" >" :"</b>" )
808+ .build ();
809+
810+ //List<DiffRow> rows = generator.generateDiffRows(original, revised);
811+ List <DiffRow >rows =generator .generateDiffRows (original ,DiffUtils .diff (original ,revised ,new MyersDiffWithLinearSpace <>() ));
812+
813+ System .out .println (rows );
814+ }
815+ }
788816}
817+