CodeReader extends CodeBuffer { public final int popTo(Matcher matcher, Appendable appendable) { return popTo(matcher, null, appendable); } CodeReader(Reader code);  CodeReader(String code);  CodeReader(Reader code, CodeReaderConfiguration configuration);  CodeReader(String code, CodeReaderConfiguration configuration); final void pop(Appendable appendable); final char[] peek(int length); final void peekTo(EndMatcher matcher, Appendable appendable); final int popTo(Matcher matcher, Appendable appendable); final int popTo(Matcher matcher, Matcher afterMatcher, Appendable appendable); final Cursor getPreviousCursor();  }
@Test public void testPopToWithRegex() { CodeReader reader = new CodeReader(new StringReader("123ABC")); StringBuilder token = new StringBuilder(); assertEquals(3, reader.popTo(Pattern.compile("\\d+").matcher(new String()), token)); assertEquals("123", token.toString()); assertEquals(-1, reader.popTo(Pattern.compile("\\d+").matcher(new String()), token)); assertEquals(3, reader.popTo(Pattern.compile("\\w+").matcher(new String()), token)); assertEquals("123ABC", token.toString()); assertEquals(-1, reader.popTo(Pattern.compile("\\w+").matcher(new String()), token)); Matcher matcher = Pattern.compile("\\d+").matcher(""); reader.popTo(matcher, token); try { matcher.find(1); Assert.fail("exception expected"); } catch (IndexOutOfBoundsException e) { assertEquals("Illegal start index", e.getMessage()); } }
@Test public void testPopToWithRegexAndFollowingMatcher() { Matcher digitMatcher = Pattern.compile("\\d+").matcher(new String()); Matcher alphabeticMatcher = Pattern.compile("[a-zA-Z]").matcher(new String()); StringBuilder token = new StringBuilder(); assertEquals(-1, new CodeReader(new StringReader("123 ABC")).popTo(digitMatcher, alphabeticMatcher, token)); assertEquals("", token.toString()); assertEquals(3, new CodeReader(new StringReader("123ABC")).popTo(digitMatcher, alphabeticMatcher, token)); assertEquals("123", token.toString()); }