@@ -270,8 +270,9 @@ pub fn official_bindings() -> &'static [KeyBinding] {
270270#[ cfg( test) ]
271271mod tests {
272272 use super :: {
273- KeyBinding , KeyToken , Locale , Modifier , format_binding, official_bindings,
274- resolve_preferred_tags,
273+ KeyBinding , KeyToken , Locale , Modifier , TextId , delete_footer, editor_footer,
274+ editor_footer_compact, editor_title, format_binding, manager_footer,
275+ manager_footer_compact, official_bindings, resolve_preferred_tags, shift_range, text,
275276 } ;
276277
277278 #[ test]
@@ -305,4 +306,115 @@ mod tests {
305306 assert_eq ! ( resolve_preferred_tags( [ "de-DE" , "es-ES" , "en-US" ] ) , Locale :: EsEs ) ;
306307 assert_eq ! ( resolve_preferred_tags( [ "de-DE" , "fr-FR" ] ) , Locale :: EnUs ) ;
307308 }
309+
310+ #[ test]
311+ fn locale_tags_and_alternation_are_symmetric ( ) {
312+ assert_eq ! ( Locale :: EsEs . tag( ) , "es-ES" ) ;
313+ assert_eq ! ( Locale :: EnUs . tag( ) , "en-US" ) ;
314+ assert_eq ! ( Locale :: EsEs . other( ) , Locale :: EnUs ) ;
315+ assert_eq ! ( Locale :: EnUs . other( ) , Locale :: EsEs ) ;
316+ assert_eq ! ( Locale :: EsEs . other( ) . other( ) , Locale :: EsEs ) ;
317+ }
318+
319+ #[ test]
320+ fn every_defined_text_id_is_translated_in_both_locales ( ) {
321+ let cases: [ ( TextId , & str , & str ) ; 14 ] = [
322+ ( TextId :: ManagerTitle , "COMANDOS PERSONALIZADOS" , "CUSTOM COMMANDS" ) ,
323+ ( TextId :: DeleteTitle , "ELIMINAR COMANDO" , "REMOVE COMMAND" ) ,
324+ ( TextId :: Empty , "Vacío" , "Empty" ) ,
325+ ( TextId :: AliasOptional , "Alias (opcional)" , "Alias (optional)" ) ,
326+ ( TextId :: Command , "Comando" , "Command" ) ,
327+ ( TextId :: Save , "Guardar" , "Save" ) ,
328+ ( TextId :: Cancel , "Cancelar" , "Cancel" ) ,
329+ ( TextId :: Delete , "Eliminar" , "Delete" ) ,
330+ ( TextId :: ConfirmDelete , "¿Eliminar comando?" , "Remove command?" ) ,
331+ ( TextId :: SaveError , "No se pudo guardar" , "Could not save" ) ,
332+ ( TextId :: DeleteError , "No se pudo eliminar" , "Could not delete" ) ,
333+ ( TextId :: CommandSaved , "Comando guardado" , "Command saved" ) ,
334+ ( TextId :: CommandDeleted , "Comando eliminado" , "Command deleted" ) ,
335+ ( TextId :: ManageCommands , "Gestionar comandos personalizados" , "Manage custom commands" ) ,
336+ ] ;
337+ for ( id, expected_es, expected_en) in cases {
338+ assert_eq ! ( text( Locale :: EsEs , id) , expected_es, "es-ES {id:?}" ) ;
339+ assert_eq ! ( text( Locale :: EnUs , id) , expected_en, "en-US {id:?}" ) ;
340+ }
341+ // Identifiers without UI copy resolve to an empty string.
342+ assert_eq ! ( text( Locale :: EsEs , TextId :: Help ) , "" ) ;
343+ assert_eq ! ( text( Locale :: EnUs , TextId :: Quit ) , "" ) ;
344+ }
345+
346+ #[ test]
347+ fn shift_range_and_panel_copy_are_localized ( ) {
348+ assert_eq ! ( shift_range( Locale :: EsEs ) , "Mayús+1–9" ) ;
349+ assert_eq ! ( shift_range( Locale :: EnUs ) , "Shift+1–9" ) ;
350+ assert ! ( manager_footer( Locale :: EsEs ) . contains( "Supr" ) ) ;
351+ assert ! ( manager_footer( Locale :: EnUs ) . contains( "Delete" ) ) ;
352+ assert ! ( manager_footer_compact( Locale :: EsEs ) . contains( "Supr" ) ) ;
353+ assert ! ( manager_footer_compact( Locale :: EnUs ) . contains( "Del" ) ) ;
354+ assert ! ( editor_footer( Locale :: EsEs ) . contains( "Tab" ) ) ;
355+ assert ! ( editor_footer( Locale :: EnUs ) . contains( "Tab" ) ) ;
356+ assert_eq ! ( editor_footer_compact( Locale :: EsEs ) , "Tab · Enter · Esc" ) ;
357+ assert_eq ! ( editor_footer_compact( Locale :: EnUs ) , "Tab · Enter · Esc" ) ;
358+ assert ! ( delete_footer( Locale :: EsEs ) . contains( "Confirmar" ) ) ;
359+ assert ! ( delete_footer( Locale :: EnUs ) . contains( "Confirm" ) ) ;
360+ }
361+
362+ #[ test]
363+ fn editor_title_distinguishes_new_from_edit_in_both_locales ( ) {
364+ assert_eq ! ( editor_title( Locale :: EsEs , true ) , "NUEVO COMANDO" ) ;
365+ assert_eq ! ( editor_title( Locale :: EsEs , false ) , "EDITAR COMANDO" ) ;
366+ assert_eq ! ( editor_title( Locale :: EnUs , true ) , "NEW COMMAND" ) ;
367+ assert_eq ! ( editor_title( Locale :: EnUs , false ) , "EDIT COMMAND" ) ;
368+ }
369+
370+ #[ test]
371+ fn format_binding_covers_modifiers_and_special_keys ( ) {
372+ let cases: [ ( KeyBinding , Locale , & str ) ; 18 ] = [
373+ (
374+ KeyBinding :: with_modifier ( Modifier :: Ctrl , KeyToken :: Char ( 'S' ) ) ,
375+ Locale :: EsEs ,
376+ "Ctrl+S" ,
377+ ) ,
378+ (
379+ KeyBinding :: with_modifier ( Modifier :: Ctrl , KeyToken :: Char ( 'U' ) ) ,
380+ Locale :: EnUs ,
381+ "Ctrl+U" ,
382+ ) ,
383+ (
384+ KeyBinding :: with_modifier ( Modifier :: Shift , KeyToken :: Char ( 'F' ) ) ,
385+ Locale :: EsEs ,
386+ "Mayús+F" ,
387+ ) ,
388+ (
389+ KeyBinding :: with_modifier ( Modifier :: Shift , KeyToken :: Char ( 'F' ) ) ,
390+ Locale :: EnUs ,
391+ "Shift+F" ,
392+ ) ,
393+ ( KeyBinding :: plain ( KeyToken :: Char ( 'q' ) ) , Locale :: EsEs , "q" ) ,
394+ ( KeyBinding :: plain ( KeyToken :: F1 ) , Locale :: EsEs , "F1" ) ,
395+ ( KeyBinding :: plain ( KeyToken :: F2 ) , Locale :: EnUs , "F2" ) ,
396+ ( KeyBinding :: plain ( KeyToken :: F3 ) , Locale :: EsEs , "F3" ) ,
397+ ( KeyBinding :: plain ( KeyToken :: Enter ) , Locale :: EnUs , "Enter" ) ,
398+ ( KeyBinding :: plain ( KeyToken :: Escape ) , Locale :: EsEs , "Esc" ) ,
399+ ( KeyBinding :: plain ( KeyToken :: Up ) , Locale :: EsEs , "↑" ) ,
400+ ( KeyBinding :: plain ( KeyToken :: Down ) , Locale :: EnUs , "↓" ) ,
401+ ( KeyBinding :: plain ( KeyToken :: Left ) , Locale :: EsEs , "←" ) ,
402+ ( KeyBinding :: plain ( KeyToken :: Right ) , Locale :: EnUs , "→" ) ,
403+ ( KeyBinding :: plain ( KeyToken :: Backspace ) , Locale :: EsEs , "Retroceso" ) ,
404+ ( KeyBinding :: plain ( KeyToken :: Backspace ) , Locale :: EnUs , "Backspace" ) ,
405+ (
406+ KeyBinding :: with_modifier ( Modifier :: Shift , KeyToken :: Enter ) ,
407+ Locale :: EnUs ,
408+ "Shift+Enter" ,
409+ ) ,
410+ (
411+ KeyBinding :: with_modifier ( Modifier :: Ctrl , KeyToken :: Backspace ) ,
412+ Locale :: EsEs ,
413+ "Ctrl+Retroceso" ,
414+ ) ,
415+ ] ;
416+ for ( binding, locale, expected) in cases {
417+ assert_eq ! ( format_binding( binding, locale) , expected) ;
418+ }
419+ }
308420}
0 commit comments