use of com.nike.riposte.util.text.parsercombinator.Parser.ParserFailure in project riposte by Nike-Inc.
the class ParserTest method test_test2_works.
@Test
public void test_test2_works() throws ParserFailure {
final Pattern numberPattern = Pattern.compile("([0-9])");
final Parser<Integer> number = regex(numberPattern).map(m -> new Integer(m.group(1)));
Parser<Number> parser;
Optional<Number> oResult;
parser = number.thenParse(number).filter(test((one, two) -> false)).map(match((one, two) -> 0));
oResult = parser.tryParse("12");
assertThat(oResult.isPresent()).isFalse();
parser = number.thenParse(number).filter(test((one, two) -> true)).map(match((one, two) -> one + two));
oResult = parser.tryParse("12");
assertThat(oResult.isPresent()).isTrue();
assertThat(oResult.get()).isNotNull();
assertThat(oResult.get()).isEqualTo(3);
oResult = parser.tryParse("1");
assertThat(oResult.isPresent()).isFalse();
}
Aggregations