Skip to content

Commit

Permalink
cbor: add test for unlabeled inner bytestrings
Browse files Browse the repository at this point in the history
  • Loading branch information
the-eater committed Oct 18, 2023
1 parent dfee01c commit 6292f2c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,18 @@ class CborReaderTest {
)
}

@Test
fun testReadValueClassWithUnlabeledByteString() {
assertContentEquals(
expected = byteArrayOf(
0x11,
0x22,
0x33
),
actual = Cbor.decodeFromHexString<ValueClassWithUnlabeledByteString>("43112233").x.x
)
}

@Test
fun testIgnoresTagsOnStrings() {
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,12 @@ class CbrWriterTest {
actual = Cbor.encodeToHexString(ValueClassWithCustomByteString(CustomByteString(0x11, 0x22, 0x33)))
)
}

@Test
fun testWriteValueClassWithUnlabeledByteString() {
assertEquals(
expected = "43112233",
actual = Cbor.encodeToHexString(ValueClassWithUnlabeledByteString(ValueClassWithUnlabeledByteString.Inner(byteArrayOf(0x11, 0x22, 0x33))))
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,12 @@ value class ValueClassWithByteString(@ByteString val x: ByteArray)

@JvmInline
@Serializable
value class ValueClassWithCustomByteString(@ByteString val x: CustomByteString)
value class ValueClassWithCustomByteString(@ByteString val x: CustomByteString)

@JvmInline
@Serializable
value class ValueClassWithUnlabeledByteString(@ByteString val x: Inner) {
@JvmInline
@Serializable
value class Inner(val x: ByteArray)
}

0 comments on commit 6292f2c

Please sign in to comment.