Pattern { public final Pattern optional() { return new OptionalPattern(this); }  abstract int match(CharSequence src, int begin, int end); final Pattern next(Pattern next); final Pattern optional(); final Pattern many(); @Deprecated final Pattern many(int min); final Pattern atLeast(int min); final Pattern many1(); @Deprecated final Pattern some(int max); final Pattern atMost(int max); @Deprecated final Pattern some(int min, int max); final Pattern times(int min, int max); final Pattern not(); final Pattern peek(); final Pattern ifelse(Pattern consequence, Pattern alternative); @Deprecated final Pattern repeat(int n); final Pattern times(int n); final Pattern or(Pattern p2); @SuppressWarnings("deprecation") final Parser<Void> toScanner(String name); static final int MISMATCH; }
@Test public void testOptional() { assertEquals(0, Patterns.NEVER.optional().match("", 0, 0)); assertEquals(0, Patterns.ALWAYS.optional().match("", 0, 0)); assertEquals(1, Patterns.hasAtLeast(1).optional().match("abc", 0, 3)); }