/** * Parses a string with a particular start symbol/sort. * * @param startSymbol the start symbol/sort * @param toParse the String to parse * @return a pair: the left projection is a parsed string as a K, if successful; * the right projection is the set of issues encountered while parsing */ public Tuple2<Option<K>, Set<Warning>> apply(Sort startSymbol, String toParse) { return apply(startSymbol, toParse, Source.apply("generated")); }
@Test public void simpleFailedParse() { Tuple2<Option<K>, Set<Warning>> actual = Parser.from(m).apply(xSort, "y"); assertTrue("The parse should fail, but was " + actual, actual._1().isEmpty()); assertTrue("There should be one error, but were: " + actual._2(), actual._2().size() == 1); } }
@Test public void simpleNoWarning() { Tuple2<Option<K>, Set<Warning>> actual = Parser.from(m).apply(xSort, "x"); assertTrue("The parse should succeed, but was " + actual, actual._1().isDefined()); assertTrue("There should be no warnings, but were: " + actual._2(), actual._2().isEmpty()); assertEquals(KApply(KLabel("x")), actual._1().get()); }