Skip to content

Commit 7e0b9b4

Browse files
authored
Document empty bytestring factory (#396)
1 parent 16356bd commit 7e0b9b4

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

bytestring/common/src/ByteString.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public fun ByteString(vararg bytes: UByte): ByteString = if (bytes.isEmpty()) {
5555
ByteString.wrap(bytes.asByteArray())
5656
}
5757

58+
/**
59+
* Returns an empty [ByteString].
60+
*
61+
* @sample kotlinx.io.bytestring.samples.ByteStringSamples.constructEmpty
62+
*/
5863
@JsName("EmptyByteString")
5964
public fun ByteString(): ByteString = ByteString.EMPTY
6065

bytestring/common/test/samples/samples.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,11 @@ class ByteStringSamples {
247247

248248
assertEquals(ByteString(3, 4, 5, 6), byteString)
249249
}
250+
251+
@Test
252+
fun constructEmpty() {
253+
val byteString = ByteString()
254+
assertTrue(byteString.isEmpty())
255+
assertContentEquals(ByteArray(0), byteString.toByteArray())
256+
}
250257
}

0 commit comments

Comments
 (0)