private void addFile(String arg) { // at the very least, we'll print this about a file: // 0.txt // @@ -1,2 +1,2 @@, // -1\\r\\n, // -2\\r\\n, // ... (more lines that didn't fit) List<String> lines = NEWLINE_SPLITTER.splitToList(arg); if (!lines.isEmpty()) { addIntendedLine(NORMAL_INDENT, lines.get(0)); } for (int i = 1; i < Math.min(MIN_LINES_PER_FILE, lines.size()); ++i) { addIntendedLine(DIFF_INDENT, lines.get(i)); } // 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) { addIntendedLine(DIFF_INDENT, iter.next()); } if (numLines >= MAX_CHECK_MESSAGE_LINES) { // we're out of space if (iter.hasNext()) { int linesLeft = lines.size() - iter.nextIndex(); addIntendedLine(NORMAL_INDENT, "... (" + linesLeft + " more lines that didn't fit)"); } } }
private void assertResultAndMessages(BuildResult result, TaskOutcome outcome, String... messages) { String expectedToStartWith = StringPrinter.buildStringFromLines(messages).trim(); int numNewlines = CharMatcher.is('\n').countIn(expectedToStartWith); List<String> actualLines = Splitter.on('\n').splitToList(LineEnding.toUnix(result.getOutput())); String actualStart = String.join("\n", actualLines.subList(0, numNewlines + 1)); Assertions.assertThat(actualStart).isEqualTo(expectedToStartWith); Assertions.assertThat(result.tasks(outcome).size() + result.tasks(TaskOutcome.UP_TO_DATE).size()) .isEqualTo(result.getTasks().size()); } }
private void addFile(String arg) { // at the very least, we'll print this about a file: // 0.txt // @@ -1,2 +1,2 @@, // -1\\r\\n, // -2\\r\\n, // ... (more lines that didn't fit) List<String> lines = NEWLINE_SPLITTER.splitToList(arg); if (!lines.isEmpty()) { addIntendedLine(NORMAL_INDENT, lines.get(0)); } for (int i = 1; i < Math.min(MIN_LINES_PER_FILE, lines.size()); ++i) { addIntendedLine(DIFF_INDENT, lines.get(i)); } // 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) { addIntendedLine(DIFF_INDENT, iter.next()); } if (numLines >= MAX_CHECK_MESSAGE_LINES) { // we're out of space if (iter.hasNext()) { int linesLeft = lines.size() - iter.nextIndex(); addIntendedLine(NORMAL_INDENT, "... (" + linesLeft + " more lines that didn't fit)"); } } }