-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
show bytes as hex on all supported platforms (#498)
- Loading branch information
Showing
4 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
12 changes: 11 additions & 1 deletion
12
assertk/src/nativeMain/kotlin/assertk/assertions/support/support.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
package assertk.assertions.support | ||
|
||
internal actual fun displayPlatformSpecific(value: Any?): String { | ||
return value.toString() | ||
return when (value) { | ||
is Byte -> formatHex(value) | ||
else -> value.toString() | ||
} | ||
} | ||
|
||
//TODO: replace with HexFormat when stable | ||
private fun formatHex(byte: Byte) : String { | ||
val topNibble = (byte.toInt() and 0xF0) ushr 4 | ||
val bottomNibble = byte.toInt() and 0x0F | ||
return "0x${topNibble.toString(16).uppercase()}${bottomNibble.toString(16).uppercase()}" | ||
} |
13 changes: 13 additions & 0 deletions
13
assertk/src/nativeTest/kotlin/test/assertk/assertions/support/NativeSupportTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package test.assertk.assertions.support | ||
|
||
import assertk.assertions.support.show | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class NativeSupportTest { | ||
|
||
@Test fun show_byte_array() { | ||
assertEquals("<[0x0A, 0x0F]>", show(byteArrayOf(10, 15))) | ||
} | ||
|
||
} |
12 changes: 11 additions & 1 deletion
12
assertk/src/wasmJsMain/kotlin/assertk/assertions/support/support.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
package assertk.assertions.support | ||
|
||
internal actual fun displayPlatformSpecific(value: Any?): String { | ||
return value.toString() | ||
return when (value) { | ||
is Byte -> formatHex(value) | ||
else -> value.toString() | ||
} | ||
} | ||
|
||
//TODO: replace with HexFormat when stable | ||
private fun formatHex(byte: Byte) : String { | ||
val topNibble = (byte.toInt() and 0xF0) ushr 4 | ||
val bottomNibble = byte.toInt() and 0x0F | ||
return "0x${topNibble.toString(16).uppercase()}${bottomNibble.toString(16).uppercase()}" | ||
} |
12 changes: 12 additions & 0 deletions
12
assertk/src/wasmJsTest/kotlin/test/assertk/assertions/support/WasmJsSupportTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package test.assertk.assertions.support | ||
|
||
import assertk.assertions.support.show | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class WasmJsSupportTest { | ||
|
||
@Test fun show_byte_array() { | ||
assertEquals("<[0x0A, 0x0F]>", show(byteArrayOf(10, 15))) | ||
} | ||
} |