use of org.antlr.v4.runtime.UnbufferedCharStream in project antlr4 by antlr.
the class TestUnbufferedCharStream method testLastChar.
@Test
public void testLastChar() {
CharStream input = createStream("abcdef");
input.consume();
assertEquals('a', input.LA(-1));
int m1 = input.mark();
input.consume();
input.consume();
input.consume();
assertEquals('d', input.LA(-1));
input.seek(2);
assertEquals('b', input.LA(-1));
input.release(m1);
input.seek(3);
assertEquals('c', input.LA(-1));
// this special case is not required by the IntStream interface, but
// UnbufferedCharStream allows it so we have to make sure the resulting
// state is consistent
input.seek(2);
assertEquals('b', input.LA(-1));
}
use of org.antlr.v4.runtime.UnbufferedCharStream in project antlr4 by antlr.
the class TestUnbufferedCharStream method testNestedMarkReleasedTwice.
/**
* The {@link IntStream} interface does not specify the behavior when a mark
* is released twice, but {@link UnbufferedCharStream} handles this case by
* throwing an {@link IllegalStateException}.
*/
@Test(expected = IllegalStateException.class)
public void testNestedMarkReleasedTwice() {
CharStream input = createStream("");
int m1 = input.mark();
int m2 = input.mark();
input.release(m2);
input.release(m2);
}
use of org.antlr.v4.runtime.UnbufferedCharStream in project antlr4 by antlr.
the class TestUnbufferedCharStream method testMarkPassedToSeek.
/**
* It is not valid to pass a mark to {@link IntStream#seek}, but
* {@link UnbufferedCharStream} creates marks in such a way that this
* invalid usage results in an {@link IllegalArgumentException}.
*/
@Test(expected = IllegalArgumentException.class)
public void testMarkPassedToSeek() {
CharStream input = createStream("");
int m1 = input.mark();
input.seek(m1);
}
use of org.antlr.v4.runtime.UnbufferedCharStream in project antlr4 by antlr.
the class TestUnbufferedCharStream method testConsumeEOF.
/**
* The {@link IntStream} interface does not specify the behavior when the
* EOF symbol is consumed, but {@link UnbufferedCharStream} handles this
* particular case by throwing an {@link IllegalStateException}.
*/
@Test(expected = IllegalStateException.class)
public void testConsumeEOF() throws Exception {
CharStream input = createStream("");
assertEquals(IntStream.EOF, input.LA(1));
input.consume();
input.consume();
}
use of org.antlr.v4.runtime.UnbufferedCharStream in project antlr4 by antlr.
the class TestUnbufferedCharStream method testMarkReleaseOutOfOrder.
/**
* The {@link IntStream} interface does not specify the behavior when marks
* are not released in the reversed order they were created, but
* {@link UnbufferedCharStream} handles this case by throwing an
* {@link IllegalStateException}.
*/
@Test(expected = IllegalStateException.class)
public void testMarkReleaseOutOfOrder() {
CharStream input = createStream("");
int m1 = input.mark();
int m2 = input.mark();
input.release(m1);
}
Aggregations