Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
Add test attribute macro
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 10, 2020
1 parent a3e4ace commit 5b4f4f3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
9 changes: 9 additions & 0 deletions tests/macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "paste-test-suite"
version = "0.0.0"
edition = "2018"
publish = false

[lib]
path = "lib.rs"
proc-macro = true
23 changes: 23 additions & 0 deletions tests/macros/lib.rs
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 19 additions & 0 deletions tests/test_attr.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down

0 comments on commit 5b4f4f3

Please sign in to comment.