diff options
author | HampusM <hampus@hampusmat.com> | 2023-12-22 22:33:09 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-12-22 22:33:09 +0100 |
commit | c501a5cc770f632eba1529de09bd3ae2d7958de6 (patch) | |
tree | e45333f7bf71ae17cf2016616ddf339a690bf8db /macros/src/util | |
parent | c56d6fee4835ca103d1e4e5fd7e9e3913c7ed6ba (diff) |
refactor: mock Dependency struct impl instead of IDependency
Diffstat (limited to 'macros/src/util')
-rw-r--r-- | macros/src/util/mod.rs | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/macros/src/util/mod.rs b/macros/src/util/mod.rs index 7ab2185..3557896 100644 --- a/macros/src/util/mod.rs +++ b/macros/src/util/mod.rs @@ -26,4 +26,42 @@ macro_rules! or { }; } -pub(crate) use {or, to_option}; +/// Imports the specified item, prepending 'Mock' to the item identifier if the `test` +/// configuration option is set. +/// +/// # Examples +/// ```ignore +/// use_double!(crate::dependency_history::DependencyHistory); +/// ``` +/// <br> +/// +/// Expands to the following when `cfg(not(test))` +/// ```ignore +/// use crate::dependency_history::DependencyHistory; +/// ``` +/// <br> +/// +/// Expands to the following when `cfg(test)` +/// ```ignore +/// use crate::dependency_history::MockDependencyHistory as DependencyHistory; +/// ``` +macro_rules! use_double { + ($([$($part: ident),*])? $item_path_part: ident :: $($next_part: tt)+) => { + use_double!( + [$($($part,)*)? $item_path_part] + $($next_part)+ + ); + }; + + ([$($part: ident),*] $item_path_part: ident) => { + #[cfg(not(test))] + use $($part::)* $item_path_part; + + ::paste::paste! { + #[cfg(test)] + use $($part::)* [<Mock $item_path_part>] as $item_path_part; + } + }; +} + +pub(crate) use {or, to_option, use_double}; |