aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2021-12-16 20:06:39 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2021-12-16 20:06:39 +0100
commit31c61e74156730f04eef641bfb69b9ee94b62fbd (patch)
tree5025015e5e971f6b71a5309c097a5b1186ba32d9 /src/test
parente5a5c75de02a003bac092e92561bd42ded284656 (diff)
Add Signature and Variant types.
Change-Id: I3579fb8745d7b021af7534d2f0c5a0aa6ce54518
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/eu/mulk/jgvariant/core/DecoderTest.java23
1 files changed, 19 insertions, 4 deletions
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());
}
}