@@ -51,6 +51,7 @@ pub enum Function {
51
51
Version ( PathBuf , String , ComparisonOperator ) ,
52
52
ProductVersion ( PathBuf , String , ComparisonOperator ) ,
53
53
FilenameVersion ( PathBuf , Regex , String , ComparisonOperator ) ,
54
+ DescriptionContains ( PathBuf , Regex ) ,
54
55
}
55
56
56
57
impl fmt:: Display for Function {
@@ -82,6 +83,9 @@ impl fmt::Display for Function {
82
83
c
83
84
)
84
85
}
86
+ DescriptionContains ( p, r) => {
87
+ write ! ( f, "description_contains(\" {}\" , \" {}\" )" , p. display( ) , r)
88
+ }
85
89
}
86
90
}
87
91
}
@@ -123,6 +127,9 @@ impl PartialEq for Function {
123
127
&& eq ( r1. as_str ( ) , r2. as_str ( ) )
124
128
&& eq ( & p1. to_string_lossy ( ) , & p2. to_string_lossy ( ) )
125
129
}
130
+ ( DescriptionContains ( p1, r1) , DescriptionContains ( p2, r2) ) => {
131
+ eq ( r1. as_str ( ) , r2. as_str ( ) ) && eq ( & p1. to_string_lossy ( ) , & p2. to_string_lossy ( ) )
132
+ }
126
133
_ => false ,
127
134
}
128
135
}
@@ -187,6 +194,10 @@ impl Hash for Function {
187
194
v. to_lowercase ( ) . hash ( state) ;
188
195
c. hash ( state) ;
189
196
}
197
+ DescriptionContains ( p, r) => {
198
+ p. to_string_lossy ( ) . to_lowercase ( ) . hash ( state) ;
199
+ r. as_str ( ) . to_lowercase ( ) . hash ( state) ;
200
+ }
190
201
}
191
202
192
203
discriminant ( self ) . hash ( state) ;
@@ -332,6 +343,16 @@ mod tests {
332
343
& format!( "{}" , function)
333
344
) ;
334
345
}
346
+
347
+ #[ test]
348
+ fn function_fmt_for_description_contains_should_format_correctly ( ) {
349
+ let function = Function :: DescriptionContains ( "Blank.esp" . into ( ) , regex ( "€ƒ." ) ) ;
350
+
351
+ assert_eq ! (
352
+ "description_contains(\" Blank.esp\" , \" €ƒ.\" )" ,
353
+ & format!( "{}" , function)
354
+ ) ;
355
+ }
335
356
}
336
357
337
358
mod eq {
@@ -815,6 +836,40 @@ mod tests {
815
836
)
816
837
) ;
817
838
}
839
+
840
+ #[ test]
841
+ fn function_eq_for_description_contains_should_check_pathbuf_and_regex ( ) {
842
+ assert_eq ! (
843
+ Function :: DescriptionContains ( "Blank.esp" . into( ) , regex( "€ƒ." ) ) ,
844
+ Function :: DescriptionContains ( "Blank.esp" . into( ) , regex( "€ƒ." ) )
845
+ ) ;
846
+
847
+ assert_ne ! (
848
+ Function :: DescriptionContains ( "Blank.esp" . into( ) , regex( "€ƒ." ) ) ,
849
+ Function :: DescriptionContains ( "Blank.esp" . into( ) , regex( ".*" ) )
850
+ ) ;
851
+ assert_ne ! (
852
+ Function :: DescriptionContains ( "Blank.esp" . into( ) , regex( "€ƒ." ) ) ,
853
+ Function :: DescriptionContains ( "other" . into( ) , regex( "€ƒ." ) )
854
+ ) ;
855
+ }
856
+
857
+ #[ test]
858
+ fn function_eq_for_description_contains_should_be_case_insensitive_on_pathbuf_and_regex ( ) {
859
+ assert_eq ! (
860
+ Function :: DescriptionContains ( "Blank.esp" . into( ) , regex( "€ƒ." ) ) ,
861
+ Function :: DescriptionContains ( "blank.esp" . into( ) , regex( "€Ƒ." ) )
862
+ ) ;
863
+ }
864
+
865
+ #[ test]
866
+ fn function_eq_description_contains_should_not_be_equal_to_file_regex_with_same_pathbuf_and_regex (
867
+ ) {
868
+ assert_ne ! (
869
+ Function :: DescriptionContains ( "Blank.esp" . into( ) , regex( "€ƒ." ) ) ,
870
+ Function :: FileRegex ( "Blank.esp" . into( ) , regex( "€ƒ." ) )
871
+ ) ;
872
+ }
818
873
}
819
874
820
875
mod hash {
@@ -1346,5 +1401,39 @@ mod tests {
1346
1401
1347
1402
assert_eq ! ( hash( function1) , hash( function2) ) ;
1348
1403
}
1404
+
1405
+ #[ test]
1406
+ fn function_hash_description_contains_should_hash_pathbuf_and_regex ( ) {
1407
+ let function1 = Function :: DescriptionContains ( "Blank.esp" . into ( ) , regex ( "€ƒ." ) ) ;
1408
+ let function2 = Function :: DescriptionContains ( "Blank.esp" . into ( ) , regex ( "€ƒ." ) ) ;
1409
+
1410
+ assert_eq ! ( hash( function1) , hash( function2) ) ;
1411
+
1412
+ let function1 = Function :: DescriptionContains ( "Blank.esp" . into ( ) , regex ( "€ƒ." ) ) ;
1413
+ let function2 = Function :: DescriptionContains ( "other" . into ( ) , regex ( "€ƒ." ) ) ;
1414
+
1415
+ assert_ne ! ( hash( function1) , hash( function2) ) ;
1416
+
1417
+ let function1 = Function :: DescriptionContains ( "Blank.esp" . into ( ) , regex ( "€ƒ." ) ) ;
1418
+ let function2 = Function :: DescriptionContains ( "Blank.esp" . into ( ) , regex ( ".*" ) ) ;
1419
+
1420
+ assert_ne ! ( hash( function1) , hash( function2) ) ;
1421
+ }
1422
+
1423
+ #[ test]
1424
+ fn function_hash_description_contains_should_be_case_insensitive ( ) {
1425
+ let function1 = Function :: DescriptionContains ( "blank.esp" . into ( ) , regex ( "€Ƒ." ) ) ;
1426
+ let function2 = Function :: DescriptionContains ( "Blank.esp" . into ( ) , regex ( "€ƒ." ) ) ;
1427
+
1428
+ assert_eq ! ( hash( function1) , hash( function2) ) ;
1429
+ }
1430
+
1431
+ #[ test]
1432
+ fn function_hash_file_regex_and_description_contains_should_not_have_equal_hashes ( ) {
1433
+ let function1 = Function :: FileRegex ( "Blank.esp" . into ( ) , regex ( "€ƒ." ) ) ;
1434
+ let function2 = Function :: DescriptionContains ( "Blank.esp" . into ( ) , regex ( "€ƒ." ) ) ;
1435
+
1436
+ assert_ne ! ( hash( function1) , hash( function2) ) ;
1437
+ }
1349
1438
}
1350
1439
}
0 commit comments