Skip to content

Commit

Permalink
Merge pull request #25 from fauna/feature/BT-4418-faunaparser_read_set
Browse files Browse the repository at this point in the history
[BT-4418] FaunaParser Set values
  • Loading branch information
pchitolina-fauna authored Jan 31, 2024
2 parents 16dfbd6 + 418eaee commit c4df959
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,12 @@ private void handleStartObject() throws IOException {
currentFaunaTokenType = FaunaTokenType.START_DOCUMENT;
tokenStack.push(FaunaTokenType.START_DOCUMENT);
break;
case REF_TAG:
case SET_TAG:
advanceTrue();
currentFaunaTokenType = FaunaTokenType.START_PAGE;
tokenStack.push(FaunaTokenType.START_PAGE);
break;
case REF_TAG:
throw new SerializationException(
"Token not implemented: " + jsonParser.getText());
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,30 @@ public void testReadDocumentTokens() throws IOException {
assertReader(reader, expectedTokens);
}

@Test
public void testReadSet() throws IOException {
String s = "{\n" +
" \"@set\": {\n" +
" \"data\": [{\"@int\": \"99\"}],\n" +
" \"after\": \"afterme\"\n" +
" }\n" +
"}";
FaunaParser reader = new FaunaParser(new ByteArrayInputStream(s.getBytes()));

List<Map.Entry<FaunaTokenType, Object>> expectedTokens = List.of(
new AbstractMap.SimpleEntry<>(FaunaTokenType.START_PAGE, null),
Map.entry(FaunaTokenType.FIELD_NAME, "data"),
new AbstractMap.SimpleEntry<>(FaunaTokenType.START_ARRAY, null),
Map.entry(FaunaTokenType.INT, 99),
new AbstractMap.SimpleEntry<>(FaunaTokenType.END_ARRAY, null),
Map.entry(FaunaTokenType.FIELD_NAME, "after"),
Map.entry(FaunaTokenType.STRING, "afterme"),
new AbstractMap.SimpleEntry<>(FaunaTokenType.END_PAGE, null)
);

assertReader(reader, expectedTokens);
}

private static void assertReader(FaunaParser reader,
List<Map.Entry<FaunaTokenType, Object>> tokens) throws IOException {
for (Map.Entry<FaunaTokenType, Object> entry : tokens) {
Expand Down

0 comments on commit c4df959

Please sign in to comment.