Skip to content

Commit 68d353d

Browse files
test(jco): add async stream lower variant test
1 parent a1cac96 commit 68d353d

4 files changed

Lines changed: 28 additions & 8 deletions

File tree

crates/test-components/src/bin/stream_rx.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use wit_bindgen::StreamReader;
1111
use bindings::exports::jco::test_components::use_stream_async;
1212
use bindings::exports::jco::test_components::use_stream_sync;
1313

14-
use bindings::exports::jco::test_components::use_stream_async::ExampleRecord;
14+
use bindings::exports::jco::test_components::use_stream_async::{ExampleVariant, ExampleRecord};
1515

1616
struct Component;
1717

@@ -77,6 +77,10 @@ impl use_stream_async::Guest for Component {
7777
async fn read_stream_values_record(rx: StreamReader<ExampleRecord>) -> Vec<ExampleRecord> {
7878
read_async_values(rx).await
7979
}
80+
81+
async fn read_stream_values_variant(rx: StreamReader<ExampleVariant>) -> Vec<ExampleVariant> {
82+
read_async_values(rx).await
83+
}
8084
}
8185

8286
async fn read_async_values<T>(mut rx: StreamReader<T>) -> Vec<T> {

crates/test-components/wit/all.wit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface example-types {
2828
num(u32),
2929
str(string),
3030
float(f32),
31-
maybe-bool(option<u32>),
31+
maybe-u32(option<u32>),
3232
}
3333

3434
enum example-enum {
@@ -214,7 +214,7 @@ interface use-stream-async {
214214

215215
read-stream-values-record: async func(s: stream<example-record>) -> list<example-record>;
216216

217-
// read-stream-values-variant: async func(s: stream<example-variant>) -> list<example-variant>;
217+
read-stream-values-variant: async func(s: stream<example-variant>) -> list<example-variant>;
218218

219219
// read-stream-values-list-u8: async func(s: stream<list<u8>>) -> list<list<u8>>;
220220
// read-stream-values-list-string: async func(s: stream<list<string>>) -> list<list<string>>;

packages/jco/test/p3/stream-lifts.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ suite("stream<T> lifts", () => {
192192
assert.instanceOf(instance["jco:test-components/get-stream-async"].getStreamVariant, AsyncFunction);
193193

194194
const vals = [
195-
{ tag: "maybe-bool", val: 123 },
196-
{ tag: "maybe-bool", val: null },
195+
{ tag: "maybe-u32", val: 123 },
196+
{ tag: "maybe-u32", val: null },
197197
{ tag: "float", val: 123.1 },
198198
{ tag: "str", val: "string-value" },
199199
{ tag: "num", val: 1 },
@@ -206,11 +206,11 @@ suite("stream<T> lifts", () => {
206206
vals: [
207207
// TODO: wit type representation smoothing mismatch,
208208
// non-nullable option<t> values are *not* wrapped as objects
209-
{ tag: "maybe-bool", val: { tag: "some", val: 123 } },
210-
{ tag: "maybe-bool", val: { tag: "none" } },
209+
{ tag: "maybe-u32", val: { tag: "some", val: 123 } },
210+
{ tag: "maybe-u32", val: { tag: "none" } },
211211
],
212212
partial: true,
213-
typeName: "variant<maybe-bool>",
213+
typeName: "variant<maybe-u32>",
214214
assertEqFn: assert.deepEqual,
215215
});
216216

packages/jco/test/p3/stream-lowers.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,22 @@ suite("stream<T> lowers", () => {
228228
assert.deepEqual(returnedVals, vals);
229229
});
230230

231+
test.skip("variant", async () => {
232+
assert.instanceOf(instance["jco:test-components/use-stream-async"].readStreamValuesVariant, AsyncFunction);
233+
234+
let vals = [
235+
{ tag: "maybe-u32", val: 123 },
236+
{ tag: "maybe-u32", val: null },
237+
{ tag: "float", val: 123.1 },
238+
{ tag: "str", val: "string-value" },
239+
{ tag: "num", val: 1 },
240+
];
241+
let returnedVals = await instance["jco:test-components/use-stream-async"].readStreamValuesVariant(
242+
createReadableStreamFromValues(vals),
243+
);
244+
assert.deepEqual(returnedVals, vals);
245+
});
246+
231247
});
232248

233249
function createReadableStreamFromValues(vals) {

0 commit comments

Comments
 (0)