@@ -50,3 +50,53 @@ pub fn only_owner_impl(input_fn: ItemFn) -> TokenStream2 {
50
50
}
51
51
}
52
52
}
53
+
54
+ #[ cfg( test) ]
55
+ mod tests {
56
+ use syn:: { parse_quote, ItemFn } ;
57
+
58
+ use super :: * ;
59
+
60
+ #[ test]
61
+ fn test_first_parameter_is_typed ( ) {
62
+ let input_fn: ItemFn = parse_quote ! {
63
+ fn test_fn( env: & Env , other: i32 ) { }
64
+ } ;
65
+ only_owner_impl ( input_fn) ;
66
+ }
67
+
68
+ #[ test]
69
+ #[ should_panic( expected = "First parameter must be a typed parameter" ) ]
70
+ fn test_first_parameter_is_not_typed ( ) {
71
+ let input_fn: ItemFn = parse_quote ! {
72
+ fn test_fn( ) { }
73
+ } ;
74
+ only_owner_impl ( input_fn) ;
75
+ }
76
+
77
+ #[ test]
78
+ fn test_first_parameter_is_simple_identifier ( ) {
79
+ let input_fn: ItemFn = parse_quote ! {
80
+ fn test_fn( env: & Env , other: i32 ) { }
81
+ } ;
82
+ only_owner_impl ( input_fn) ;
83
+ }
84
+
85
+ #[ test]
86
+ #[ should_panic( expected = "First parameter must be a simple identifier" ) ]
87
+ fn test_first_parameter_is_not_simple_identifier ( ) {
88
+ let input_fn: ItemFn = parse_quote ! {
89
+ fn test_fn( ( env, other) : ( & Env , i32 ) ) { }
90
+ } ;
91
+ only_owner_impl ( input_fn) ;
92
+ }
93
+
94
+ #[ test]
95
+ #[ should_panic( expected = "First parameter must be named 'env'" ) ]
96
+ fn test_first_parameter_is_not_named_env ( ) {
97
+ let input_fn: ItemFn = parse_quote ! {
98
+ fn test_fn( not_env: & Env , other: i32 ) { }
99
+ } ;
100
+ only_owner_impl ( input_fn) ;
101
+ }
102
+ }
0 commit comments