Debian Codegraph @

tests/cli/component-model/import.wast

raw
1 ;; RUN: wast --assert default --snapshot tests/snapshots % -f cm-values
2
3 (component
4 (import "a" (func))
5 (import "b" (instance))
6 (import "c" (instance
7 (export "a" (func))
8 ))
9 (import "d" (component
10 (import "a" (core module))
11 (export "b" (func))
12 ))
13 (type $t (func))
14 (import "e" (type (eq $t)))
15 )
16
17 (assert_invalid
18 (component
19 (type $f (func))
20 (import "a" (instance (type $f)))
21 )
22 "type index 0 is not an instance type")
23
24 (assert_invalid
25 (component
26 (core type $f (func))
27 (import "a" (core module (type $f)))
28 )
29 "core type index 0 is not a module type")
30
31 (assert_invalid
32 (component
33 (type $f string)
34 (import "a" (func (type $f)))
35 )
36 "type index 0 is not a function type")
37
38 ;; Disallow duplicate imports for core wasm modules
39 (assert_invalid
40 (component
41 (core type (module
42 (import "" "" (func))
43 (import "" "" (func))
44 ))
45 )
46 "duplicate import name `:`")
47 (assert_invalid
48 (component
49 (core module
50 (import "" "" (func))
51 (import "" "" (func))
52 )
53 )
54 "duplicate import name `:`")
55 (assert_invalid
56 (component
57 (core type (module
58 (import "" "a" (func))
59 (import "" "a" (func))
60 ))
61 )
62 "duplicate import name `:a`")
63 (assert_invalid
64 (component
65 (core module
66 (import "" "a" (func))
67 (import "" "a" (func))
68 )
69 )
70 "duplicate import name `:a`")
71
72 (assert_invalid
73 (component
74 (import "a" (func))
75 (import "a" (func))
76 )
77 "import name `a` conflicts with previous name `a`")
78
79 (assert_invalid
80 (component
81 (type (component
82 (import "a" (func))
83 (import "a" (func))
84 ))
85 )
86 "import name `a` conflicts with previous name `a`")
87
88 (assert_invalid
89 (component
90 (import "a" (func (type 100)))
91 )
92 "type index out of bounds")
93
94 (assert_invalid
95 (component
96 (core module $m (func (export "")))
97 (core instance $i (instantiate $m))
98 (func (type 100) (canon lift (core func $i "")))
99 )
100 "type index out of bounds")
101
102 (assert_invalid
103 (component
104 (import "a" (value string))
105 )
106 "value index 0 was not used as part of an instantiation, start function, or export")
107
108 (component
109 (import "a" (value string))
110 (export "b" (value 0))
111 )
112
113 (component
114 (import "wasi:http/types" (func))
115 (import "wasi:http/[email protected]" (func))
116 (import "wasi:http/[email protected]" (func))
117 (import "a-b:c-d/[email protected]" (func))
118 (import "a:b/[email protected]" (func))
119 (import "a:b/[email protected]" (func))
120 (import "a:b/[email protected]+abcd" (func))
121 (import "a:b/[email protected]+abcd-efg" (func))
122 (import "a:b/[email protected]+efg" (func))
123 (import "a:b/[email protected]+efg.4.ee.5" (func))
124 )
125
126 (assert_invalid
127 (component
128 (import "wasi:http/types" (func))
129 (import "wasi:http/types" (func))
130 )
131 "conflicts with previous name")
132
133 (assert_invalid
134 (component (import "" (func)))
135 "`` is not in kebab case")
136 (assert_invalid
137 (component (import "wasi:" (func)))
138 "`` is not in kebab case")
139 (assert_invalid
140 (component (import "wasi:/" (func)))
141 "not in kebab case")
142 (assert_invalid
143 (component (import ":/" (func)))
144 "not in kebab case")
145 (assert_invalid
146 (component (import "wasi/http" (func)))
147 "`wasi/http` is not in kebab case")
148 (assert_invalid
149 (component (import "wasi:http/TyPeS" (func)))
150 "`TyPeS` is not in kebab case")
151 (assert_invalid
152 (component (import "WaSi:http/types" (func)))
153 "`WaSi` is not in kebab case")
154 (assert_invalid
155 (component (import "wasi:HtTp/types" (func)))
156 "`HtTp` is not in kebab case")
157 (assert_invalid
158 (component (import "wasi:http/types@" (func)))
159 "empty string")
160 (assert_invalid
161 (component (import "wasi:http/types@." (func)))
162 "unexpected character '.'")
163 (assert_invalid
164 (component (import "wasi:http/types@1." (func)))
165 "unexpected end of input")
166 (assert_invalid
167 (component (import "wasi:http/[email protected]" (func)))
168 "unexpected character 'a'")
169 (assert_invalid
170 (component (import "wasi:http/[email protected]" (func)))
171 "unexpected character 'b'")
172 (assert_invalid
173 (component (import "wasi:http/[email protected]" (func)))
174 "unexpected character 'x'")
175 (assert_invalid
176 (component (import "wasi:http/[email protected]+" (func)))
177 "empty identifier segment")
178 (assert_invalid
179 (component (import "wasi:http/[email protected]" (func)))
180 "empty identifier segment")
181 (assert_invalid
182 (component (import "foo:bar:baz/qux" (func)))
183 "expected `/` after package name")
184 (assert_invalid
185 (component (import "foo:bar/baz/qux" (func)))
186 "trailing characters found: `/qux`")
187
188 (component
189 (import "a" (func $a))
190 (export "a" (func $a))
191 )
192
193 (component
194 (import "unlocked-dep=<a:b>" (func))
195 (import "unlocked-dep=<a:b@*>" (func))
196 (import "unlocked-dep=<a:b@{>=1.2.3}>" (func))
197 (import "unlocked-dep=<a:b@{>=1.2.3-rc}>" (func))
198 (import "unlocked-dep=<a:b@{<1.2.3}>" (func))
199 (import "unlocked-dep=<a:b@{<1.2.3-rc}>" (func))
200 (import "unlocked-dep=<a:b@{>=1.2.3 <1.2.3}>" (func))
201 (import "unlocked-dep=<a:b@{>=1.2.3-rc <1.2.3}>" (func))
202 )
203
204 (assert_invalid
205 (component (import "unlocked-dep=" (func)))
206 "expected `<` at ``")
207 (assert_invalid
208 (component (import "unlocked-dep=<" (func)))
209 "`` is not in kebab case")
210 (assert_invalid
211 (component (import "unlocked-dep=<>" (func)))
212 "`` is not in kebab case")
213 (assert_invalid
214 (component (import "unlocked-dep=<:>" (func)))
215 "`` is not in kebab case")
216 (assert_invalid
217 (component (import "unlocked-dep=<a:>" (func)))
218 "`` is not in kebab case")
219 (assert_invalid
220 (component (import "unlocked-dep=<:a>" (func)))
221 "`` is not in kebab case")
222 (assert_invalid
223 (component (import "unlocked-dep=<a:a@>" (func)))
224 "expected `{` at `>`")
225 (assert_invalid
226 (component (import "unlocked-dep=<a:a@{xyz}>" (func)))
227 "expected `>=` or `<` at start of version range")
228 (assert_invalid
229 (component (import "unlocked-dep=<a:a@{<xyz}>" (func)))
230 "`xyz` is not a valid semver")
231 (assert_invalid
232 (component (import "unlocked-dep=<a:a@{<1.2.3 >=2.3.4}>" (func)))
233 "`1.2.3 >=2.3.4` is not a valid semver")
234
235 (component
236 (import "locked-dep=<a:b>" (func))
237 (import "locked-dep=<a:[email protected]>" (func))
238 (import "locked-dep=<a:b>,integrity=<sha256-a>" (func))
239 (import "locked-dep=<a:[email protected]>,integrity=<sha256-a>" (func))
240 )
241
242 (assert_invalid
243 (component (import "locked-dep=" (func)))
244 "expected `<` at ``")
245 (assert_invalid
246 (component (import "locked-dep=<" (func)))
247 "`` is not in kebab case")
248 (assert_invalid
249 (component (import "locked-dep=<:" (func)))
250 "`` is not in kebab case")
251 (assert_invalid
252 (component (import "locked-dep=<:>" (func)))
253 "`` is not in kebab case")
254 (assert_invalid
255 (component (import "locked-dep=<a:>" (func)))
256 "`` is not in kebab case")
257 (assert_invalid
258 (component (import "locked-dep=<:a>" (func)))
259 "`` is not in kebab case")
260 (assert_invalid
261 (component (import "locked-dep=<a:a" (func)))
262 "expected `>` at ``")
263 (assert_invalid
264 (component (import "locked-dep=<a:a@>" (func)))
265 "is not a valid semver")
266 (assert_invalid
267 (component (import "locked-dep=<a:[email protected]" (func)))
268 "expected `>` at ``")
269 (assert_invalid
270 (component (import "locked-dep=<a:[email protected]>," (func)))
271 "expected `integrity=<`")
272 (assert_invalid
273 (component (import "locked-dep=<a:[email protected]>x" (func)))
274 "trailing characters found: `x`")
275
276 (component
277 (import "url=<>" (func))
278 (import "url=<a>" (func))
279 (import "url=<a>,integrity=<sha256-a>" (func))
280 )
281
282 (assert_invalid
283 (component (import "url=" (func)))
284 "expected `<` at ``")
285 (assert_invalid
286 (component (import "url=<" (func)))
287 "failed to find `>`")
288 (assert_invalid
289 (component (import "url=<<>" (func)))
290 "url cannot contain `<`")
291
292 (assert_invalid
293 (component
294 (import "relative-url=<>" (func))
295 (import "relative-url=<a>" (func))
296 (import "relative-url=<a>,integrity=<sha256-a>" (func))
297 )
298 "not a valid extern name")
299
300 (assert_invalid
301 (component (import "relative-url=" (func)))
302 "not a valid extern name")
303 (assert_invalid
304 (component (import "relative-url=<" (func)))
305 "not a valid extern name")
306 (assert_invalid
307 (component (import "relative-url=<<>" (func)))
308 "not a valid extern name")
309
310 (component
311 (import "integrity=<sha256-a>" (func))
312 (import "integrity=<sha384-a>" (func))
313 (import "integrity=<sha512-a>" (func))
314 (import "integrity=<sha512-a sha256-b>" (func))
315 (import "integrity=< sha512-a sha256-b >" (func))
316 (import "integrity=< sha512-a?abcd >" (func))
317 (import "integrity=<sha256-abcdefghijklmnopqrstuvwxyz>" (func))
318 (import "integrity=<sha256-ABCDEFGHIJKLMNOPQRSTUVWXYZ>" (func))
319 (import "integrity=<sha256-++++++++++++++++++++==>" (func))
320 (import "integrity=<sha256-////////////////////==>" (func))
321 )
322 (assert_invalid
323 (component (import "integrity=<>" (func)))
324 "integrity hash cannot be empty")
325 (assert_invalid
326 (component (import "integrity=<sha256>" (func)))
327 "expected `-` after hash algorithm")
328 (assert_invalid
329 (component (import "integrity=<sha256->" (func)))
330 "not valid base64")
331 (assert_invalid
332 (component (import "integrity=<sha256-^^^^>" (func)))
333 "not valid base64")
334 (assert_invalid
335 (component (import "integrity=<sha256-=========>" (func)))
336 "not valid base64")
337 (assert_invalid
338 (component (import "integrity=<sha256-=>" (func)))
339 "not valid base64")
340 (assert_invalid
341 (component (import "integrity=<sha256-==>" (func)))
342 "not valid base64")
343 (assert_invalid
344 (component (import "integrity=<md5-ABC>" (func)))
345 "unrecognized hash algorithm")
346
347 ;; Prior to WebAssembly/component-model#263 this was a valid component.
348 ;; Specifically the 0x01 prefix byte on the import was valid. Nowadays that's
349 ;; not valid in the spec but it's accepted for backwards compatibility. This
350 ;; tests is here to ensure such compatibility. In the future this test should
351 ;; be changed to `(assert_invalid ...)`
352 (component binary
353 "\00asm" "\0d\00\01\00" ;; component header
354
355 "\07\05" ;; type section, 5 bytes large
356 "\01" ;; 1 count
357 "\40" ;; function
358 "\00" ;; parameters, 0 count
359 "\01\00" ;; results, named, 0 count
360
361 "\0a\06" ;; import section, 6 bytes large
362 "\01" ;; 1 count
363 "\01" ;; prefix byte of 0x01 (invalid by the spec nowadays)
364 "\01a" ;; name = "a"
365 "\01\00" ;; type = func ($type 0)
366 )