1 macro_rules! gentest {
2     ($id:ident $name:tt $path:tt) => {
3         mod $id {
4             mod sugar {
5                 wasmtime::component::bindgen!(in $path);
6             }
7             mod async_ {
8                 wasmtime::component::bindgen!({
9                     path: $path,
10                     async: true,
11                 });
12             }
13             mod tracing {
14                 wasmtime::component::bindgen!({
15                     path: $path,
16                     tracing: true,
17                     ownership: Borrowing {
18                         duplicate_if_necessary: true
19                     }
20                 });
21             }
22         }
23     };
24 }
25 
26 component_macro_test_helpers::foreach!(gentest);
27 
28 mod with_key_and_resources {
29     use anyhow::Result;
30     use wasmtime::component::Resource;
31 
32     wasmtime::component::bindgen!({
33         inline: "
34             package demo:pkg;
35 
36             interface bar {
37                 resource a;
38                 resource b;
39             }
40 
41             world foo {
42                 resource a;
43                 resource b;
44 
45                 import foo: interface {
46                     resource a;
47                     resource b;
48                 }
49 
50                 import bar;
51             }
52         ",
53         with: {
54             "a": MyA,
55             "b": MyA,
56             "foo/a": MyA,
57             "foo/b": MyA,
58             "demo:pkg/bar/a": MyA,
59             "demo:pkg/bar/b": MyA,
60         },
61     });
62 
63     pub struct MyA;
64 
65     struct MyComponent;
66 
67     impl FooImports for MyComponent {}
68 
69     impl HostA for MyComponent {
70         fn drop(&mut self, _: Resource<MyA>) -> Result<()> {
71             loop {}
72         }
73     }
74 
75     impl HostB for MyComponent {
76         fn drop(&mut self, _: Resource<MyA>) -> Result<()> {
77             loop {}
78         }
79     }
80 
81     impl foo::Host for MyComponent {}
82 
83     impl foo::HostA for MyComponent {
84         fn drop(&mut self, _: Resource<MyA>) -> Result<()> {
85             loop {}
86         }
87     }
88 
89     impl foo::HostB for MyComponent {
90         fn drop(&mut self, _: Resource<MyA>) -> Result<()> {
91             loop {}
92         }
93     }
94 
95     impl demo::pkg::bar::Host for MyComponent {}
96 
97     impl demo::pkg::bar::HostA for MyComponent {
98         fn drop(&mut self, _: Resource<MyA>) -> Result<()> {
99             loop {}
100         }
101     }
102 
103     impl demo::pkg::bar::HostB for MyComponent {
104         fn drop(&mut self, _: Resource<MyA>) -> Result<()> {
105             loop {}
106         }
107     }
108 }
109 
110 mod trappable_errors {
111     wasmtime::component::bindgen!({
112         inline: "
113             package demo:pkg;
114 
115             interface a {
116                 type b = u64;
117 
118                 z1: func() -> result<_, b>;
119                 z2: func() -> result<_, b>;
120             }
121 
122             interface b {
123                 use a.{b};
124                 z: func() -> result<_, b>;
125             }
126 
127             interface c {
128                 type b = u64;
129             }
130 
131             interface d {
132                 use c.{b};
133                 z: func() -> result<_, b>;
134             }
135 
136             world foo {
137                 import a;
138                 import b;
139                 import d;
140             }
141         ",
142         trappable_error_type: {
143             "demo:pkg/a/b" => MyX,
144             "demo:pkg/c/b" => MyX,
145         },
146     });
147 
148     #[allow(dead_code)]
149     type MyX = u32;
150 }
151 
152 mod interface_name_with_rust_keyword {
153     wasmtime::component::bindgen!({
154         inline: "
155             package foo:foo;
156 
157             interface crate { }
158 
159             world foo {
160                 export crate;
161             }
162         "
163     });
164 }
165