-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test): dummy writers and readers
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
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,25 @@ | ||
package bridge | ||
|
||
class DummyReader(private val contents: Array<ByteArray>) : Reader { | ||
private var index = 0 | ||
|
||
override suspend fun read(): Reader.Result { | ||
return readSync() | ||
} | ||
|
||
override fun readSync(): Reader.Result { | ||
// If we have read all the contents, return closed. | ||
if (isClosed()) { | ||
return Reader.Result.closed() | ||
} | ||
|
||
// Increment the index and return the next value. | ||
val value = contents[index] | ||
index += 1 | ||
return Reader.Result.success(value) | ||
} | ||
|
||
override fun isClosed(): Boolean { | ||
return index >= contents.size | ||
} | ||
} |
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,25 @@ | ||
package bridge | ||
|
||
class DummyWriter : Writer { | ||
private val values = mutableListOf<ByteArray>() | ||
private var closed = false | ||
|
||
override suspend fun push(value: ByteArray) { | ||
pushSync(value) | ||
} | ||
|
||
override fun pushSync(value: ByteArray) { | ||
if (closed) { | ||
throw IllegalStateException("Cannot push to closed writer.") | ||
} | ||
values.add(value) | ||
} | ||
|
||
override fun close() { | ||
closed = true | ||
} | ||
|
||
fun getValues(): List<ByteArray> { | ||
return values | ||
} | ||
} |