(String before, String after)
| 23 | /** Creates diffs which are easy to assert against. */ |
| 24 | public class Diff { |
| 25 | public static String computeDiff(String before, String after) { |
| 26 | diff_match_patch differ = new diff_match_patch(); |
| 27 | LinkedList<diff_match_patch.Diff> diffs = differ.diff_main(before, after); |
| 28 | differ.diff_cleanupEfficiency(diffs); |
| 29 | differ.diff_cleanupSemantic(diffs); |
| 30 | return StringPrinter.buildString(printer -> { |
| 31 | for (diff_match_patch.Diff diff : diffs) { |
| 32 | switch (diff.operation) { |
| 33 | case EQUAL: |
| 34 | // do nothing |
| 35 | break; |
| 36 | case DELETE: |
| 37 | case INSERT: |
| 38 | printer.println(diff.operation.name()); |
| 39 | printer.println(FileMisc.toUnixNewline(diff.text)); |
| 40 | break; |
| 41 | default: |
| 42 | throw Unhandled.enumException(diff.operation); |
| 43 | } |
| 44 | } |
| 45 | }); |
| 46 | } |
| 47 | } |
no test coverage detected