@@ -54,7 +54,7 @@ impl Buffer {
54
54
/// Returns a Buffer with all cells set to the default one
55
55
#[ must_use]
56
56
pub fn empty ( area : Rect ) -> Self {
57
- Self :: filled ( area, & Cell :: default ( ) )
57
+ Self :: filled ( area, & Cell :: EMPTY )
58
58
}
59
59
60
60
/// Returns a Buffer with all cells initialized with the attributes of the given Cell
@@ -278,7 +278,7 @@ impl Buffer {
278
278
if self . content . len ( ) > length {
279
279
self . content . truncate ( length) ;
280
280
} else {
281
- self . content . resize ( length, Cell :: default ( ) ) ;
281
+ self . content . resize ( length, Cell :: EMPTY ) ;
282
282
}
283
283
self . area = area;
284
284
}
@@ -293,7 +293,7 @@ impl Buffer {
293
293
/// Merge an other buffer into this one
294
294
pub fn merge ( & mut self , other : & Self ) {
295
295
let area = self . area . union ( other. area ) ;
296
- self . content . resize ( area. area ( ) as usize , Cell :: default ( ) ) ;
296
+ self . content . resize ( area. area ( ) as usize , Cell :: EMPTY ) ;
297
297
298
298
// Move original content to the appropriate space
299
299
let size = self . area . area ( ) as usize ;
@@ -453,12 +453,6 @@ mod tests {
453
453
454
454
use super :: * ;
455
455
456
- fn cell ( s : & str ) -> Cell {
457
- let mut cell = Cell :: default ( ) ;
458
- cell. set_symbol ( s) ;
459
- cell
460
- }
461
-
462
456
#[ test]
463
457
fn debug_empty_buffer ( ) {
464
458
let buffer = Buffer :: empty ( Rect :: ZERO ) ;
@@ -749,25 +743,25 @@ mod tests {
749
743
let prev = Buffer :: empty ( area) ;
750
744
let next = Buffer :: empty ( area) ;
751
745
let diff = prev. diff ( & next) ;
752
- assert_eq ! ( diff, vec! [ ] ) ;
746
+ assert_eq ! ( diff, [ ] ) ;
753
747
}
754
748
755
749
#[ test]
756
750
fn diff_empty_filled ( ) {
757
751
let area = Rect :: new ( 0 , 0 , 40 , 40 ) ;
758
752
let prev = Buffer :: empty ( area) ;
759
- let next = Buffer :: filled ( area, Cell :: default ( ) . set_symbol ( "a" ) ) ;
753
+ let next = Buffer :: filled ( area, & Cell :: new ( "a" ) ) ;
760
754
let diff = prev. diff ( & next) ;
761
755
assert_eq ! ( diff. len( ) , 40 * 40 ) ;
762
756
}
763
757
764
758
#[ test]
765
759
fn diff_filled_filled ( ) {
766
760
let area = Rect :: new ( 0 , 0 , 40 , 40 ) ;
767
- let prev = Buffer :: filled ( area, Cell :: default ( ) . set_symbol ( "a" ) ) ;
768
- let next = Buffer :: filled ( area, Cell :: default ( ) . set_symbol ( "a" ) ) ;
761
+ let prev = Buffer :: filled ( area, & Cell :: new ( "a" ) ) ;
762
+ let next = Buffer :: filled ( area, & Cell :: new ( "a" ) ) ;
769
763
let diff = prev. diff ( & next) ;
770
- assert_eq ! ( diff, vec! [ ] ) ;
764
+ assert_eq ! ( diff, [ ] ) ;
771
765
}
772
766
773
767
#[ test]
@@ -789,35 +783,36 @@ mod tests {
789
783
let diff = prev. diff ( & next) ;
790
784
assert_eq ! (
791
785
diff,
792
- vec! [
793
- ( 2 , 1 , & cell ( "I" ) ) ,
794
- ( 3 , 1 , & cell ( "T" ) ) ,
795
- ( 4 , 1 , & cell ( "L" ) ) ,
796
- ( 5 , 1 , & cell ( "E" ) ) ,
786
+ [
787
+ ( 2 , 1 , & Cell :: new ( "I" ) ) ,
788
+ ( 3 , 1 , & Cell :: new ( "T" ) ) ,
789
+ ( 4 , 1 , & Cell :: new ( "L" ) ) ,
790
+ ( 5 , 1 , & Cell :: new ( "E" ) ) ,
797
791
]
798
792
) ;
799
793
}
800
794
801
795
#[ test]
802
- #[ rustfmt:: skip]
803
796
fn diff_multi_width ( ) {
797
+ #[ rustfmt:: skip]
804
798
let prev = Buffer :: with_lines ( [
805
799
"┌Title─┐ " ,
806
800
"└──────┘ " ,
807
801
] ) ;
802
+ #[ rustfmt:: skip]
808
803
let next = Buffer :: with_lines ( [
809
804
"┌称号──┐ " ,
810
805
"└──────┘ " ,
811
806
] ) ;
812
807
let diff = prev. diff ( & next) ;
813
808
assert_eq ! (
814
809
diff,
815
- vec! [
816
- ( 1 , 0 , & cell ( "称" ) ) ,
810
+ [
811
+ ( 1 , 0 , & Cell :: new ( "称" ) ) ,
817
812
// Skipped "i"
818
- ( 3 , 0 , & cell ( "号" ) ) ,
813
+ ( 3 , 0 , & Cell :: new ( "号" ) ) ,
819
814
// Skipped "l"
820
- ( 5 , 0 , & cell ( "─" ) ) ,
815
+ ( 5 , 0 , & Cell :: new ( "─" ) ) ,
821
816
]
822
817
) ;
823
818
}
@@ -830,7 +825,11 @@ mod tests {
830
825
let diff = prev. diff ( & next) ;
831
826
assert_eq ! (
832
827
diff,
833
- vec![ ( 1 , 0 , & cell( "─" ) ) , ( 2 , 0 , & cell( "称" ) ) , ( 4 , 0 , & cell( "号" ) ) , ]
828
+ [
829
+ ( 1 , 0 , & Cell :: new( "─" ) ) ,
830
+ ( 2 , 0 , & Cell :: new( "称" ) ) ,
831
+ ( 4 , 0 , & Cell :: new( "号" ) ) ,
832
+ ]
834
833
) ;
835
834
}
836
835
@@ -843,67 +842,33 @@ mod tests {
843
842
}
844
843
845
844
let diff = prev. diff ( & next) ;
846
- assert_eq ! ( diff, vec![ ( 0 , 0 , & cell( "4" ) ) ] , ) ;
847
- }
848
-
849
- #[ test]
850
- fn merge ( ) {
851
- let mut one = Buffer :: filled (
852
- Rect {
853
- x : 0 ,
854
- y : 0 ,
855
- width : 2 ,
856
- height : 2 ,
857
- } ,
858
- Cell :: default ( ) . set_symbol ( "1" ) ,
859
- ) ;
860
- let two = Buffer :: filled (
861
- Rect {
862
- x : 0 ,
863
- y : 2 ,
864
- width : 2 ,
865
- height : 2 ,
866
- } ,
867
- Cell :: default ( ) . set_symbol ( "2" ) ,
868
- ) ;
869
- one. merge ( & two) ;
870
- assert_eq ! ( one, Buffer :: with_lines( [ "11" , "11" , "22" , "22" ] ) ) ;
845
+ assert_eq ! ( diff, [ ( 0 , 0 , & Cell :: new( "4" ) ) ] , ) ;
871
846
}
872
847
873
- #[ test]
874
- fn merge2 ( ) {
875
- let mut one = Buffer :: filled (
876
- Rect {
877
- x : 2 ,
878
- y : 2 ,
879
- width : 2 ,
880
- height : 2 ,
881
- } ,
882
- Cell :: default ( ) . set_symbol ( "1" ) ,
883
- ) ;
884
- let two = Buffer :: filled (
885
- Rect {
886
- x : 0 ,
887
- y : 0 ,
888
- width : 2 ,
889
- height : 2 ,
890
- } ,
891
- Cell :: default ( ) . set_symbol ( "2" ) ,
892
- ) ;
848
+ #[ rstest]
849
+ #[ case( Rect :: new( 0 , 0 , 2 , 2 ) , Rect :: new( 0 , 2 , 2 , 2 ) , [ "11" , "11" , "22" , "22" ] ) ]
850
+ #[ case( Rect :: new( 2 , 2 , 2 , 2 ) , Rect :: new( 0 , 0 , 2 , 2 ) , [ "22 " , "22 " , " 11" , " 11" ] ) ]
851
+ fn merge < ' line , Lines > ( #[ case] one : Rect , #[ case] two : Rect , #[ case] expected : Lines )
852
+ where
853
+ Lines : IntoIterator ,
854
+ Lines :: Item : Into < Line < ' line > > ,
855
+ {
856
+ let mut one = Buffer :: filled ( one, & Cell :: new ( "1" ) ) ;
857
+ let two = Buffer :: filled ( two, & Cell :: new ( "2" ) ) ;
893
858
one. merge ( & two) ;
894
- assert_eq ! ( one, Buffer :: with_lines( [ "22 " , "22 " , " 11" , " 11" ] ) ) ;
859
+ assert_eq ! ( one, Buffer :: with_lines( expected ) ) ;
895
860
}
896
861
897
862
#[ test]
898
- fn merge3 ( ) {
863
+ fn merge_with_offset ( ) {
899
864
let mut one = Buffer :: filled (
900
865
Rect {
901
866
x : 3 ,
902
867
y : 3 ,
903
868
width : 2 ,
904
869
height : 2 ,
905
870
} ,
906
- Cell :: default ( ) . set_symbol ( "1" ) ,
871
+ & Cell :: new ( "1" ) ,
907
872
) ;
908
873
let two = Buffer :: filled (
909
874
Rect {
@@ -912,54 +877,31 @@ mod tests {
912
877
width : 3 ,
913
878
height : 4 ,
914
879
} ,
915
- Cell :: default ( ) . set_symbol ( "2" ) ,
880
+ & Cell :: new ( "2" ) ,
916
881
) ;
917
882
one. merge ( & two) ;
918
- let mut merged = Buffer :: with_lines ( [ "222 " , "222 " , "2221" , "2221" ] ) ;
919
- merged . area = Rect {
883
+ let mut expected = Buffer :: with_lines ( [ "222 " , "222 " , "2221" , "2221" ] ) ;
884
+ expected . area = Rect {
920
885
x : 1 ,
921
886
y : 1 ,
922
887
width : 4 ,
923
888
height : 4 ,
924
889
} ;
925
- assert_eq ! ( one, merged) ;
926
- }
927
-
928
- #[ test]
929
- fn merge_skip ( ) {
930
- let mut one = Buffer :: filled (
931
- Rect {
932
- x : 0 ,
933
- y : 0 ,
934
- width : 2 ,
935
- height : 2 ,
936
- } ,
937
- Cell :: default ( ) . set_symbol ( "1" ) ,
938
- ) ;
939
- let two = Buffer :: filled (
940
- Rect {
941
- x : 0 ,
942
- y : 1 ,
943
- width : 2 ,
944
- height : 2 ,
945
- } ,
946
- Cell :: default ( ) . set_symbol ( "2" ) . set_skip ( true ) ,
947
- ) ;
948
- one. merge ( & two) ;
949
- let skipped: Vec < bool > = one. content ( ) . iter ( ) . map ( |c| c. skip ) . collect ( ) ;
950
- assert_eq ! ( skipped, vec![ false , false , true , true , true , true ] ) ;
890
+ assert_eq ! ( one, expected) ;
951
891
}
952
892
953
- #[ test]
954
- fn merge_skip2 ( ) {
893
+ #[ rstest]
894
+ #[ case( false , true , [ false , false , true , true , true , true ] ) ]
895
+ #[ case( true , false , [ true , true , false , false , false , false ] ) ]
896
+ fn merge_skip ( #[ case] one : bool , #[ case] two : bool , #[ case] expected : [ bool ; 6 ] ) {
955
897
let mut one = Buffer :: filled (
956
898
Rect {
957
899
x : 0 ,
958
900
y : 0 ,
959
901
width : 2 ,
960
902
height : 2 ,
961
903
} ,
962
- Cell :: default ( ) . set_symbol ( "1" ) . set_skip ( true ) ,
904
+ Cell :: new ( "1" ) . set_skip ( one ) ,
963
905
) ;
964
906
let two = Buffer :: filled (
965
907
Rect {
@@ -968,11 +910,11 @@ mod tests {
968
910
width : 2 ,
969
911
height : 2 ,
970
912
} ,
971
- Cell :: default ( ) . set_symbol ( "2" ) ,
913
+ Cell :: new ( "2" ) . set_skip ( two ) ,
972
914
) ;
973
915
one. merge ( & two) ;
974
- let skipped: Vec < bool > = one. content ( ) . iter ( ) . map ( |c| c. skip ) . collect ( ) ;
975
- assert_eq ! ( skipped, vec! [ true , true , false , false , false , false ] ) ;
916
+ let skipped = one. content ( ) . iter ( ) . map ( |c| c. skip ) . collect :: < Vec < _ > > ( ) ;
917
+ assert_eq ! ( skipped, expected ) ;
976
918
}
977
919
978
920
#[ test]
0 commit comments