Patterns { public static Pattern range(char c1, char c2) { return isChar(CharPredicates.range(c1, c2)); } private  Patterns(); static Pattern hasAtLeast(final int n); static Pattern hasExact(final int n); static Pattern isChar(char c); static Pattern range(char c1, char c2); static Pattern among(String chars); static Pattern isChar(final CharPredicate predicate); static Pattern lineComment(String begin); static Pattern string(final String string); static Pattern stringCaseInsensitive(final String string); static Pattern notString(final String string); static Pattern notStringCaseInsensitive(final String string); static Pattern not(Pattern pattern); static Pattern and(final Pattern... patterns); static Pattern or(Pattern... patterns); static Pattern sequence(Pattern... patterns); static Pattern repeat(int n, CharPredicate predicate); @Deprecated static Pattern many(int min, CharPredicate predicate); static Pattern atLeast(final int min, final CharPredicate predicate); static Pattern many(final CharPredicate predicate); @Deprecated static Pattern some(int min, int max, CharPredicate predicate); static Pattern times(final int min, final int max, final CharPredicate predicate); @Deprecated static Pattern some(final int max, final CharPredicate predicate); static Pattern atMost(final int max, final CharPredicate predicate); static Pattern longer(Pattern p1, Pattern p2); static Pattern longest(final Pattern... patterns); static Pattern shorter(Pattern p1, Pattern p2); static Pattern shortest(final Pattern... patterns); static Pattern many1(CharPredicate predicate); static Pattern regex(final java.util.regex.Pattern p); static Pattern regex(String s); static final Pattern NEVER; static final Pattern ALWAYS; static final Pattern ANY_CHAR; static final Pattern EOF; static final Pattern ESCAPED; static final Pattern INTEGER; static final Pattern STRICT_DECIMAL; static final Pattern FRACTION; static final Pattern DECIMAL; static final Pattern WORD; static final Pattern OCT_INTEGER; static final Pattern DEC_INTEGER; static final Pattern HEX_INTEGER; static final Pattern SCIENTIFIC_NOTATION; static final Pattern REGEXP_PATTERN; static final Pattern REGEXP_MODIFIERS; }
@Test public void testRange() { assertEquals(1, Patterns.range('a', 'c').match("a", 0, 1)); assertEquals(1, Patterns.range('a', 'c').match("b", 0, 1)); assertEquals(1, Patterns.range('a', 'c').match("c", 0, 1)); assertEquals(1, Patterns.range('a', 'c').match("abc", 0, 1)); assertEquals(1, Patterns.range('a', 'c').match("ba", 1, 2)); assertEquals(MISMATCH, Patterns.range('a', 'c').match("d", 0, 1)); assertEquals(MISMATCH, Patterns.range('a', 'c').match("0", 0, 1)); assertEquals(MISMATCH, Patterns.range('a', 'c').match("a", 0, 0)); assertEquals(MISMATCH, Patterns.range('a', 'c').match("a", 0, 0)); }