Skip to content

Commit

Permalink
test driver: avoid using mutation on bytes (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu-zh authored Dec 2, 2024
1 parent b7ae8ff commit 5aba6b4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions crates/moonbuild/template/test_driver/wasm_args.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ fn moonbit_test_driver_internal_string_read_char(handle : MoonbitTestDriverInter

fn moonbit_test_driver_internal_finish_read_string(handle : MoonbitTestDriverInternalStringReadHandle) = "__moonbit_fs_unstable" "finish_read_string"

fn fixedarray_to_bytes(arr : FixedArray[Byte]) -> Bytes = "%identity"

fn moonbit_test_driver_internal_string_from_extern(e : MoonbitTestDriverInternalExternString) -> String {
let buf = Bytes::new(512)
let buf = FixedArray::make(512, Byte::default())
let mut len = 0
let handle = moonbit_test_driver_internal_begin_read_string(e)
while true {
let ch = moonbit_test_driver_internal_string_read_char(handle)
if ch == -1 {
break
} else {
let written_bytes_len = buf.set_utf16_char(len, Char::from_int(ch))
let written_bytes_len = buf.set_utf16le_char(len, Char::from_int(ch))
len += written_bytes_len
}
}
moonbit_test_driver_internal_finish_read_string(handle)
buf.to_unchecked_string(offset = 0, length = len).to_string()
fixedarray_to_bytes(buf).to_unchecked_string(offset = 0, length = len).to_string()
}

0 comments on commit 5aba6b4

Please sign in to comment.