use of com.nike.riposte.util.text.parsercombinator.Parser.ParserFailure in project riposte by Nike-Inc.
the class ParserTest method test_test6_works.
@Test
public void test_test6_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).thenParse(number).thenParse(number).thenParse(number).thenParse(number).filter(test((one, two, three, four, five, six) -> false)).map(match((one, two, three, four, five, six) -> 0));
oResult = parser.tryParse("123456");
assertThat(oResult.isPresent()).isFalse();
parser = number.thenParse(number).thenParse(number).thenParse(number).thenParse(number).thenParse(number).filter(test((one, two, three, four, five, six) -> true)).map(match((one, two, three, four, five, six) -> one + two + three + four + five + six));
oResult = parser.tryParse("123456");
assertThat(oResult.isPresent()).isTrue();
assertThat(oResult.get()).isNotNull();
assertThat(oResult.get()).isEqualTo(21);
oResult = parser.tryParse("12345");
assertThat(oResult.isPresent()).isFalse();
}
use of com.nike.riposte.util.text.parsercombinator.Parser.ParserFailure in project riposte by Nike-Inc.
the class ParserTest method test_test3_works.
@Test
public void test_test3_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).thenParse(number).filter(test((one, two, three) -> false)).map(match((one, two, three) -> 0));
oResult = parser.tryParse("123");
assertThat(oResult.isPresent()).isFalse();
parser = number.thenParse(number).thenParse(number).filter(test((one, two, three) -> true)).map(match((one, two, three) -> one + two + three));
oResult = parser.tryParse("123");
assertThat(oResult.isPresent()).isTrue();
assertThat(oResult.get()).isNotNull();
assertThat(oResult.get()).isEqualTo(6);
oResult = parser.tryParse("12");
assertThat(oResult.isPresent()).isFalse();
}
use of com.nike.riposte.util.text.parsercombinator.Parser.ParserFailure in project riposte by Nike-Inc.
the class ParserTest method test_test7_works.
@Test
public void test_test7_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).thenParse(number).thenParse(number).thenParse(number).thenParse(number).thenParse(number).filter(test((one, two, three, four, five, six, seven) -> false)).map(match((one, two, three, four, five, six, seven) -> 0));
oResult = parser.tryParse("1234567");
assertThat(oResult.isPresent()).isFalse();
parser = number.thenParse(number).thenParse(number).thenParse(number).thenParse(number).thenParse(number).thenParse(number).filter(test((one, two, three, four, five, six, seven) -> true)).map(match((one, two, three, four, five, six, seven) -> one + two + three + four + five + six + seven));
oResult = parser.tryParse("1234567");
assertThat(oResult.isPresent()).isTrue();
assertThat(oResult.get()).isNotNull();
assertThat(oResult.get()).isEqualTo(28);
oResult = parser.tryParse("123456");
assertThat(oResult.isPresent()).isFalse();
}
use of com.nike.riposte.util.text.parsercombinator.Parser.ParserFailure in project riposte by Nike-Inc.
the class ParserTest method test_test4_works.
@Test
public void test_test4_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).thenParse(number).thenParse(number).filter(test((one, two, three, four) -> false)).map(match((one, two, three, four) -> 0));
oResult = parser.tryParse("1234");
assertThat(oResult.isPresent()).isFalse();
parser = number.thenParse(number).thenParse(number).thenParse(number).filter(test((one, two, three, four) -> true)).map(match((one, two, three, four) -> one + two + three + four));
oResult = parser.tryParse("1234");
assertThat(oResult.isPresent()).isTrue();
assertThat(oResult.get()).isNotNull();
assertThat(oResult.get()).isEqualTo(10);
oResult = parser.tryParse("123");
assertThat(oResult.isPresent()).isFalse();
}
use of com.nike.riposte.util.text.parsercombinator.Parser.ParserFailure in project riposte by Nike-Inc.
the class ParserTest method test_test8_works.
@Test
public void test_test8_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).thenParse(number).thenParse(number).thenParse(number).thenParse(number).thenParse(number).thenParse(number).filter(test((one, two, three, four, five, six, seven, eight) -> false)).map(match((one, two, three, four, five, six, seven, eight) -> 0));
oResult = parser.tryParse("12345678");
assertThat(oResult.isPresent()).isFalse();
parser = number.thenParse(number).thenParse(number).thenParse(number).thenParse(number).thenParse(number).thenParse(number).thenParse(number).filter(test((one, two, three, four, five, six, seven, eight) -> true)).map(match((one, two, three, four, five, six, seven, eight) -> one + two + three + four + five + six + seven + eight));
oResult = parser.tryParse("12345678");
assertThat(oResult.isPresent()).isTrue();
assertThat(oResult.get()).isNotNull();
assertThat(oResult.get()).isEqualTo(36);
oResult = parser.tryParse("1234567");
assertThat(oResult.isPresent()).isFalse();
}
Aggregations