From cf41e138389d27f5e5f7cec5def64321d35d8275 Mon Sep 17 00:00:00 2001 From: Philippe Marschall Date: Sun, 10 Nov 2024 13:28:45 +0100 Subject: [PATCH 1/2] Implement JsonStructureParser.currentEvent() --- .../org/eclipse/parsson/JsonStructureParser.java | 5 +++++ .../org/eclipse/parsson/tests/JsonParserTest.java | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/impl/src/main/java/org/eclipse/parsson/JsonStructureParser.java b/impl/src/main/java/org/eclipse/parsson/JsonStructureParser.java index c311698..bccca2b 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()) { 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()); } From 48d478e39d8d5a74b0a67b400b59a84a5e36603f Mon Sep 17 00:00:00 2001 From: Jorge Bescos Gascon Date: Tue, 12 Nov 2024 12:46:41 +0100 Subject: [PATCH 2/2] Update JsonStructureParser.java Trigger the GH actions --- impl/src/main/java/org/eclipse/parsson/JsonStructureParser.java | 1 + 1 file changed, 1 insertion(+) diff --git a/impl/src/main/java/org/eclipse/parsson/JsonStructureParser.java b/impl/src/main/java/org/eclipse/parsson/JsonStructureParser.java index bccca2b..7f7ac2a 100644 --- a/impl/src/main/java/org/eclipse/parsson/JsonStructureParser.java +++ b/impl/src/main/java/org/eclipse/parsson/JsonStructureParser.java @@ -126,6 +126,7 @@ private void transition() { state = Event.END_ARRAY; } } else { + // ObjectScope if (state == Event.KEY_NAME) { nextStateAndEndOfTheObjectOrArray();