From 31c61e74156730f04eef641bfb69b9ee94b62fbd Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Thu, 16 Dec 2021 20:06:39 +0100 Subject: Add Signature and Variant types. Change-Id: I3579fb8745d7b021af7534d2f0c5a0aa6ce54518 --- .../java/eu/mulk/jgvariant/core/DecoderTest.java | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (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 3cae863..5cf1a1c 100644 --- a/src/test/java/eu/mulk/jgvariant/core/DecoderTest.java +++ b/src/test/java/eu/mulk/jgvariant/core/DecoderTest.java @@ -9,6 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import java.nio.ByteBuffer; +import java.text.ParseException; import java.util.List; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -138,9 +139,11 @@ class DecoderTest { }; var decoder = Decoder.ofVariant(); - var result = (Object[]) decoder.decode(ByteBuffer.wrap(data)); + var variant = decoder.decode(ByteBuffer.wrap(data)); + var result = (Object[]) variant.value(); assertAll( + () -> assertEquals(Signature.parse("((ys)as)"), variant.signature()), () -> assertEquals(2, result.length), () -> assertArrayEquals(new Object[] {(byte) 0x69, "can"}, (Object[]) result[0]), () -> assertEquals(List.of("has", "strings?"), result[1])); @@ -371,7 +374,7 @@ class DecoderTest { } @Test - void testSimpleVariantRecord() { + void testSimpleVariantRecord() throws ParseException { // signature: "(bynqiuxtdsogvmiai)" var data = new byte[] { @@ -413,10 +416,22 @@ class DecoderTest { "hi", "hi", "hi", - 9, + new Variant(Signature.parse("i"), 9), Optional.of(10), List.of(11, 12) }, - (Object[]) decoder.decode(ByteBuffer.wrap(data))); + (Object[]) decoder.decode(ByteBuffer.wrap(data)).value()); + } + + @Test + void testSignatureString() throws ParseException { + var data = + new byte[] { + 0x28, 0x62, 0x79, 0x6E, 0x71, 0x69, 0x75, 0x78, 0x74, 0x64, 0x73, 0x6F, 0x67, 0x76, 0x6D, + 0x69, 0x61, 0x69, 0x29 + }; + + var signature = Signature.parse(ByteBuffer.wrap(data)); + assertEquals("(bynqiuxtdsogvmiai)", signature.toString()); } } -- cgit v1.2.3