diff options
author | Steve Block <steveblock@google.com> | 2010-09-29 15:08:51 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-09-29 18:51:42 +0100 |
commit | 856f2859e8550c274c7fe3f05b971bf34bdcb525 (patch) | |
tree | c8fe48932259bbaa38e98f3522f0d5a5190aa8d7 | |
parent | fd487ad1b8d11dbc3df29b3073a0ec89f998c819 (diff) | |
download | frameworks_base-856f2859e8550c274c7fe3f05b971bf34bdcb525.zip frameworks_base-856f2859e8550c274c7fe3f05b971bf34bdcb525.tar.gz frameworks_base-856f2859e8550c274c7fe3f05b971bf34bdcb525.tar.bz2 |
Fix some bugs in DumpRenderTree2 when forming HTML diffs
Change-Id: Id98c1b7dde1961c2dab4214a36ad43916baf8011
-rw-r--r-- | tests/DumpRenderTree2/src/com/android/dumprendertree2/TextResult.java | 4 | ||||
-rw-r--r-- | tests/DumpRenderTree2/src/com/android/dumprendertree2/VisualDiffUtils.java | 59 |
2 files changed, 37 insertions, 26 deletions
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/TextResult.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/TextResult.java index fce8355..3d2b98b 100644 --- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/TextResult.java +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/TextResult.java @@ -208,6 +208,10 @@ public class TextResult extends AbstractResult { VisualDiffUtils.generateExpectedResultLines(diffs, expectedLineNums, expectedLines); VisualDiffUtils.generateActualResultLines(diffs, actualLineNums, actualLines); + // TODO: We should use a map for each line number and lines pair. + assert expectedLines.size() == expectedLineNums.size(); + assert actualLines.size() == actualLineNums.size(); + assert expectedLines.size() == actualLines.size(); html.append(VisualDiffUtils.getHtml(expectedLineNums, expectedLines, actualLineNums, actualLines)); diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/VisualDiffUtils.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/VisualDiffUtils.java index 26bf75c..d7f7313 100644 --- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/VisualDiffUtils.java +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/VisualDiffUtils.java @@ -68,35 +68,38 @@ public class VisualDiffUtils { String line = ""; int i = 1; - for (diff_match_patch.Diff diff : diffs) { + diff_match_patch.Diff diff; + int size = diffs.size(); + boolean isLastDiff; + for (int j = 0; j < size; j++) { + diff = diffs.get(j); + isLastDiff = j == size - 1; switch (diff.operation) { case DELETE: - line = processDiff(diff, lineNums, lines, line, i, delSpan); + line = processDiff(diff, lineNums, lines, line, i, delSpan, isLastDiff); if (line.equals("")) { i++; } break; case INSERT: - if (diff.text.endsWith("\n")) { - lineNums.add(DONT_PRINT_LINE_NUMBER); - lines.add(""); + // If the line is currently empty and this insertion is the entire line, the + // expected line is absent, so it has no line number. + if (diff.text.endsWith("\n") || isLastDiff) { + lineNums.add(line.equals("") ? DONT_PRINT_LINE_NUMBER : i++); + lines.add(line); + line = ""; } break; case EQUAL: - line = processDiff(diff, lineNums, lines, line, i, eqlSpan); + line = processDiff(diff, lineNums, lines, line, i, eqlSpan, isLastDiff); if (line.equals("")) { i++; } break; } } - - if (!line.isEmpty()) { - lines.add(line); - lineNums.add(i); - } } public static void generateActualResultLines(LinkedList<diff_match_patch.Diff> diffs, @@ -106,35 +109,38 @@ public class VisualDiffUtils { String line = ""; int i = 1; - for (diff_match_patch.Diff diff : diffs) { + diff_match_patch.Diff diff; + int size = diffs.size(); + boolean isLastDiff; + for (int j = 0; j < size; j++) { + diff = diffs.get(j); + isLastDiff = j == size - 1; switch (diff.operation) { case INSERT: - line = processDiff(diff, lineNums, lines, line, i, insSpan); + line = processDiff(diff, lineNums, lines, line, i, insSpan, isLastDiff); if (line.equals("")) { i++; } break; case DELETE: - if (diff.text.endsWith("\n")) { - lineNums.add(DONT_PRINT_LINE_NUMBER); - lines.add(""); + // If the line is currently empty and deletion is the entire line, the + // actual line is absent, so it has no line number. + if (diff.text.endsWith("\n") || isLastDiff) { + lineNums.add(line.equals("") ? DONT_PRINT_LINE_NUMBER : i++); + lines.add(line); + line = ""; } break; case EQUAL: - line = processDiff(diff, lineNums, lines, line, i, eqlSpan); + line = processDiff(diff, lineNums, lines, line, i, eqlSpan, isLastDiff); if (line.equals("")) { i++; } break; } } - - if (!line.isEmpty()) { - lines.add(line); - lineNums.add(i); - } } /** @@ -147,15 +153,16 @@ public class VisualDiffUtils { * @param line * @param i * @param begSpan + * @param forceOutputLine Force the current line to be output * @return */ public static String processDiff(diff_match_patch.Diff diff, LinkedList<Integer> lineNums, - LinkedList<String> lines, String line, int i, String begSpan) { + LinkedList<String> lines, String line, int i, String begSpan, boolean forceOutputLine) { String endSpan = "</span>"; String br = " "; - if (diff.text.endsWith("\n")) { - lineNums.add(i++); + if (diff.text.endsWith("\n") || forceOutputLine) { + lineNums.add(i); /** TODO: Think of better way to replace stuff */ line += begSpan + diff.text.replace(" ", " ") + endSpan + br; @@ -204,4 +211,4 @@ public class VisualDiffUtils { } return html.toString(); } -}
\ No newline at end of file +} |