Skip to content

Commit

Permalink
Merge pull request #24 from fauna/feature/BT-4418-faunaparser_read_do…
Browse files Browse the repository at this point in the history
…cument

[BT-4418] FaunaParser Document values
  • Loading branch information
pchitolina-fauna authored Jan 31, 2024
2 parents af0ac35 + 2fcbccb commit 16dfbd6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,14 @@ private void handleStartObject() throws IOException {
tokenStack.push(InternalTokenType.START_ESCAPED_OBJECT);
break;
case DOC_TAG:
advanceTrue();
currentFaunaTokenType = FaunaTokenType.START_DOCUMENT;
tokenStack.push(FaunaTokenType.START_DOCUMENT);
break;
case REF_TAG:
case SET_TAG:
throw new SerializationException(
"Token not implemented: " + jsonParser.currentToken());
"Token not implemented: " + jsonParser.getText());
default:
bufferedFaunaTokenType = FaunaTokenType.FIELD_NAME;
tokenStack.push(FaunaTokenType.START_OBJECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,37 @@ public void testReadEscapedObject() throws IOException {
assertReader(reader, expectedTokens);
}

@Test
public void testReadDocumentTokens() throws IOException {
String s = "{\n" +
" \"@doc\": {\n" +
" \"id\": \"123\",\n" +
" \"coll\": { \"@mod\": \"Coll\" },\n" +
" \"ts\": { \"@time\": \"2023-12-03T16:07:23.111012Z\" },\n" +
" \"data\": { \"foo\": \"bar\" }\n" +
" }\n" +
"}";
FaunaParser reader = new FaunaParser(new ByteArrayInputStream(s.getBytes()));

List<Map.Entry<FaunaTokenType, Object>> expectedTokens = List.of(
new AbstractMap.SimpleEntry<>(FaunaTokenType.START_DOCUMENT, null),
Map.entry(FaunaTokenType.FIELD_NAME, "id"),
Map.entry(FaunaTokenType.STRING, "123"),
Map.entry(FaunaTokenType.FIELD_NAME, "coll"),
Map.entry(FaunaTokenType.MODULE, new Module("Coll")),
Map.entry(FaunaTokenType.FIELD_NAME, "ts"),
Map.entry(FaunaTokenType.TIME, Instant.parse("2023-12-03T16:07:23.111012Z")),
Map.entry(FaunaTokenType.FIELD_NAME, "data"),
new AbstractMap.SimpleEntry<>(FaunaTokenType.START_OBJECT, null),
Map.entry(FaunaTokenType.FIELD_NAME, "foo"),
Map.entry(FaunaTokenType.STRING, "bar"),
new AbstractMap.SimpleEntry<>(FaunaTokenType.END_OBJECT, null),
new AbstractMap.SimpleEntry<>(FaunaTokenType.END_DOCUMENT, 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 16dfbd6

Please sign in to comment.