Add trybuild tests for event_enum! macro

This commit is contained in:
Devin R 2020-06-09 20:18:05 -04:00 committed by Jonas Platte
parent 36d7ee2676
commit 86ca6bb39d
5 changed files with 60 additions and 1 deletions

View File

@ -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).

View File

@ -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!({

View 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() {}

View 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() {}

View 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`