Skip to content

Commit

Permalink
Company roundtrip just works
Browse files Browse the repository at this point in the history
  • Loading branch information
kajacx committed May 2, 2024
1 parent 942efc4 commit 559b76f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/wit_components/resources/guest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ impl Guest for MyEmployees {
let company = component_test::wit_protocol::companies::Company::new(&name, 80_000);
company.get_name().to_owned()
}

fn company_roundtrip(company: Company) -> Company {
company
}
}

export!(MyEmployees);
14 changes: 14 additions & 0 deletions tests/wit_components/resources/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ pub fn run_test(component_bytes: &[u8]) -> Result<()> {
.unwrap();
assert_eq!(result, "Company Name");

let company = Resource::new_own(store.data_mut().companies.new(MyCompany {
name: "Company Roundtrip".into(),
max_salary: 30_000,
}));

let result = instance
.call_company_roundtrip(&mut store, company)
.unwrap();
assert_eq!(
store.data().companies.get(result.rep()).unwrap().name,
"Company Roundtrip"
);
store.data_mut().companies.drop(result.rep()).unwrap();

assert_eq!(
store.data().companies.resources.len(),
0,
Expand Down
3 changes: 3 additions & 0 deletions tests/wit_components/resources/protocol.wit
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ interface companies {

world resources {
import companies;
use companies.{company};

export create-company: func(name: string) -> string;

export company-roundtrip: func(company: company) -> company;
}

0 comments on commit 559b76f

Please sign in to comment.