Skip to content

Commit

Permalink
Avoid printing (1 more lines that didn't fit)
Browse files Browse the repository at this point in the history
fixes #467
  • Loading branch information
vlsi committed Nov 8, 2019
1 parent f7b4c16 commit 9bd34fd
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
Expand Up @@ -137,7 +137,10 @@ private void addFile(String arg) {

// then we'll print the rest that can fit
ListIterator<String> iter = lines.listIterator(Math.min(MIN_LINES_PER_FILE, lines.size()));
while (iter.hasNext() && numLines < MAX_CHECK_MESSAGE_LINES) {
// lines.size() - iter.nextIndex() == 1 means "just one line left", and we just print the line
// instead of "1 more lines that didn't fit"
while (iter.hasNext() &&
(numLines < MAX_CHECK_MESSAGE_LINES || lines.size() - iter.nextIndex() == 1)) {
addIntendedLine(DIFF_INDENT, iter.next());
}

Expand Down
Expand Up @@ -393,4 +393,69 @@ public void longFile() throws Exception {
" -47␍␊",
" ... (1952 more lines that didn't fit)");
}

@Test
public void oneMoreLineThatDidntFit() throws Exception {
// com.diffplug.spotless.extra.integration.DiffMessageFormatter.MAX_CHECK_MESSAGE_LINES
// defaults to 50, so we create a diff that would be exactly 50 lines long
// The test is to ensure diff does not contain "1 more lines that didn't fit"
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 25; ++i) {
builder.append(i);
builder.append(i < 1 ? "\n" : "\r\n");
}
SpotlessTask task = create(setFile("testFile").toContent(builder.toString()));
assertTaskFailure(task,
" testFile",
" @@ -1,25 +1,25 @@",
" 0",
" -1␍␊",
" -2␍␊",
" -3␍␊",
" -4␍␊",
" -5␍␊",
" -6␍␊",
" -7␍␊",
" -8␍␊",
" -9␍␊",
" -10␍␊",
" -11␍␊",
" -12␍␊",
" -13␍␊",
" -14␍␊",
" -15␍␊",
" -16␍␊",
" -17␍␊",
" -18␍␊",
" -19␍␊",
" -20␍␊",
" -21␍␊",
" -22␍␊",
" -23␍␊",
" -24␍␊",
" +1␊",
" +2␊",
" +3␊",
" +4␊",
" +5␊",
" +6␊",
" +7␊",
" +8␊",
" +9␊",
" +10␊",
" +11␊",
" +12␊",
" +13␊",
" +14␊",
" +15␊",
" +16␊",
" +17␊",
" +18␊",
" +19␊",
" +20␊",
" +21␊",
" +22␊",
" +23␊",
" +24␊");
}
}

0 comments on commit 9bd34fd

Please sign in to comment.