@@ -537,3 +537,83 @@ fn test_event_non_key_press() {
537
537
let result = mode. run ( & mut terminal) ;
538
538
assert ! ( result. is_ok( ) ) ;
539
539
}
540
+
541
+ #[ test]
542
+ fn test_run_with_event_error ( ) -> io:: Result < ( ) > {
543
+ use crossterm:: event:: { Event , KeyEventState } ;
544
+ let mut mode = InteractiveMode :: default ( ) ;
545
+
546
+ // Test different event types
547
+ let events = vec ! [
548
+ Event :: Paste ( "test" . to_string( ) ) ,
549
+ Event :: Key ( KeyEvent {
550
+ code: KeyCode :: Char ( 'q' ) ,
551
+ modifiers: KeyModifiers :: NONE ,
552
+ kind: KeyEventKind :: Press ,
553
+ state: KeyEventState :: NONE ,
554
+ } ) ,
555
+ Event :: Key ( KeyEvent {
556
+ code: KeyCode :: Char ( 'q' ) ,
557
+ modifiers: KeyModifiers :: CONTROL ,
558
+ kind: KeyEventKind :: Press ,
559
+ state: KeyEventState :: NONE ,
560
+ } ) ,
561
+ Event :: Key ( KeyEvent {
562
+ code: KeyCode :: Char ( 'r' ) ,
563
+ modifiers: KeyModifiers :: NONE ,
564
+ kind: KeyEventKind :: Press ,
565
+ state: KeyEventState :: NONE ,
566
+ } ) ,
567
+ Event :: Key ( KeyEvent {
568
+ code: KeyCode :: Char ( 'r' ) ,
569
+ modifiers: KeyModifiers :: CONTROL ,
570
+ kind: KeyEventKind :: Press ,
571
+ state: KeyEventState :: NONE ,
572
+ } ) ,
573
+ Event :: Resize ( 20 , 20 ) ,
574
+ Event :: FocusGained ,
575
+ Event :: FocusLost ,
576
+ ] ;
577
+
578
+ for event in events {
579
+ match event {
580
+ Event :: Key ( key_event) => mode. handle_key_event ( key_event) ,
581
+ _ => { }
582
+ }
583
+ }
584
+
585
+ Ok ( ( ) )
586
+ }
587
+
588
+ #[ test]
589
+ fn test_run_with_empty_terminal ( ) -> io:: Result < ( ) > {
590
+ use ratatui:: backend:: TestBackend ;
591
+
592
+ let mut mode = InteractiveMode :: default ( ) ;
593
+ let backend = TestBackend :: new ( 0 , 0 ) ;
594
+ let mut terminal = Terminal :: new ( backend) ?;
595
+
596
+ // Force exit condition
597
+ mode. exit = true ;
598
+
599
+ // This should test both the draw and event handling paths
600
+ let result = mode. run ( & mut terminal) ;
601
+ assert ! ( result. is_ok( ) ) ;
602
+
603
+ Ok ( ( ) )
604
+ }
605
+
606
+ #[ test]
607
+ fn test_draw_with_generic_backend ( ) -> io:: Result < ( ) > {
608
+ let mut mode = InteractiveMode :: default ( ) ;
609
+ let backend = TestBackend :: new ( 10 , 10 ) ;
610
+ let mut terminal = Terminal :: new ( backend) ?;
611
+
612
+ terminal. draw ( |f| mode. draw ( f) ) ?;
613
+
614
+ // Try different frame sizes
615
+ terminal. resize ( Rect :: new ( 0 , 0 , 5 , 5 ) ) ?;
616
+ terminal. draw ( |f| mode. draw ( f) ) ?;
617
+
618
+ Ok ( ( ) )
619
+ }
0 commit comments