-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(macros): improve macros and add tests (#4)
- Loading branch information
Showing
5 changed files
with
93 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use aionbot_core::event::{Message, MessageSegment}; | ||
use aionbot_macros::register; | ||
|
||
#[register(router = "test_router")] | ||
pub fn test_register_fn(_event: Arc<Event>) -> Result<()> { | ||
Ok(()) | ||
} | ||
|
||
#[register(router = "test_router", priority = 1)] | ||
pub fn test_register_fn_priority(_event: Arc<Event>) -> Result<()> { | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_register_router() { | ||
let event = Event { | ||
plain_data: Message { | ||
entity: Some("test".to_string()), | ||
segments: vec![MessageSegment { | ||
text: "test_router".to_string(), | ||
type_: "text".to_string(), | ||
}], | ||
}, | ||
user_id: "test".to_string(), | ||
channel_id: "test".to_string(), | ||
timestamp: "test".to_string(), | ||
event_type: "text".to_string(), | ||
variables: Default::default(), | ||
}; | ||
let entry = test_register_fn(); | ||
assert!(entry.priority == 0); | ||
assert!(entry.router.matches(&event)); | ||
} | ||
|
||
#[test] | ||
fn test_register_router_priority() { | ||
let event = Event { | ||
plain_data: Message { | ||
entity: Some("test".to_string()), | ||
segments: vec![MessageSegment { | ||
text: "test_router".to_string(), | ||
type_: "text".to_string(), | ||
}], | ||
}, | ||
user_id: "test".to_string(), | ||
channel_id: "test".to_string(), | ||
timestamp: "test".to_string(), | ||
event_type: "text".to_string(), | ||
variables: Default::default(), | ||
}; | ||
let entry = test_register_fn_priority(); | ||
assert!(entry.priority == 1); | ||
assert!(entry.router.matches(&event)); | ||
} |