| 1 |
use pretty_assertions::assert_eq; |
| 2 |
use wit_encoder::{Interface, StandaloneFunc, Type}; |
| 3 |
|
| 4 |
const PACKAGE: &str = indoc::indoc! {" |
| 5 |
package foo:functions; |
| 6 |
|
| 7 |
interface error-reporter {} |
| 8 |
|
| 9 |
world %world { |
| 10 |
/// inline interface |
| 11 |
export example: interface { |
| 12 |
/// func docs |
| 13 |
do-nothing: func(); |
| 14 |
} |
| 15 |
/// scan stuff |
| 16 |
export scan: func() -> list<u8>; |
| 17 |
import error-reporter; |
| 18 |
import print: func(s: string); |
| 19 |
} |
| 20 |
"}; |
| 21 |
|
| 22 |
#[test] |
| 23 |
fn worlds() { |
| 24 |
let name = wit_encoder::PackageName::new("foo", "functions", None); |
| 25 |
let mut package = wit_encoder::Package::new(name); |
| 26 |
|
| 27 |
package.interface(wit_encoder::Interface::new("error-reporter")); |
| 28 |
|
| 29 |
package.world({ |
| 30 |
let mut world = wit_encoder::World::new("world"); |
| 31 |
world.inline_interface_export({ |
| 32 |
let mut interface = Interface::new("example"); |
| 33 |
interface.set_docs(Some("inline interface")); |
| 34 |
interface.function({ |
| 35 |
let mut func = StandaloneFunc::new("do-nothing", false); |
| 36 |
func.set_docs(Some("func docs")); |
| 37 |
func |
| 38 |
}); |
| 39 |
interface |
| 40 |
}); |
| 41 |
world.function_export({ |
| 42 |
let mut func = StandaloneFunc::new("scan", false); |
| 43 |
func.set_result(Some(Type::list(Type::U8))); |
| 44 |
func.set_docs(Some("scan stuff")); |
| 45 |
func |
| 46 |
}); |
| 47 |
world.named_interface_import("error-reporter"); |
| 48 |
world.function_import({ |
| 49 |
let mut func: StandaloneFunc = StandaloneFunc::new("print", false); |
| 50 |
func.set_params(("s", Type::String)); |
| 51 |
func |
| 52 |
}); |
| 53 |
world |
| 54 |
}); |
| 55 |
|
| 56 |
assert_eq!(PACKAGE, package.to_string()); |
| 57 |
} |