Add trybuild tests for event_enum! macro
This commit is contained in:
parent
36d7ee2676
commit
86ca6bb39d
@ -214,7 +214,7 @@ pub struct EventEnumInput {
|
||||
/// The name of the event.
|
||||
pub name: Ident,
|
||||
|
||||
/// An array of valid matrix event types. This will generate the variants of the event content type "name".
|
||||
/// An array of valid matrix event types. This will generate the variants of the event type "name".
|
||||
/// There needs to be a corresponding variant in `ruma_events::EventType` for
|
||||
/// this event (converted to a valid Rust-style type name by stripping `m.`, replacing the
|
||||
/// remaining dots by underscores and then converting from snake_case to CamelCase).
|
||||
|
@ -15,6 +15,13 @@ use ruma_events::{
|
||||
AnyMessageEvent, MessageEvent, UnsignedData,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn ui() {
|
||||
let t = trybuild::TestCases::new();
|
||||
t.pass("tests/ui/07-enum-sanity-check.rs");
|
||||
t.compile_fail("tests/ui/08-enum-invalid-path.rs");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_message_event() {
|
||||
let json_data = json!({
|
||||
|
15
tests/ui/07-enum-sanity-check.rs
Normal file
15
tests/ui/07-enum-sanity-check.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use ruma_events_macros::event_enum;
|
||||
|
||||
event_enum! {
|
||||
/// Any basic event.
|
||||
name: AnyBasicEvent,
|
||||
events: [
|
||||
"m.direct",
|
||||
"m.dummy",
|
||||
"m.ignored_user_list",
|
||||
"m.push_rules",
|
||||
"m.room_key",
|
||||
]
|
||||
}
|
||||
|
||||
fn main() {}
|
17
tests/ui/08-enum-invalid-path.rs
Normal file
17
tests/ui/08-enum-invalid-path.rs
Normal file
@ -0,0 +1,17 @@
|
||||
use ruma_events_macros::event_enum;
|
||||
|
||||
event_enum! {
|
||||
name: InvalidEvent,
|
||||
events: [
|
||||
"m.not.a.path",
|
||||
]
|
||||
}
|
||||
|
||||
event_enum! {
|
||||
name: InvalidEvent,
|
||||
events: [
|
||||
"not.a.path",
|
||||
]
|
||||
}
|
||||
|
||||
fn main() {}
|
20
tests/ui/08-enum-invalid-path.stderr
Normal file
20
tests/ui/08-enum-invalid-path.stderr
Normal file
@ -0,0 +1,20 @@
|
||||
error: proc macro panicked
|
||||
--> $DIR/08-enum-invalid-path.rs:10:1
|
||||
|
|
||||
10 | / event_enum! {
|
||||
11 | | name: InvalidEvent,
|
||||
12 | | events: [
|
||||
13 | | "not.a.path",
|
||||
14 | | ]
|
||||
15 | | }
|
||||
| |_^
|
||||
|
|
||||
= help: message: assertion failed: `(left == right)`
|
||||
left: `"no"`,
|
||||
right: `"m."`
|
||||
|
||||
error[E0433]: failed to resolve: could not find `not` in `ruma_events`
|
||||
--> $DIR/08-enum-invalid-path.rs:6:9
|
||||
|
|
||||
6 | "m.not.a.path",
|
||||
| ^^^^^^^^^^^^^^ could not find `not` in `ruma_events`
|
Loading…
x
Reference in New Issue
Block a user