diff --git a/impl/src/main/java/org/eclipse/parsson/JsonStructureParser.java b/impl/src/main/java/org/eclipse/parsson/JsonStructureParser.java index c311698..7f7ac2a 100644 --- a/impl/src/main/java/org/eclipse/parsson/JsonStructureParser.java +++ b/impl/src/main/java/org/eclipse/parsson/JsonStructureParser.java @@ -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()) { @@ -121,6 +126,7 @@ private void transition() { state = Event.END_ARRAY; } } else { + // ObjectScope if (state == Event.KEY_NAME) { nextStateAndEndOfTheObjectOrArray(); diff --git a/impl/src/test/java/org/eclipse/parsson/tests/JsonParserTest.java b/impl/src/test/java/org/eclipse/parsson/tests/JsonParserTest.java index 556512a..5fba5cc 100644 --- a/impl/src/test/java/org/eclipse/parsson/tests/JsonParserTest.java +++ b/impl/src/test/java/org/eclipse/parsson/tests/JsonParserTest.java @@ -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()); @@ -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"); @@ -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(); @@ -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()); }