Path: blob/main/crates/wiggle/tests/keywords.rs
1692 views
//! Tests to check that keywords in `witx` files are escaped.1//!2//! No `#[test]` functions are defined below because the `wiggle::from_witx!` macro expanding into3//! syntactically correct Rust code at compile time is the subject under test.45/// Test that an enum variant that conflicts with a Rust keyword can be compiled properly.6mod enum_test {7wiggle::from_witx!({8witx_literal:9"(typename $self10(enum (@witx tag u8)11$self12$2big13)14)",15});16}1718/// Test module, trait, function, and function parameter names conflicting with Rust keywords.19///20/// We use `self` because the camel-cased trait name `Self` is *also* a strict keyword. This lets21/// us simultaneously test the name of the module and the generated trait.22mod module_trait_fn_and_arg_test {23use wiggle_test::WasiCtx;24wiggle::from_witx!({25witx_literal:26"(module $self27(@interface func (export \"fn\")28(param $use u32)29(param $virtual u32)30)31)",32});33impl<'a> self_::Self_ for WasiCtx<'a> {34fn fn_(&mut self, _memory: &mut wiggle::GuestMemory<'_>, _use_: u32, _virtual_: u32) {35unimplemented!();36}37}38}3940/// Test that a struct and member names conflicting with Rust keywords can be compiled properly.41mod struct_test {42wiggle::from_witx!({43witx_literal:44"(typename $self45(record46(field $become s32)47(field $mut s32)48)49)",50});51}5253/// Test that a union variant that conflicts with a Rust keyword can be compiled properly.54mod union_test {55wiggle::from_witx!({56witx: ["tests/keywords_union.witx"],57});58}596061