Skip to content

Commit

Permalink
Add unit tests for from_json()/to_json() with nested arrays. (#242,
Browse files Browse the repository at this point in the history
  • Loading branch information
blackwinter committed Jul 15, 2022
1 parent 327bc7f commit e47c76c
Showing 1 changed file with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,42 @@ public void shouldConvertArrayFromJson() {
);
}

@Test
public void shouldConvertNestedArrayFromJson() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"from_json(test)"
),
i -> {
i.startRecord("1");
i.literal("test", "{\"zoo[]\":[{\"animals[]\":[[\"ant\",\"dog\"],\"cat\",[\"fish\",[\"zebra\",\"horse\"],\"hippo\"],\"giraffe\"]}]}");
i.endRecord();
},
(o, f) -> {
o.get().startRecord("1");
o.get().startEntity("test");
o.get().startEntity("zoo[]");
o.get().startEntity("1");
o.get().startEntity("animals[]");
o.get().startEntity("1[]");
o.get().literal("1", "ant");
o.get().literal("2", "dog");
o.get().endEntity();
o.get().literal("2", "cat");
o.get().startEntity("3[]");
o.get().literal("1", "fish");
o.get().startEntity("2[]");
o.get().literal("1", "zebra");
o.get().literal("2", "horse");
o.get().endEntity();
o.get().literal("3", "hippo");
o.get().endEntity();
o.get().literal("4", "giraffe");
f.apply(4).endEntity();
o.get().endRecord();
}
);
}

@Test
public void shouldConvertHashFromJson() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
Expand Down Expand Up @@ -3308,6 +3344,45 @@ public void shouldConvertArrayToJson() {
);
}

@Test
public void shouldConvertNestedArrayToJson() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"to_json(test)"
),
i -> {
i.startRecord("1");
i.startEntity("test");
i.startEntity("zoo[]");
i.startEntity("1");
i.startEntity("animals[]");
i.startEntity("1[]");
i.literal("1", "ant");
i.literal("2", "dog");
i.endEntity();
i.literal("2", "cat");
i.startEntity("3[]");
i.literal("1", "fish");
i.startEntity("2[]");
i.literal("1", "zebra");
i.literal("2", "horse");
i.endEntity();
i.literal("3", "hippo");
i.endEntity();
i.literal("4", "giraffe");
i.endEntity();
i.endEntity();
i.endEntity();
i.endEntity();
i.endRecord();
},
o -> {
o.get().startRecord("1");
o.get().literal("test", "{\"zoo[]\":[{\"animals[]\":[[\"ant\",\"dog\"],\"cat\",[\"fish\",[\"zebra\",\"horse\"],\"hippo\"],\"giraffe\"]}]}");
o.get().endRecord();
}
);
}

@Test
public void shouldConvertHashToJson() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
Expand Down

0 comments on commit e47c76c

Please sign in to comment.