AbstractCharStreamScanner implements CharStreamScanner { @Override public boolean expect(String expected) { return expect(expected, false); } AbstractCharStreamScanner(); @Override int readDigit(); @Override double readDouble(); @Override float readFloat(); @Override int skipWhile(CharFilter filter); @Override char skipWhileAndPeek(CharFilter filter); @Override char skipWhileAndPeek(CharFilter filter, int max); @Override String readWhile(CharFilter filter); @Override String readUntil(CharFilter filter, boolean acceptEof, String stop); @Override String readUntil(CharFilter filter, boolean acceptEot, String stop, boolean ignoreCase); @Override boolean skipOver(String substring); @Override boolean skipOver(String substring, boolean ignoreCase); @Override String readLine(); @Override boolean expect(String expected); @Override boolean expectStrict(String expected); @Override Character readJavaCharLiteral(); @Override String readJavaStringLiteral();  }
@Test public void testSkipUntil() { CharStreamScanner scanner = scanner("string"); assertThat(scanner.skipUntil('n')).isTrue(); assertThat(scanner.next()).isEqualTo('g'); assertThat(scanner.hasNext()).isFalse(); String end = "12345"; scanner = scanner("\"Quotet text with \\\" inside!\"" + end); assertThat(scanner.next()).isEqualTo('\"'); assertThat(scanner.skipUntil('\"', '\\')).isTrue(); assertThat(scanner.expect(end, false)).isTrue(); }
@Test public void testExpectPositive() { String start = "hello "; String middle = "world"; String end = " this is cool!"; CharStreamScanner scanner = scanner(start + middle + end); assertThat(scanner.expect(start, false)).isTrue(); assertThat(scanner.expect(middle.toUpperCase(Locale.ENGLISH), true)).isTrue(); assertThat(scanner.expect(end.toLowerCase(Locale.ENGLISH), true)).isTrue(); assertThat(scanner.hasNext()).isFalse(); }
@Test public void testExpectNegative() { String string = "string"; CharStreamScanner scanner = scanner(string); assertThat(scanner.expect("strign", false)).isFalse(); assertThat(scanner.read(2)).isEqualTo("ng"); assertThat(scanner.hasNext()).isFalse(); }
@Test public void testExpect() { String string = "public static final String foo;"; CharStreamScanner scanner = scanner(string); assertThat(scanner.expect("public", false)).isTrue(); assertThat(scanner.expect('$')).isFalse(); assertThat(scanner.expect(' ')).isTrue(); assertThat(scanner.expect("StATiC", true)).isTrue(); assertThat(scanner.expect(' ')).isTrue(); assertThat(scanner.expect("FINAL", false)).isFalse(); assertThat(scanner.expect("FINAL", true)).isTrue(); assertThat(scanner.expect(' ')).isTrue(); assertThat(scanner.expect("string", false)).isFalse(); assertThat(scanner.expect("String", false)).isTrue(); assertThat(scanner.forceNext()).isEqualTo(' '); assertThat(scanner.expect("banana", true)).isFalse(); assertThat(scanner.expect("foo", false)).isTrue(); assertThat(scanner.forceNext()).isEqualTo(';'); assertThat(scanner.hasNext()).isFalse(); }