Skip to content

Commit

Permalink
upgraded result lib to 2.0.0 (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieTap authored Apr 2, 2024
1 parent 5e418f4 commit 19fd910
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BinaryExpressionDecoderTest {
}
val expected = Ok(Expression(NumericInstruction.I32Eqz))

val actual = io.github.charlietap.chasm.decoder.wasm.decoder.instruction.BinaryExpressionDecoder(
val actual = BinaryExpressionDecoder(
FakeWasmBinaryReader(),
instructionBlockDecoder,
)
Expand All @@ -34,7 +34,7 @@ class BinaryExpressionDecoderTest {
val err = ioError()
val reader = IOErrorWasmFileReader(err)

val actual = io.github.charlietap.chasm.decoder.wasm.decoder.instruction.BinaryExpressionDecoder(reader)
val actual = BinaryExpressionDecoder(reader)

assertEquals(err, actual)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.github.michaelbull.result.Ok
import io.github.charlietap.chasm.ast.value.NameValue
import io.github.charlietap.chasm.decoder.wasm.decoder.value.name.NameValueDecoder
import io.github.charlietap.chasm.decoder.wasm.fixture.ioError
import io.github.charlietap.chasm.decoder.wasm.reader.FakeWasmBinaryReader
import io.github.charlietap.chasm.decoder.wasm.reader.FakeUIntReader
import io.github.charlietap.chasm.decoder.wasm.reader.IOErrorWasmFileReader
import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -20,8 +20,7 @@ class BinaryGenericVectorDecoderTest {
)
val expected = Ok(Vector(expectedNames))

val int: () -> Ok<UInt> = { Ok(2u) }
val reader = FakeWasmBinaryReader(fakeUIntReader = int)
val reader = FakeUIntReader { Ok(2u) }

val names = sequenceOf(NameValue("one"), NameValue("two")).iterator()
val subDecoder: NameValueDecoder = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.charlietap.chasm.decoder.wasm.decoder.vector

import com.github.michaelbull.result.Ok
import com.github.michaelbull.result.Result
import io.github.charlietap.chasm.decoder.wasm.error.WasmDecodeError
import io.github.charlietap.chasm.decoder.wasm.fixture.ioError
import io.github.charlietap.chasm.decoder.wasm.reader.FakeWasmBinaryReader
import io.github.charlietap.chasm.decoder.wasm.reader.IOErrorWasmFileReader
Expand All @@ -14,8 +16,8 @@ class BinaryVectorDecoderTest {

val expected = Ok(ByteVector(VALID_VECTOR, 16u))

val int: () -> Ok<UInt> = { Ok(16u) }
val bytes: (UInt) -> Ok<UByteArray> = { _ -> Ok(VALID_VECTOR) }
val int: () -> Result<UInt, WasmDecodeError> = { Ok(16u) }
val bytes: (UInt) -> Result<UByteArray, WasmDecodeError> = { _ -> Ok(VALID_VECTOR) }

val reader = FakeWasmBinaryReader(fakeUBytesReader = bytes, fakeUIntReader = int)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.github.charlietap.chasm.decoder.wasm.decoder.vector

import com.github.michaelbull.result.Ok
import io.github.charlietap.chasm.decoder.wasm.fixture.ioError
import io.github.charlietap.chasm.decoder.wasm.reader.FakeWasmBinaryReader
import io.github.charlietap.chasm.decoder.wasm.reader.FakeUIntReader
import io.github.charlietap.chasm.decoder.wasm.reader.IOErrorWasmFileReader
import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -14,8 +14,7 @@ class BinaryVectorLengthDecoderTest {

val expected = Ok(VectorLength(16u))

val int: () -> Ok<UInt> = { Ok(16u) }
val reader = FakeWasmBinaryReader(fakeUIntReader = int)
val reader = FakeUIntReader { Ok(16u) }

val actual = BinaryVectorLengthDecoder(reader)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package io.github.charlietap.chasm.decoder.wasm.reader

import com.github.michaelbull.result.Err
import com.github.michaelbull.result.Result
import io.github.charlietap.chasm.decoder.wasm.error.WasmDecodeError

internal fun IOErrorWasmFileReader(err: Err<WasmDecodeError.IOError>): WasmBinaryReader = object : WasmBinaryReader {
internal fun IOErrorWasmFileReader(err: Result<Nothing, WasmDecodeError.IOError>): WasmBinaryReader = object : WasmBinaryReader {

override fun byte(): Result<Byte, WasmDecodeError> = err

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.github.charlietap.chasm.decoder.wasm.reader

import com.github.michaelbull.result.Ok
import com.github.michaelbull.result.Result
import io.github.charlietap.chasm.decoder.wasm.const.Leb128
import io.github.charlietap.chasm.decoder.wasm.error.WasmDecodeError
import io.github.charlietap.chasm.decoder.wasm.fixture.ioError
import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -10,7 +12,7 @@ class SourceWasmBinaryReaderTest {

@Test
fun `can read a byte from source and forward it on`() {
val expected: Ok<Byte> = Ok(0x01)
val expected: Result<Byte, WasmDecodeError> = Ok(0x01)
val sourceReader = FakeByteSourceReader {
expected.value
}
Expand All @@ -34,7 +36,7 @@ class SourceWasmBinaryReaderTest {

@Test
fun `can read a ubyte from source and forward it on`() {
val expected: Ok<UByte> = Ok(0x01u)
val expected: Result<UByte, WasmDecodeError> = Ok(0x01u)
val sourceReader = FakeByteSourceReader {
expected.value.toByte()
}
Expand All @@ -58,7 +60,7 @@ class SourceWasmBinaryReaderTest {

@Test
fun `can read bytes from source and forward them on`() {
val expected: Ok<ByteArray> = Ok(byteArrayOf(0x01, 0x02))
val expected: Result<ByteArray, WasmDecodeError> = Ok(byteArrayOf(0x01, 0x02))
val sourceReader = FakeByteArraySourceReader { amount ->
assertEquals(2, amount)
expected.value
Expand All @@ -83,7 +85,7 @@ class SourceWasmBinaryReaderTest {

@Test
fun `can read ubytes from source and forward them on`() {
val expected: Ok<UByteArray> = Ok(ubyteArrayOf(0x01u, 0x02u))
val expected: Result<UByteArray, WasmDecodeError> = Ok(ubyteArrayOf(0x01u, 0x02u))
val sourceReader = FakeByteArraySourceReader { amount ->
assertEquals(2, amount)
expected.value.asByteArray()
Expand All @@ -108,7 +110,7 @@ class SourceWasmBinaryReaderTest {

@Test
fun `can read a leb128 encoded int and forward it on`() {
val expected: Ok<Int> = Ok(128)
val expected: Result<Int, WasmDecodeError> = Ok(128)
val source = Leb128.Integer.TWO_BYTES_SIGNED_POSITIVE.asSequence().iterator()
val sourceReader = FakeByteSourceReader {
source.next()
Expand All @@ -133,7 +135,7 @@ class SourceWasmBinaryReaderTest {

@Test
fun `can read a leb128 encoded uint and forward it on`() {
val expected: Ok<UInt> = Ok(128u)
val expected: Result<UInt, WasmDecodeError> = Ok(128u)
val source = Leb128.Integer.TWO_BYTES_UNSIGNED.asSequence().iterator()
val sourceReader = FakeByteSourceReader {
source.next().toByte()
Expand All @@ -158,7 +160,7 @@ class SourceWasmBinaryReaderTest {

@Test
fun `can read a leb128 encoded long and forward it on`() {
val expected: Ok<Long> = Ok(Long.MAX_VALUE)
val expected: Result<Long, WasmDecodeError> = Ok(Long.MAX_VALUE)
val source = Leb128.Long.TEN_BYTES_SIGNED_POSITIVE.asSequence().iterator()
val sourceReader = FakeByteSourceReader {
source.next()
Expand All @@ -183,7 +185,7 @@ class SourceWasmBinaryReaderTest {

@Test
fun `can read an IEEE 754 encoded float and forward it on`() {
val expected: Ok<Float> = Ok(1.5f)
val expected: Result<Float, WasmDecodeError> = Ok(1.5f)
val sourceReader = FakeByteArraySourceReader {
byteArrayOf(0x00.toByte(), 0x00.toByte(), 0xC0.toByte(), 0x3F.toByte())
}
Expand All @@ -207,7 +209,7 @@ class SourceWasmBinaryReaderTest {

@Test
fun `can read an IEEE 754 encoded double and forward it on`() {
val expected: Ok<Double> = Ok(12345.6789)
val expected: Result<Double, WasmDecodeError> = Ok(12345.6789)
val sourceReader = FakeByteArraySourceReader {
byteArrayOf(161.toByte(), 248.toByte(), 49.toByte(), 230.toByte(), 214.toByte(), 28.toByte(), 200.toByte(), 64.toByte())
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ kotlinx-io = "0.3.1"
kotlinx-serialization = "1.5.1"
kotlinx-test-resources = "0.4.1"

result = "1.1.18"
result = "2.0.0"

[plugins]

Expand Down

0 comments on commit 19fd910

Please sign in to comment.