Skip to content

Commit d9cf1f0

Browse files
committed
Add list lowering tests
1 parent 3597d40 commit d9cf1f0

File tree

7 files changed

+25
-0
lines changed

7 files changed

+25
-0
lines changed

tests/runtime/lists/exports.wit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ list-result: function() -> list<u8>
99
list-result2: function() -> string
1010
list-result3: function() -> list<string>
1111

12+
list-roundtrip: function(a: list<u8>) -> list<u8>
1213
string-roundtrip: function(a: string) -> string

tests/runtime/lists/host.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def list_result2(self) -> str:
2828
def list_result3(self) -> List[str]:
2929
return ['hello,', 'world!']
3030

31+
def list_roundtrip(self, a: bytes) -> bytes:
32+
return a
33+
3134
def string_roundtrip(self, a: str) -> str:
3235
return a
3336

tests/runtime/lists/host.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ impl Imports for MyImports {
4343
vec!["hello,".to_string(), "world!".to_string()]
4444
}
4545

46+
fn list_roundtrip(&mut self, list: &[u8]) -> Vec<u8> {
47+
list.to_vec()
48+
}
49+
4650
fn string_roundtrip(&mut self, s: &str) -> String {
4751
s.to_string()
4852
}

tests/runtime/lists/host.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ async function run() {
2525
},
2626
listResult2() { return 'hello!'; },
2727
listResult3() { return ['hello,', 'world!']; },
28+
listRoundtrip(x) { return x; },
2829
stringRoundtrip(x) { return x; },
2930

3031
unalignedRoundtrip1(u16, u32, u64, flag32, flag64) {
@@ -119,6 +120,12 @@ async function run() {
119120
assert.deepStrictEqual(Array.from(wasm.listResult()), [1, 2, 3, 4, 5]);
120121
assert.deepStrictEqual(wasm.listResult2(), "hello!");
121122
assert.deepStrictEqual(wasm.listResult3(), ["hello,", "world!"]);
123+
124+
const buffer = new ArrayBuffer(8);
125+
(new Uint8Array(buffer)).set(new Uint8Array([1, 2, 3, 4]), 2);
126+
// Create a view of the four bytes in the middle of the buffer
127+
const view = new Uint8Array(buffer, 2, 4);
128+
assert.deepStrictEqual(Array.from(wasm.listRoundtrip(view)), [1, 2, 3, 4]);
122129

123130
assert.deepStrictEqual(wasm.stringRoundtrip("x"), "x");
124131
assert.deepStrictEqual(wasm.stringRoundtrip(""), "");

tests/runtime/lists/imports.wit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ list-minmax32: function(a: list<u32>, b: list<s32>) -> (list<u32>, list<s32>)
3030
list-minmax64: function(a: list<u64>, b: list<s64>) -> (list<u64>, list<s64>)
3131
list-minmax-float: function(a: list<f32>, b: list<f64>) -> (list<f32>, list<f64>)
3232

33+
list-roundtrip: function(a: list<u8>) -> list<u8>
34+
3335
string-roundtrip: function(a: string) -> string
3436

3537
unaligned-roundtrip1: function(a: list<u16>, b: list<u32>, c: list<u64>, d: list<flag32>, e: list<flag64>)

tests/runtime/lists/wasm.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ void exports_list_result3(exports_list_string_t *ret0) {
283283
exports_string_dup(&ret0->ptr[1], "world!");
284284
}
285285

286+
void exports_list_roundtrip(exports_list_u8_t *a, exports_list_u8_t *ret0) {
287+
*ret0 = *a;
288+
}
289+
286290
void exports_string_roundtrip(exports_string_t *a, exports_string_t *ret0) {
287291
*ret0 = *a;
288292
}

tests/runtime/lists/wasm.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ impl exports::Exports for Exports {
159159
vec!["hello,".to_string(), "world!".to_string()]
160160
}
161161

162+
fn list_roundtrip(x: Vec<u8>) -> Vec<u8> {
163+
x.clone()
164+
}
165+
162166
fn string_roundtrip(x: String) -> String {
163167
x.clone()
164168
}

0 commit comments

Comments
 (0)