aboutsummaryrefslogtreecommitdiff
path: root/test_util_macros/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-11-11 22:52:30 +0100
committerHampusM <hampus@hampusmat.com>2022-11-11 22:52:30 +0100
commit7793779ce197fa0c917d0ef312bfa9bcfcb64790 (patch)
treed63d99d659e575fe6d833d95b58503b6cb39293f /test_util_macros/src
parentde5aca66532272a84aeb04cac02bd25bb7afc414 (diff)
test: add unit test for create_caster_fn_ident
Diffstat (limited to 'test_util_macros/src')
-rw-r--r--test_util_macros/src/lib.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/test_util_macros/src/lib.rs b/test_util_macros/src/lib.rs
new file mode 100644
index 0000000..aa87ecf
--- /dev/null
+++ b/test_util_macros/src/lib.rs
@@ -0,0 +1,47 @@
+#![deny(clippy::all)]
+#![deny(clippy::pedantic)]
+#![deny(missing_docs)]
+
+//! Internal macros used by tests.
+
+use std::iter::repeat;
+
+use proc_macro::TokenStream;
+use quote::quote;
+use syn::parse::Parse;
+use syn::{parse_macro_input, LitChar, LitInt, Token};
+
+/// Repeats a character N number of times.
+#[proc_macro]
+pub fn repeat_char(input: TokenStream) -> TokenStream
+{
+ let RepeatMacroArgs { character, count } =
+ parse_macro_input!(input as RepeatMacroArgs);
+
+ let repeated = repeat(character.value()).take(count).collect::<String>();
+
+ quote! {
+ #repeated
+ }
+ .into()
+}
+
+struct RepeatMacroArgs
+{
+ character: LitChar,
+ count: usize,
+}
+
+impl Parse for RepeatMacroArgs
+{
+ fn parse(input: syn::parse::ParseStream) -> syn::Result<Self>
+ {
+ let character = input.parse::<LitChar>()?;
+
+ input.parse::<Token![,]>()?;
+
+ let count = input.parse::<LitInt>()?.base10_parse::<usize>()?;
+
+ Ok(Self { character, count })
+ }
+}