diff --git a/Cargo.toml b/Cargo.toml index e0b2223..63cb4c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ readme = "README.md" proc-macro = true [dev-dependencies] +paste-test-suite = { version = "0", path = "tests/macros" } rustversion = "1.0" trybuild = "1.0" diff --git a/tests/macros/Cargo.toml b/tests/macros/Cargo.toml new file mode 100644 index 0000000..ba2ce2d --- /dev/null +++ b/tests/macros/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "paste-test-suite" +version = "0.0.0" +edition = "2018" +publish = false + +[lib] +path = "lib.rs" +proc-macro = true diff --git a/tests/macros/lib.rs b/tests/macros/lib.rs new file mode 100644 index 0000000..08228dc --- /dev/null +++ b/tests/macros/lib.rs @@ -0,0 +1,23 @@ +use proc_macro::{TokenStream, TokenTree}; + +#[proc_macro_attribute] +pub fn paste_test(args: TokenStream, input: TokenStream) -> TokenStream { + let mut iter = args.clone().into_iter(); + match iter.next() { + Some(TokenTree::Ident(_)) => {} + _ => panic!("{}", args), + } + match iter.next() { + Some(TokenTree::Punct(punct)) if punct.as_char() == '=' => {} + _ => panic!("{}", args), + } + match iter.next() { + Some(TokenTree::Literal(literal)) if literal.to_string().starts_with('"') => {} + _ => panic!("{}", args), + } + match iter.next() { + None => {} + _ => panic!("{}", args), + } + input +} diff --git a/tests/test_attr.rs b/tests/test_attr.rs index fd67e2a..01abbfe 100644 --- a/tests/test_attr.rs +++ b/tests/test_attr.rs @@ -1,4 +1,23 @@ use paste::paste; +use paste_test_suite::paste_test; + +#[test] +fn test_attr() { + paste! { + #[paste_test(k = "val" "ue")] + struct A; + + #[paste_test_suite::paste_test(k = "val" "ue")] + struct B; + + #[::paste_test_suite::paste_test(k = "val" "ue")] + struct C; + } + + let _ = A; + let _ = B; + let _ = C; +} #[test] fn test_paste_cfg() {