Skip to content

Commit 77556e8

Browse files
fshcheglovCommit Queue
authored andcommitted
Improve diff by making Short Diff only appear if it is less than or equal to 30% of the full diff in line number.
Change-Id: Icd2496deae0a4258fd2c1867ca8107210f5b60a7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441992 Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent f47cc44 commit 77556e8

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

pkg/analyzer/test/util/diff.dart

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'dart:math';
66

77
/// Generates a "focused" unified diff, showing only the changed lines
88
/// plus a few lines of context around them.
9-
String generateFocusedDiff(
9+
List<String> generateFocusedDiff(
1010
String expected,
1111
String actual, {
1212
int contextLines = 3,
@@ -30,7 +30,7 @@ String generateFocusedDiff(
3030
}
3131

3232
if (indicesToInclude.isEmpty) {
33-
return 'No differences found.';
33+
return ['No differences found.'];
3434
}
3535

3636
int lastIncludedIndex = -1;
@@ -45,25 +45,28 @@ String generateFocusedDiff(
4545
lastIncludedIndex = i;
4646
}
4747

48-
return outputLines.join('\n');
48+
return outputLines;
4949
}
5050

5151
/// Generates a "full" unified diff, showing every line from the comparison.
52-
String generateFullDiff(String expected, String actual) {
52+
List<String> generateFullDiff(String expected, String actual) {
5353
var diffResults = _createDiff(expected, actual);
54-
return diffResults.map(_formatLine).join('\n');
54+
return diffResults.map(_formatLine).toList();
5555
}
5656

5757
void printPrettyDiff(String expected, String actual, {int context = 3}) {
5858
var full = generateFullDiff(expected, actual);
5959
var short = generateFocusedDiff(expected, actual);
60-
print('-------- Short diff --------');
61-
print(short);
60+
61+
if (full.length * 0.3 >= short.length) {
62+
print('-------- Short diff --------');
63+
print(short.join('/n'));
64+
}
6265
print('-------- Full diff ---------');
63-
print(full);
66+
print(full.join('/n'));
6467
print('---------- Actual ----------');
6568
print(actual.trimRight());
66-
print('------------------------');
69+
print('----------------------------');
6770
}
6871

6972
/// Backtracks through the LCS table to build the list of diff results.

0 commit comments

Comments
 (0)