Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/wiggle/tests/keywords.rs
1692 views
1
//! Tests to check that keywords in `witx` files are escaped.
2
//!
3
//! No `#[test]` functions are defined below because the `wiggle::from_witx!` macro expanding into
4
//! syntactically correct Rust code at compile time is the subject under test.
5
6
/// Test that an enum variant that conflicts with a Rust keyword can be compiled properly.
7
mod enum_test {
8
wiggle::from_witx!({
9
witx_literal:
10
"(typename $self
11
(enum (@witx tag u8)
12
$self
13
$2big
14
)
15
)",
16
});
17
}
18
19
/// Test module, trait, function, and function parameter names conflicting with Rust keywords.
20
///
21
/// We use `self` because the camel-cased trait name `Self` is *also* a strict keyword. This lets
22
/// us simultaneously test the name of the module and the generated trait.
23
mod module_trait_fn_and_arg_test {
24
use wiggle_test::WasiCtx;
25
wiggle::from_witx!({
26
witx_literal:
27
"(module $self
28
(@interface func (export \"fn\")
29
(param $use u32)
30
(param $virtual u32)
31
)
32
)",
33
});
34
impl<'a> self_::Self_ for WasiCtx<'a> {
35
fn fn_(&mut self, _memory: &mut wiggle::GuestMemory<'_>, _use_: u32, _virtual_: u32) {
36
unimplemented!();
37
}
38
}
39
}
40
41
/// Test that a struct and member names conflicting with Rust keywords can be compiled properly.
42
mod struct_test {
43
wiggle::from_witx!({
44
witx_literal:
45
"(typename $self
46
(record
47
(field $become s32)
48
(field $mut s32)
49
)
50
)",
51
});
52
}
53
54
/// Test that a union variant that conflicts with a Rust keyword can be compiled properly.
55
mod union_test {
56
wiggle::from_witx!({
57
witx: ["tests/keywords_union.witx"],
58
});
59
}
60
61