@GwtIncompatible // Doubles.tryParse private static void checkTryParse(String input) { Double expected = referenceTryParse(input); assertEquals(expected, Doubles.tryParse(input)); if (expected != null && !Doubles.FLOATING_POINT_PATTERN.matcher(input).matches()) { // TODO(cpovirk): Use SourceCodeEscapers if it is added to Guava. StringBuilder escapedInput = new StringBuilder(); for (char c : input.toCharArray()) { if (c >= 0x20 && c <= 0x7E) { escapedInput.append(c); } else { escapedInput.append(String.format("\\u%04x", (int) c)); } } fail("FLOATING_POINT_PATTERN should have matched valid input <" + escapedInput + ">"); } }
@GwtIncompatible // Doubles.tryParse public void testTryParseFailures() { for (String badInput : BAD_TRY_PARSE_INPUTS) { assertThat(badInput) .doesNotMatch( Pattern.compile( Doubles.FLOATING_POINT_PATTERN.pattern(), Doubles.FLOATING_POINT_PATTERN.flags())); assertEquals(referenceTryParse(badInput), Doubles.tryParse(badInput)); assertNull(Doubles.tryParse(badInput)); } }
@GwtIncompatible // Doubles.tryParse private static void checkTryParse(String input) { Double expected = referenceTryParse(input); assertEquals(expected, Doubles.tryParse(input)); if (expected != null && !Doubles.FLOATING_POINT_PATTERN.matcher(input).matches()) { // TODO(cpovirk): Use SourceCodeEscapers if it is added to Guava. StringBuilder escapedInput = new StringBuilder(); for (char c : input.toCharArray()) { if (c >= 0x20 && c <= 0x7E) { escapedInput.append(c); } else { escapedInput.append(String.format("\\u%04x", (int) c)); } } fail("FLOATING_POINT_PATTERN should have matched valid input <" + escapedInput + ">"); } }
@GwtIncompatible // Doubles.tryParse public void testTryParseFailures() { for (String badInput : BAD_TRY_PARSE_INPUTS) { assertThat(badInput).doesNotMatch(Doubles.FLOATING_POINT_PATTERN); assertEquals(referenceTryParse(badInput), Doubles.tryParse(badInput)); assertNull(Doubles.tryParse(badInput)); } }