| 692 | |
| 693 | #[test] |
| 694 | fn strings() -> Result<()> { |
| 695 | let component = format!( |
| 696 | r#"(component |
| 697 | (core module $m |
| 698 | (memory (export "memory") 1) |
| 699 | (func (export "roundtrip") (param i32 i32) (result i32) |
| 700 | (local $base i32) |
| 701 | (local.set $base |
| 702 | (call $realloc |
| 703 | (i32.const 0) |
| 704 | (i32.const 0) |
| 705 | (i32.const 4) |
| 706 | (i32.const 8))) |
| 707 | (i32.store offset=0 |
| 708 | (local.get $base) |
| 709 | (local.get 0)) |
| 710 | (i32.store offset=4 |
| 711 | (local.get $base) |
| 712 | (local.get 1)) |
| 713 | (local.get $base) |
| 714 | ) |
| 715 | |
| 716 | {REALLOC_AND_FREE} |
| 717 | ) |
| 718 | (core instance $i (instantiate $m)) |
| 719 | |
| 720 | (func (export "list8-to-str") (param "a" (list u8)) (result string) |
| 721 | (canon lift |
| 722 | (core func $i "roundtrip") |
| 723 | (memory $i "memory") |
| 724 | (realloc (func $i "realloc")) |
| 725 | ) |
| 726 | ) |
| 727 | (func (export "str-to-list8") (param "a" string) (result (list u8)) |
| 728 | (canon lift |
| 729 | (core func $i "roundtrip") |
| 730 | (memory $i "memory") |
| 731 | (realloc (func $i "realloc")) |
| 732 | ) |
| 733 | ) |
| 734 | (func (export "list16-to-str") (param "a" (list u16)) (result string) |
| 735 | (canon lift |
| 736 | (core func $i "roundtrip") |
| 737 | string-encoding=utf16 |
| 738 | (memory $i "memory") |
| 739 | (realloc (func $i "realloc")) |
| 740 | ) |
| 741 | ) |
| 742 | (func (export "str-to-list16") (param "a" string) (result (list u16)) |
| 743 | (canon lift |
| 744 | (core func $i "roundtrip") |
| 745 | string-encoding=utf16 |
| 746 | (memory $i "memory") |
| 747 | (realloc (func $i "realloc")) |
| 748 | ) |
| 749 | ) |
| 750 | )"# |
| 751 | ); |