From 55c34814bc7e6749a1530e7b36b51e0bc6358df3 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 14 Dec 2021 21:51:10 +0100 Subject: Remove Variant class, parse variants into Object. Change-Id: I9b4b3079aea42b74f6fcf6341305b6fded9234f4 --- src/test/java/eu/mulk/jgvariant/core/DecoderTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/test/java') diff --git a/src/test/java/eu/mulk/jgvariant/core/DecoderTest.java b/src/test/java/eu/mulk/jgvariant/core/DecoderTest.java index d37f6a2..0e16973 100644 --- a/src/test/java/eu/mulk/jgvariant/core/DecoderTest.java +++ b/src/test/java/eu/mulk/jgvariant/core/DecoderTest.java @@ -2,6 +2,8 @@ package eu.mulk.jgvariant.core; import static java.nio.ByteOrder.LITTLE_ENDIAN; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import java.nio.ByteBuffer; @@ -125,6 +127,23 @@ class DecoderTest { decoder.decode(ByteBuffer.wrap(data))); } + @Test + void testNestedStructureVariant() { + var data = + new byte[] { + 0x69, 0x63, 0x61, 0x6E, 0x00, 0x68, 0x61, 0x73, 0x00, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, + 0x73, 0x3F, 0x00, 0x04, 0x0d, 0x05, 0x00, 0x28, 0x28, 0x79, 0x73, 0x29, 0x61, 0x73, 0x29 + }; + + var decoder = Decoder.ofVariant(); + var result = (Object[]) decoder.decode(ByteBuffer.wrap(data)); + + assertAll( + () -> assertEquals(2, result.length), + () -> assertArrayEquals(new Object[] {(byte) 0x69, "can"}, (Object[]) result[0]), + () -> assertEquals(List.of("has", "strings?"), result[1])); + } + @Test void testSimpleStructure() { var data = new byte[] {0x60, 0x70}; -- cgit v1.2.3