()
| 8 | |
| 9 | #[test] |
| 10 | fn record_derive() -> Result<()> { |
| 11 | #[derive(ComponentType, Lift, Lower, PartialEq, Eq, Debug, Copy, Clone)] |
| 12 | #[component(record)] |
| 13 | struct Foo { |
| 14 | #[component(name = "foo-bar-baz")] |
| 15 | a: i32, |
| 16 | b: u32, |
| 17 | } |
| 18 | |
| 19 | let engine = super::engine(); |
| 20 | let mut store = Store::new(&engine, ()); |
| 21 | |
| 22 | // Happy path: component type matches field count, names, and types |
| 23 | |
| 24 | let component = Component::new( |
| 25 | &engine, |
| 26 | make_echo_component(r#"(record (field "foo-bar-baz" s32) (field "b" u32))"#, 8), |
| 27 | )?; |
| 28 | let instance = Linker::new(&engine).instantiate(&mut store, &component)?; |
| 29 | |
| 30 | let input = Foo { a: -42, b: 73 }; |
| 31 | let output = instance |
| 32 | .get_typed_func::<(Foo,), (Foo,)>(&mut store, "echo")? |
| 33 | .call(&mut store, (input,))?; |
| 34 | |
| 35 | assert_eq!((input,), output); |
| 36 | |
| 37 | // Sad path: field count mismatch (too few) |
| 38 | |
| 39 | let component = Component::new( |
| 40 | &engine, |
| 41 | make_echo_component(r#"(record (field "foo-bar-baz" s32))"#, 4), |
| 42 | )?; |
| 43 | let instance = Linker::new(&engine).instantiate(&mut store, &component)?; |
| 44 | |
| 45 | assert!( |
| 46 | instance |
| 47 | .get_typed_func::<(Foo,), (Foo,)>(&mut store, "echo") |
| 48 | .is_err() |
| 49 | ); |
| 50 | |
| 51 | // Sad path: field count mismatch (too many) |
| 52 | |
| 53 | let component = Component::new( |
| 54 | &engine, |
| 55 | make_echo_component( |
| 56 | r#"(record (field "foo-bar-baz" s32) (field "b" u32) (field "c" u32))"#, |
| 57 | 12, |
| 58 | ), |
| 59 | )?; |
| 60 | let instance = Linker::new(&engine).instantiate(&mut store, &component)?; |
| 61 | |
| 62 | assert!( |
| 63 | instance |
| 64 | .get_typed_func::<(Foo,), (Foo,)>(&mut store, "echo") |
| 65 | .is_err() |
| 66 | ); |
| 67 |
nothing calls this directly
no test coverage detected