use of com.nike.riposte.util.text.parsercombinator.Parser.ParserFailure in project riposte by Nike-Inc.
the class ParserTest method test_match2_works.
@Test
public void test_match2_works() throws ParserFailure {
final Pattern numberPattern = Pattern.compile("([0-9])");
final Parser<Integer> number = regex(numberPattern).map(m -> new Integer(m.group(1)));
Parser<String> parser = number.thenParse(string("A")).map(match((first, second) -> first.toString() + "+" + second));
Optional<String> oResult = parser.tryParse("1A");
assertThat(oResult.isPresent()).isTrue();
assertThat(oResult.get()).isNotNull();
assertThat(oResult.get()).isEqualTo("1+A");
}
use of com.nike.riposte.util.text.parsercombinator.Parser.ParserFailure in project riposte by Nike-Inc.
the class ParserTest method test_match3_works.
@Test
public void test_match3_works() throws ParserFailure {
final Pattern numberPattern = Pattern.compile("([0-9])");
final Pattern booleanPattern = Pattern.compile("(true|false)");
final Parser<Integer> number = regex(numberPattern).map(m -> new Integer(m.group(1)));
final Parser<Boolean> bool = regex(booleanPattern).map(m -> new Boolean(m.group(1)));
Parser<String> parser = number.thenParse(string("A")).thenParse(bool).map(match((first, second, third) -> first.toString() + "+" + second + "+" + third.toString()));
Optional<String> oResult = parser.tryParse("1Atrue");
assertThat(oResult.isPresent()).isTrue();
assertThat(oResult.get()).isNotNull();
assertThat(oResult.get()).isEqualTo("1+A+true");
}
use of com.nike.riposte.util.text.parsercombinator.Parser.ParserFailure in project riposte by Nike-Inc.
the class ParserTest method test_match7_works.
@Test
public void test_match7_works() throws ParserFailure {
final Pattern numberPattern = Pattern.compile("([0-9])");
final Pattern booleanPattern = Pattern.compile("(true|false)");
final Supplier<Parser<Integer>> number = () -> regex(numberPattern).map(m -> new Integer(m.group(1)));
final Supplier<Parser<Boolean>> bool = () -> regex(booleanPattern).map(m -> new Boolean(m.group(1)));
Parser<String> parser = number.get().thenParse(string("A")).thenParse(bool).thenParse(number).thenParse(string("B")).thenParse(bool).thenParse(number).map(match((first, second, third, fourth, fifth, sixth, seventh) -> {
return first.toString() + "+" + second.toString() + "+" + third.toString() + "+" + fourth.toString() + "+" + fifth.toString() + "+" + sixth.toString() + "+" + seventh.toString();
}));
Optional<String> oResult = parser.tryParse("1Atrue2Bfalse3");
assertThat(oResult.isPresent()).isTrue();
assertThat(oResult.get()).isNotNull();
assertThat(oResult.get()).isEqualTo("1+A+true+2+B+false+3");
}
use of com.nike.riposte.util.text.parsercombinator.Parser.ParserFailure in project riposte by Nike-Inc.
the class ParserTest method test_match4_works.
@Test
public void test_match4_works() throws ParserFailure {
final Pattern numberPattern = Pattern.compile("([0-9])");
final Pattern booleanPattern = Pattern.compile("(true|false)");
final Supplier<Parser<Integer>> number = () -> regex(numberPattern).map(m -> new Integer(m.group(1)));
final Supplier<Parser<Boolean>> bool = () -> regex(booleanPattern).map(m -> new Boolean(m.group(1)));
Parser<String> parser = number.get().thenParse(string("A")).thenParse(bool).thenParse(number).map(match((first, second, third, fourth) -> {
return first.toString() + "+" + second.toString() + "+" + third.toString() + "+" + fourth.toString();
}));
Optional<String> oResult = parser.tryParse("1Atrue2");
assertThat(oResult.isPresent()).isTrue();
assertThat(oResult.get()).isNotNull();
assertThat(oResult.get()).isEqualTo("1+A+true+2");
}
use of com.nike.riposte.util.text.parsercombinator.Parser.ParserFailure in project riposte by Nike-Inc.
the class ParserTest method test_match5_works.
@Test
public void test_match5_works() throws ParserFailure {
final Pattern numberPattern = Pattern.compile("([0-9])");
final Pattern booleanPattern = Pattern.compile("(true|false)");
final Supplier<Parser<Integer>> number = () -> regex(numberPattern).map(m -> new Integer(m.group(1)));
final Supplier<Parser<Boolean>> bool = () -> regex(booleanPattern).map(m -> new Boolean(m.group(1)));
Parser<String> parser = number.get().thenParse(string("A")).thenParse(bool).thenParse(number).thenParse(string("B")).map(match((first, second, third, fourth, fifth) -> {
return first.toString() + "+" + second.toString() + "+" + third.toString() + "+" + fourth.toString() + "+" + fifth.toString();
}));
Optional<String> oResult = parser.tryParse("1Atrue2B");
assertThat(oResult.isPresent()).isTrue();
assertThat(oResult.get()).isNotNull();
assertThat(oResult.get()).isEqualTo("1+A+true+2+B");
}
Aggregations