Skip to content

Commit 8694d56

Browse files
authored
Migrate resource_with_lists test to wit-bindgen test (#1263)
1 parent 5708666 commit 8694d56

File tree

10 files changed

+81
-111
lines changed

10 files changed

+81
-111
lines changed

crates/test-rust-wasm/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,3 @@ test = false
2626
[[bin]]
2727
name = "resources"
2828
test = false
29-
30-
[[bin]]
31-
name = "resource_with_lists"
32-
test = false

crates/test-rust-wasm/src/bin/resource_with_lists.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package example:composition;
2+
3+
let a = new test:leaf { ... };
4+
let b = new test:resource-with-lists { ...a, ... };
5+
let c = new test:runner { ...b, ... };
6+
7+
export c...;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
include!(env!("BINDINGS"));
2+
3+
use crate::exports::test::resource_with_lists::test::{Guest, GuestThing};
4+
use std::cell::RefCell;
5+
6+
#[derive(Default)]
7+
pub struct MyThing(RefCell<Vec<u8>>);
8+
9+
struct Component;
10+
11+
export!(Component);
12+
13+
impl Guest for Component {
14+
type Thing = MyThing;
15+
}
16+
17+
impl GuestThing for MyThing {
18+
fn new(mut l: Vec<u8>) -> MyThing {
19+
l.extend_from_slice(" HostThing".as_bytes());
20+
MyThing(RefCell::new(l))
21+
}
22+
23+
fn foo(&self) -> Vec<u8> {
24+
let mut list = self.0.borrow().clone();
25+
list.extend_from_slice(" HostThing.foo".as_bytes());
26+
list
27+
}
28+
29+
fn bar(&self, mut l: Vec<u8>) {
30+
l.extend_from_slice(" HostThing.bar".as_bytes());
31+
*self.0.borrow_mut() = l;
32+
}
33+
34+
fn baz(mut l: Vec<u8>) -> Vec<u8> {
35+
l.extend_from_slice(" HostThing.baz".as_bytes());
36+
l
37+
}
38+
}

tests/runtime/resource_with_lists/wasm.rs renamed to tests/runtime-new/resource_with_lists/resource-with-lists.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
wit_bindgen::generate!({
2-
path: "../../tests/runtime/resource_with_lists",
3-
});
1+
include!(env!("BINDINGS"));
42

53
use exports::test::resource_with_lists::test::GuestThing;
64
use test::resource_with_lists::test::Thing;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
include!(env!("BINDINGS"));
2+
3+
use crate::test::resource_with_lists::test::Thing;
4+
5+
fn main() {
6+
let thing_instance = Thing::new(b"Hi");
7+
8+
assert_eq!(
9+
thing_instance.foo(),
10+
b"Hi Thing HostThing HostThing.foo Thing.foo"
11+
);
12+
13+
thing_instance.bar(b"Hola");
14+
15+
assert_eq!(
16+
thing_instance.foo(),
17+
b"Hola Thing.bar HostThing.bar HostThing.foo Thing.foo"
18+
);
19+
20+
assert_eq!(
21+
Thing::baz(b"Ohayo Gozaimas"),
22+
b"Ohayo Gozaimas Thing.baz HostThing.baz Thing.baz again"
23+
);
24+
}

tests/runtime/resource_with_lists/world.wit renamed to tests/runtime-new/resource_with_lists/test.wit

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//@ dependencies = ['resource-with-lists', 'leaf']
2+
//@ wac = 'compose.wac'
3+
14
package test:resource-with-lists;
25

36
interface test {
@@ -9,7 +12,15 @@ interface test {
912
}
1013
}
1114

15+
world leaf {
16+
export test;
17+
}
18+
1219
world resource-with-lists {
1320
import test;
1421
export test;
1522
}
23+
24+
world runner {
25+
import test;
26+
}

tests/runtime/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use wit_parser::{Resolve, WorldId, WorldItem};
1515

1616
mod flavorful;
1717
mod options;
18-
mod resource_with_lists;
1918
mod resources;
2019
mod results;
2120

tests/runtime/resource_with_lists.rs

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)