@@ -58,11 +58,12 @@ fn is_keys_remove_call(func: &Expr, args: &Punctuated<Expr, Comma>) -> bool {
58
58
#[ cfg( test) ]
59
59
mod tests {
60
60
use super :: * ;
61
+ use quote:: quote;
61
62
62
- fn lint ( input : & str ) -> Result {
63
+ fn lint ( input : proc_macro2 :: TokenStream ) -> Result {
63
64
let mut visitor = KeysRemoveVisitor :: default ( ) ;
64
- visitor
65
- . visit_expr_call ( & syn :: parse_str ( input ) . expect ( "should only use on a function call" ) ) ;
65
+ let expr : syn :: ExprCall = syn :: parse2 ( input ) . expect ( "should be a valid function call" ) ;
66
+ visitor . visit_expr_call ( & expr ) ;
66
67
67
68
if visitor. errors . is_empty ( ) {
68
69
Ok ( ( ) )
@@ -73,46 +74,46 @@ mod tests {
73
74
74
75
#[ test]
75
76
fn test_keys_remove_forbidden ( ) {
76
- let input = r#" Keys::<T>::remove(netuid, uid_to_replace)"# ;
77
+ let input = quote ! { Keys :: <T >:: remove( netuid, uid_to_replace) } ;
77
78
assert ! ( lint( input) . is_err( ) ) ;
78
- let input = r#" Keys::<U>::remove(netuid, uid_to_replace)"# ;
79
+ let input = quote ! { Keys :: <U >:: remove( netuid, uid_to_replace) } ;
79
80
assert ! ( lint( input) . is_err( ) ) ;
80
- let input = r#" Keys::<U>::remove(1, "2".parse().unwrap(),)"# ;
81
+ let input = quote ! { Keys :: <U >:: remove( 1 , "2" . parse( ) . unwrap( ) , ) } ;
81
82
assert ! ( lint( input) . is_err( ) ) ;
82
83
}
83
84
84
85
#[ test]
85
86
fn test_non_keys_remove_not_forbidden ( ) {
86
- let input = r#" remove(netuid, uid_to_replace)"# ;
87
+ let input = quote ! { remove( netuid, uid_to_replace) } ;
87
88
assert ! ( lint( input) . is_ok( ) ) ;
88
- let input = r#" Keys::remove(netuid, uid_to_replace)"# ;
89
+ let input = quote ! { Keys :: remove( netuid, uid_to_replace) } ;
89
90
assert ! ( lint( input) . is_ok( ) ) ;
90
- let input = r#" Keys::<T>::remove::<U>(netuid, uid_to_replace)"# ;
91
+ let input = quote ! { Keys :: <T >:: remove:: <U >( netuid, uid_to_replace) } ;
91
92
assert ! ( lint( input) . is_ok( ) ) ;
92
- let input = r#" Keys::<T>::remove(netuid, uid_to_replace, third_wheel)"# ;
93
+ let input = quote ! { Keys :: <T >:: remove( netuid, uid_to_replace, third_wheel) } ;
93
94
assert ! ( lint( input) . is_ok( ) ) ;
94
- let input = r#" ParentKeys::remove(netuid, uid_to_replace)"# ;
95
+ let input = quote ! { ParentKeys :: remove( netuid, uid_to_replace) } ;
95
96
assert ! ( lint( input) . is_ok( ) ) ;
96
- let input = r#" ChildKeys::<T>::remove(netuid, uid_to_replace)"# ;
97
+ let input = quote ! { ChildKeys :: <T >:: remove( netuid, uid_to_replace) } ;
97
98
assert ! ( lint( input) . is_ok( ) ) ;
98
99
}
99
100
100
101
#[ test]
101
102
fn test_keys_remove_allowed ( ) {
102
- let input = r#"
103
- #[allow(unknown_lints)]
104
- Keys::<T>::remove(netuid, uid_to_replace)
105
- "# ;
103
+ let input = quote ! {
104
+ #[ allow( unknown_lints) ]
105
+ Keys :: <T >:: remove( netuid, uid_to_replace)
106
+ } ;
106
107
assert ! ( lint( input) . is_ok( ) ) ;
107
- let input = r#"
108
- #[allow(unknown_lints)]
109
- Keys::<U>::remove(netuid, uid_to_replace)
110
- "# ;
108
+ let input = quote ! {
109
+ #[ allow( unknown_lints) ]
110
+ Keys :: <U >:: remove( netuid, uid_to_replace)
111
+ } ;
111
112
assert ! ( lint( input) . is_ok( ) ) ;
112
- let input = r#"
113
- #[allow(unknown_lints)]
114
- Keys::<U>::remove(1, "2".parse().unwrap(),)
115
- "# ;
113
+ let input = quote ! {
114
+ #[ allow( unknown_lints) ]
115
+ Keys :: <U >:: remove( 1 , "2" . parse( ) . unwrap( ) , )
116
+ } ;
116
117
assert ! ( lint( input) . is_ok( ) ) ;
117
118
}
118
119
}
0 commit comments