Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement JsonStructureParser.currentEvent() #134

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public boolean hasNext() {
return !((state == Event.END_OBJECT || state == Event.END_ARRAY) && scopeStack.isEmpty());
}

@Override
public Event currentEvent() {
return state;
}

@Override
public Event next() {
if (!hasNext()) {
Expand All @@ -121,6 +126,7 @@ private void transition() {
state = Event.END_ARRAY;
}
} else {

// ObjectScope
if (state == Event.KEY_NAME) {
nextStateAndEndOfTheObjectOrArray();
Expand Down
14 changes: 14 additions & 0 deletions impl/src/test/java/org/eclipse/parsson/tests/JsonParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,12 @@ static void testEmptyArrayIterator(JsonParser parser) {
Assertions.assertTrue(parser.hasNext());
Assertions.assertTrue(parser.hasNext());
Assertions.assertEquals(Event.START_ARRAY, parser.next());
Assertions.assertEquals(Event.START_ARRAY, parser.currentEvent());

Assertions.assertTrue(parser.hasNext());
Assertions.assertTrue(parser.hasNext());
Assertions.assertEquals(Event.END_ARRAY, parser.next());
Assertions.assertEquals(Event.END_ARRAY, parser.currentEvent());

Assertions.assertFalse(parser.hasNext());
Assertions.assertFalse(parser.hasNext());
Expand Down Expand Up @@ -212,7 +214,9 @@ void testEmptyArrayIterator2Structure() {

static void testEmptyArrayIterator2(JsonParser parser) {
Assertions.assertEquals(Event.START_ARRAY, parser.next());
Assertions.assertEquals(Event.START_ARRAY, parser.currentEvent());
Assertions.assertEquals(Event.END_ARRAY, parser.next());
Assertions.assertEquals(Event.END_ARRAY, parser.currentEvent());
try {
parser.next();
Assertions.fail("Should have thrown a NoSuchElementException");
Expand All @@ -237,7 +241,9 @@ void testEmptyArrayIterator3Structure() {

static void testEmptyArrayIterator3(JsonParser parser) {
Assertions.assertEquals(Event.START_ARRAY, parser.next());
Assertions.assertEquals(Event.START_ARRAY, parser.currentEvent());
Assertions.assertEquals(Event.END_ARRAY, parser.next());
Assertions.assertEquals(Event.END_ARRAY, parser.currentEvent());
Assertions.assertFalse(parser.hasNext());
try {
parser.next();
Expand Down Expand Up @@ -521,13 +527,21 @@ void testNestedArrayStructure() {

static void testNestedArray(JsonParser parser) {
Assertions.assertEquals(Event.START_ARRAY, parser.next());
Assertions.assertEquals(Event.START_ARRAY, parser.currentEvent());
Assertions.assertEquals(Event.START_ARRAY, parser.next());
Assertions.assertEquals(Event.START_ARRAY, parser.currentEvent());
Assertions.assertEquals(Event.END_ARRAY, parser.next());
Assertions.assertEquals(Event.END_ARRAY, parser.currentEvent());
Assertions.assertEquals(Event.START_ARRAY, parser.next());
Assertions.assertEquals(Event.START_ARRAY, parser.currentEvent());
Assertions.assertEquals(Event.START_ARRAY, parser.next());
Assertions.assertEquals(Event.START_ARRAY, parser.currentEvent());
Assertions.assertEquals(Event.END_ARRAY, parser.next());
Assertions.assertEquals(Event.END_ARRAY, parser.currentEvent());
Assertions.assertEquals(Event.END_ARRAY, parser.next());
Assertions.assertEquals(Event.END_ARRAY, parser.currentEvent());
Assertions.assertEquals(Event.END_ARRAY, parser.next());
Assertions.assertEquals(Event.END_ARRAY, parser.currentEvent());
Assertions.assertFalse(parser.hasNext());
Assertions.assertFalse(parser.hasNext());
}
Expand Down
Loading