Skip to main content

rosu_mods/
macros.rs

1#![cfg(feature = "macros")]
2
3/// Short-hand macro to easily create [`GameMods`] or [`GameModsIntermode`].
4///
5/// To create [`GameModsIntermode`], specify a space-separated list of
6/// acronyms.
7///
8/// To create [`GameMods`], specify `Osu`, `Taiko`, `Catch`, or `Mania`,
9/// followed by a colon (`:`), followed by a space-separated list of acronyms.
10///
11/// # Example
12///
13/// ```
14/// # use rosu_mods::{mods, GameMods, GameModsIntermode};
15/// let mods: GameMods = mods!(Taiko: NC HR);
16/// assert_eq!(mods.to_string(), "HRNC");
17///
18/// let mods: GameModsIntermode = mods!(DT HR TC);
19/// assert_eq!(mods.to_string(), "DTHRTC");
20/// ```
21///
22/// [`GameMods`]: crate::GameMods
23/// [`GameModsIntermode`]: crate::GameModsIntermode
24#[macro_export(local_inner_macros)]
25#[cfg_attr(all(docsrs, not(doctest)), doc(cfg(feature = "macros")))]
26macro_rules! mods {
27    ( Osu $( : $( $acronym:tt )* )? ) => {
28        mods_inner!(@ Osu: $( $( $acronym )* )?)
29    };
30    ( Taiko $( : $( $acronym:tt )* )? ) => {
31        mods_inner!(@ Taiko: $( $( $acronym )* )?)
32    };
33    ( Catch $( : $( $acronym:tt )* )? ) => {
34        mods_inner!(@ Catch: $( $( $acronym )* )?)
35    };
36    ( Mania $( : $( $acronym:tt )* )? ) => {
37        mods_inner!(@ Mania: $( $( $acronym )* )?)
38    };
39    ( $( $acronym:tt )* ) => {
40        mods_inner!(@ $( $acronym )*)
41    };
42}
43
44pub use pastey::paste;
45
46#[cfg(test)]
47mod tests {
48    #[test]
49    fn empty_intermode() {
50        let mods = mods!();
51        assert!(mods.is_empty());
52    }
53
54    #[test]
55    fn single_intermode() {
56        let mods = mods!(WG);
57        assert_eq!(mods.len(), 1);
58    }
59
60    #[test]
61    fn full_intermode() {
62        let mods = mods!(HD DT DT HR TC);
63        assert_eq!(mods.to_string(), "DTHDHRTC");
64    }
65
66    #[test]
67    fn empty_catch() {
68        let mods = mods!(Catch);
69        assert!(mods.is_empty());
70    }
71
72    #[test]
73    fn full_taiko() {
74        let mods = mods!(Taiko: HR PF);
75        assert_eq!(mods.len(), 2);
76    }
77}