@@ -188,49 +188,57 @@ mod test {
188
188
use super :: * ;
189
189
use pretty_assertions:: assert_eq;
190
190
191
+ fn ch ( c : & str ) -> IcedKey {
192
+ IcedKey :: Character ( SmolStr :: new ( c) )
193
+ }
194
+
195
+ #[ track_caller]
196
+ fn parse ( input : & str , expected : Result < KeySequence , String > ) {
197
+ assert_eq ! (
198
+ input. parse:: <KeySequence >( ) ,
199
+ expected,
200
+ "Failed to parse {:?}" ,
201
+ input
202
+ ) ;
203
+ }
204
+
191
205
#[ test]
192
206
fn parse_key_sequence ( ) {
193
- macro_rules! assert_parsed_key_sequences {
194
- ( $( $seq: literal -> $( $outcome: tt ) ,+ ) * ) => { {
195
- $(
196
- assert_eq!(
197
- $seq. parse:: <KeySequence >( ) ,
198
- assert_parsed_key_sequences!( @seq $( $outcome) ,* ) ,
199
- concat!( "Failed to parse " , $seq)
200
- ) ;
201
- ) *
202
- } } ;
203
- ( @seq Err , $message: literal ) => { Err ( $message. to_string( ) ) } ;
204
- ( @seq $first: expr) => { Ok ( KeySequence ( ( assert_parsed_key_sequences!( @key $first) , None ) ) ) } ;
205
- ( @seq $first: tt, $second: tt) => { {
206
- Ok ( KeySequence ( (
207
- assert_parsed_key_sequences!( @key $first) ,
208
- Some ( assert_parsed_key_sequences!( @key $second) )
209
- ) ) )
210
- } } ;
211
- ( @key $key: ident) => { IcedKey :: Named ( key:: Named :: $key) } ;
212
- ( @key $key: literal) => { IcedKey :: Character ( SmolStr :: new( $key) ) } ;
213
- }
214
-
215
- assert_parsed_key_sequences ! {
216
- "gh" -> "g" , "h"
217
- "ge" -> "g" , "e"
218
- "x" -> "x"
219
- "Lx" -> "L" , "x"
220
- "" -> Err , "Expected at least 1 key."
221
- "<space>x" -> Space , "x"
222
- "x<space>" -> "x" , Space
223
- "<space><space>" -> Space , Space
224
- "<<" -> "<" , "<"
225
- "<>" -> "<" , ">"
226
- "<" -> "<"
227
- ">>" -> ">" , ">"
228
- "<<space>" -> "<" , Space
229
- "<f32><f31>" -> F32 , F31
230
- "><f32>" -> ">" , F32
231
- "abc" -> Err , "At the moment, only up to 2 keys in a sequence are supported."
232
- "<f32>b<f16>" -> Err , "At the moment, only up to 2 keys in a sequence are supported."
233
- "<@>" -> Err , "Invalid key: <@>. Matching variant not found"
234
- }
207
+ use IcedKey :: Named ;
208
+ use key:: Named :: * ;
209
+
210
+ parse ( "gh" , Ok ( KeySequence ( ( ch ( "g" ) , Some ( ch ( "h" ) ) ) ) ) ) ;
211
+ parse ( "ge" , Ok ( KeySequence ( ( ch ( "g" ) , Some ( ch ( "e" ) ) ) ) ) ) ;
212
+ parse ( "x" , Ok ( KeySequence ( ( ch ( "x" ) , None ) ) ) ) ;
213
+ parse ( "Lx" , Ok ( KeySequence ( ( ch ( "L" ) , Some ( ch ( "x" ) ) ) ) ) ) ;
214
+ parse ( "" , Err ( "Expected at least 1 key." . to_string ( ) ) ) ;
215
+ parse ( "<space>x" , Ok ( KeySequence ( ( Named ( Space ) , Some ( ch ( "x" ) ) ) ) ) ) ;
216
+ parse ( "x<space>" , Ok ( KeySequence ( ( ch ( "x" ) , Some ( Named ( Space ) ) ) ) ) ) ;
217
+ parse (
218
+ "<space><space>" ,
219
+ Ok ( KeySequence ( ( Named ( Space ) , Some ( Named ( Space ) ) ) ) ) ,
220
+ ) ;
221
+ parse ( "<<" , Ok ( KeySequence ( ( ch ( "<" ) , Some ( ch ( "<" ) ) ) ) ) ) ;
222
+ parse ( "<>" , Ok ( KeySequence ( ( ch ( "<" ) , Some ( ch ( ">" ) ) ) ) ) ) ;
223
+ parse ( "<" , Ok ( KeySequence ( ( ch ( "<" ) , None ) ) ) ) ;
224
+ parse ( ">>" , Ok ( KeySequence ( ( ch ( ">" ) , Some ( ch ( ">" ) ) ) ) ) ) ;
225
+ parse ( "<<space>" , Ok ( KeySequence ( ( ch ( "<" ) , Some ( Named ( Space ) ) ) ) ) ) ;
226
+ parse (
227
+ "<f32><f31>" ,
228
+ Ok ( KeySequence ( ( Named ( F32 ) , Some ( Named ( F31 ) ) ) ) ) ,
229
+ ) ;
230
+ parse ( "><f32>" , Ok ( KeySequence ( ( ch ( ">" ) , Some ( Named ( F32 ) ) ) ) ) ) ;
231
+ parse (
232
+ "abc" ,
233
+ Err ( "At the moment, only up to 2 keys in a sequence are supported." . to_string ( ) ) ,
234
+ ) ;
235
+ parse (
236
+ "<f32>b<f16>" ,
237
+ Err ( "At the moment, only up to 2 keys in a sequence are supported." . to_string ( ) ) ,
238
+ ) ;
239
+ parse (
240
+ "<@>" ,
241
+ Err ( "Invalid key: <@>. Matching variant not found" . to_string ( ) ) ,
242
+ ) ;
235
243
}
236
244
}
0 commit comments