()
| 475 | |
| 476 | #[test] |
| 477 | fn records() -> Result<()> { |
| 478 | let engine = super::engine(); |
| 479 | let mut store = Store::new(&engine, ()); |
| 480 | |
| 481 | let component = Component::new( |
| 482 | &engine, |
| 483 | make_echo_component_with_params( |
| 484 | r#" |
| 485 | (type $c' (record |
| 486 | (field "D" bool) |
| 487 | (field "E" u32) |
| 488 | )) |
| 489 | (export $c "c" (type $c')) |
| 490 | (type $Foo' (record |
| 491 | (field "A" u32) |
| 492 | (field "B" float64) |
| 493 | (field "C" $c) |
| 494 | )) |
| 495 | "#, |
| 496 | &[ |
| 497 | Param(Type::I32, Some(0)), |
| 498 | Param(Type::F64, Some(8)), |
| 499 | Param(Type::U8, Some(16)), |
| 500 | Param(Type::I32, Some(20)), |
| 501 | ], |
| 502 | ), |
| 503 | )?; |
| 504 | let instance = Linker::new(&engine).instantiate(&mut store, &component)?; |
| 505 | let func = instance.get_func(&mut store, "echo").unwrap(); |
| 506 | let input = Val::Record(vec![ |
| 507 | ("A".into(), Val::U32(32343)), |
| 508 | ("B".into(), Val::Float64(3.14159265)), |
| 509 | ( |
| 510 | "C".into(), |
| 511 | Val::Record(vec![ |
| 512 | ("D".into(), Val::Bool(false)), |
| 513 | ("E".into(), Val::U32(2084037802)), |
| 514 | ]), |
| 515 | ), |
| 516 | ]); |
| 517 | let mut output = [Val::Bool(false)]; |
| 518 | func.call(&mut store, &[input.clone()], &mut output)?; |
| 519 | |
| 520 | assert_eq!(input, output[0]); |
| 521 | |
| 522 | // Sad path: type mismatch |
| 523 | |
| 524 | let err = Val::Record(vec![ |
| 525 | ("A".into(), Val::S32(32343)), |
| 526 | ("B".into(), Val::Float64(3.14159265)), |
| 527 | ( |
| 528 | "C".into(), |
| 529 | Val::Record(vec![ |
| 530 | ("D".into(), Val::Bool(false)), |
| 531 | ("E".into(), Val::U32(2084037802)), |
| 532 | ]), |
| 533 | ), |
| 534 | ]); |
nothing calls this directly
no test coverage detected