Skip to content

Commit da2aed4

Browse files
authored
Migrate resource-borrow-in-record test to wit-bindgen test (#1237)
Nothing, just a normal test.
1 parent a2922e2 commit da2aed4

File tree

11 files changed

+107
-138
lines changed

11 files changed

+107
-138
lines changed

crates/test-rust-wasm/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ test = false
4040
name = "resources"
4141
test = false
4242

43-
[[bin]]
44-
name = "resource_borrow_in_record"
45-
test = false
46-
4743
[[bin]]
4844
name = "resource_floats"
4945
test = false

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

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using System.Diagnostics;
4+
using RunnerWorld.wit.imports.test.resourceBorrowInRecord;
5+
using System.Text;
6+
7+
public class Program {
8+
public static void Main() {
9+
IToTest.Thing thing1 = new IToTest.Thing("Bonjour");
10+
IToTest.Thing thing2 = new IToTest.Thing("mon cher");
11+
12+
List<IToTest.Foo> myList = new List<IToTest.Foo>();
13+
myList.Add(new IToTest.Foo(thing1));
14+
myList.Add(new IToTest.Foo(thing2));
15+
List<IToTest.Thing> ret = ToTestInterop.Test(myList);
16+
17+
Debug.Assert(ret[0].Get() == "Bonjour new test get");
18+
Debug.Assert(ret[1].Get() == "mon cher new test get");
19+
}
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
include!(env!("BINDINGS"));
2+
3+
use crate::test::resource_borrow_in_record::to_test::{test, Foo, Thing};
4+
5+
fn main() {
6+
let thing1 = Thing::new("Bonjour");
7+
let thing2 = Thing::new("mon cher");
8+
let result = test(&[Foo { thing: &thing1 }, Foo { thing: &thing2 }])
9+
.into_iter()
10+
.map(|x| x.get())
11+
.collect::<Vec<_>>();
12+
assert_eq!(result, ["Bonjour new test get", "mon cher new test get"]);
13+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using TestWorld.wit.exports.test.resourceBorrowInRecord;
2+
3+
public class ToTestImpl : IToTest {
4+
public class Thing : IToTest.Thing, IToTest.IThing {
5+
public string val;
6+
7+
public Thing(string v) {
8+
this.val = v + " new";
9+
}
10+
11+
public Thing(Thing other) {
12+
this.val = other.val + " test";
13+
}
14+
15+
public string Get() {
16+
return val + " get";
17+
}
18+
}
19+
20+
public static List<IToTest.Thing> Test(List<IToTest.Foo> v) {
21+
var myResult = new List<IToTest.Thing>();
22+
foreach (var foo in v)
23+
{
24+
myResult.Add(new Thing((Thing) foo.thing));
25+
}
26+
return myResult;
27+
}
28+
}
29+
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_borrow_in_record::to_test::{Foo, Guest, GuestThing, Thing};
4+
5+
export!(Component);
6+
7+
struct Component;
8+
9+
impl Guest for Component {
10+
type Thing = MyThing;
11+
12+
fn test(list: Vec<Foo<'_>>) -> Vec<Thing> {
13+
list.iter()
14+
.map(|foo| {
15+
Thing::new(MyThing {
16+
contents: format!("{} test", foo.thing.get::<MyThing>().contents),
17+
})
18+
})
19+
.collect()
20+
// ..
21+
}
22+
}
23+
24+
#[derive(Clone)]
25+
struct MyThing {
26+
contents: String,
27+
}
28+
29+
impl GuestThing for MyThing {
30+
fn new(msg: String) -> MyThing {
31+
MyThing {
32+
contents: format!("{msg} new"),
33+
}
34+
}
35+
fn get(&self) -> String {
36+
format!("{} get", self.contents)
37+
}
38+
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package test:resource-borrow-in-record;
22

3-
interface test {
3+
interface to-test {
44
resource thing {
55
constructor(s: string);
66
get: func() -> string;
@@ -13,7 +13,10 @@ interface test {
1313
test: func(a: list<foo>) -> list<thing>;
1414
}
1515

16-
world resource-borrow-in-record {
17-
import test;
18-
export test;
16+
world test {
17+
export to-test;
18+
}
19+
20+
world runner {
21+
import to-test;
1922
}

tests/runtime/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ mod resource_alias;
2020
mod resource_alias_redux;
2121
mod resource_borrow_export;
2222
mod resource_borrow_import;
23-
mod resource_borrow_in_record;
2423
mod resource_borrow_simple;
2524
mod resource_floats;
2625
mod resource_import_and_export;

tests/runtime/resource_borrow_in_record.rs

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

0 commit comments

Comments
 (0)