diff options
author | nea <romangraef@gmail.com> | 2022-09-13 00:25:28 +0200 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2022-09-13 00:25:28 +0200 |
commit | b7793a83b1f39ff94bfbaeef8ac4c387839a94de (patch) | |
tree | 2d89200e800de8230cf91aa4741d9958edd76d0a /src/test/kotlin | |
parent | 24b3430c42614bc2f9076a8a04d79720c05bb67b (diff) | |
download | javamailserver-b7793a83b1f39ff94bfbaeef8ac4c387839a94de.tar.gz javamailserver-b7793a83b1f39ff94bfbaeef8ac4c387839a94de.tar.bz2 javamailserver-b7793a83b1f39ff94bfbaeef8ac4c387839a94de.zip |
Diffstat (limited to 'src/test/kotlin')
-rw-r--r-- | src/test/kotlin/moe/nea89/mail/util/ProtocolSpec.kt | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/kotlin/moe/nea89/mail/util/ProtocolSpec.kt b/src/test/kotlin/moe/nea89/mail/util/ProtocolSpec.kt new file mode 100644 index 0000000..9a4bcbf --- /dev/null +++ b/src/test/kotlin/moe/nea89/mail/util/ProtocolSpec.kt @@ -0,0 +1,41 @@ +package moe.nea89.mail.util + +import Protocol +import findSubarray +import io.kotest.core.spec.style.FreeSpec +import io.kotest.datatest.withData +import readUntil +import java.io.ByteArrayInputStream +import java.io.ByteArrayOutputStream + + +data class ByteArrayString(val hay: String, val needle: String, val position: Int?, val offset: Int = 0) +class ProtocolSpec : FreeSpec({ + "ByteArray.findSubarray" - { + "should work correctly" - { + withData( + listOf( + ByteArrayString("abc", "a", 0), + ByteArrayString("abca", "a", 0), + ByteArrayString("abca", "a", 3, 2), + ByteArrayString("abca", "a", 3, 3), + ByteArrayString("bc", "a", null), + ByteArrayString("acbcab", "ab", 4), + ByteArrayString("abcbcab", "ab", 5, 1), + ) + ) { (hay, needle, position, offset) -> + val hay = hay.encodeToByteArray() + val needle = needle.encodeToByteArray() + assert(hay.findSubarray(needle, offset) == position) + } + } + } + "Protocol.IO" - { + "readUntil" { + val data = ("a".repeat(9) + "01" + "b".repeat(10) + "02").encodeToByteArray() + val protIO = Protocol.IO.FromStreams(ByteArrayInputStream(data), ByteArrayOutputStream()) + assert(protIO.readUntil("01".encodeToByteArray()).decodeToString() == "a".repeat(9)) + assert(protIO.readUntil("02".encodeToByteArray()).decodeToString() == "b".repeat(10)) + } + } +}) |