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()); } }
/** * Returns a {@code char} matcher that matches any character present in the given character * sequence. */ public static CharMatcher anyOf(final CharSequence sequence) { switch (sequence.length()) { case 0: return none(); case 1: return is(sequence.charAt(0)); case 2: return isEither(sequence.charAt(0), sequence.charAt(1)); default: // TODO(lowasser): is it potentially worth just going ahead and building a precomputed // matcher? return new AnyOf(sequence); } }
/** * Helper method for {@link #precomputedInternal} that doesn't test if the negation is cheaper. */ @GwtIncompatible("java.util.BitSet") private static CharMatcher precomputedPositive( int totalCharacters, BitSet table, String description) { switch (totalCharacters) { case 0: return none(); case 1: return is((char) table.nextSetBit(0)); case 2: char c1 = (char) table.nextSetBit(0); char c2 = (char) table.nextSetBit(c1 + 1); return isEither(c1, c2); default: return isSmall(totalCharacters, table.length()) ? SmallCharMatcher.from(table, description) : new BitSetMatcher(table, description); } }
@Override CharMatcher padding() { return (paddingChar == null) ? CharMatcher.NONE : CharMatcher.is(paddingChar.charValue()); }
/** * Returns a splitter that uses the given single-character separator. For * example, {@code Splitter.on(',').split("foo,,bar")} returns an iterable * containing {@code ["foo", "", "bar"]}. * * @param separator the character to recognize as a separator * @return a splitter, with default settings, that recognizes that separator */ @CheckReturnValue public static Splitter on(char separator) { return on(CharMatcher.is(separator)); }