From 7793779ce197fa0c917d0ef312bfa9bcfcb64790 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 11 Nov 2022 22:52:30 +0100 Subject: test: add unit test for create_caster_fn_ident --- test_util_macros/Cargo.toml | 11 +++++++++++ test_util_macros/src/lib.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 test_util_macros/Cargo.toml create mode 100644 test_util_macros/src/lib.rs (limited to 'test_util_macros') diff --git a/test_util_macros/Cargo.toml b/test_util_macros/Cargo.toml new file mode 100644 index 0000000..8848961 --- /dev/null +++ b/test_util_macros/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "test_util_macros" +version = "0.1.0" +edition = "2021" + +[lib] +proc_macro = true + +[dependencies] +syn = { version = "1.0.96", features = ["full"] } +quote = "1.0.18" 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::(); + + quote! { + #repeated + } + .into() +} + +struct RepeatMacroArgs +{ + character: LitChar, + count: usize, +} + +impl Parse for RepeatMacroArgs +{ + fn parse(input: syn::parse::ParseStream) -> syn::Result + { + let character = input.parse::()?; + + input.parse::()?; + + let count = input.parse::()?.base10_parse::()?; + + Ok(Self { character, count }) + } +} -- cgit v1.2.3-18-g5258