Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. fn any_sorted_attr(item:&syn::ExprMatch)->bool{
  2. item.attrs
  3. .iter()
  4. .flat_map(syn::Attribute::parse_meta)
  5. .any(|meta| meta.name()=="sorted" )
  6. }
  7.  
  8.  
  9. #[test]
  10. fn found_any_sorted_attr(){
  11. let matches=vec![
  12. (false,"match () { ()=>() }"),
  13. (false,"#[nothing] match () { ()=>() }"),
  14. (true ,"#[sorted] match () { ()=>() }"),
  15. (true ,"#[nothing] #[sorted] match () { ()=>() }"),
  16. ];
  17.  
  18. for (expected,expr) in matches{
  19. let parsed=syn::parse_str::<syn::Expr>(expr).expect(expr);
  20. let parsed=match parsed {
  21. syn::Expr::Match(v)=>v,
  22. _=>unreachable!(),
  23. };
  24. assert_eq!( expected, any_sorted_attr(&parsed) );
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement