1+ use gix_date:: parse:: TimeBuf ;
12use gix_mailmap:: { Entry , Snapshot } ;
23use gix_testtools:: fixture_bytes;
34
45#[ test]
56fn try_resolve ( ) {
67 let snapshot = Snapshot :: from_bytes ( & fixture_bytes ( "typical.txt" ) ) ;
7- let mut buf = Vec :: with_capacity ( 64 ) ;
8+ let mut buf = TimeBuf :: default ( ) ;
89 assert_eq ! (
910 snapshot
. try_resolve
( signature
( "Foo" , "[email protected] " ) . to_ref
( & mut buf
) ) , 1011 Some ( signature
( "Joe R. Developer" , "[email protected] " ) ) , 1112 "resolved signatures contain all original fields, and normalize the email as well to match the one that it was looked up with"
1213 ) ;
13- buf. clear ( ) ;
1414 assert_eq ! (
1515 snapshot
. try_resolve
( signature
( "Joe" , "[email protected] " ) . to_ref
( & mut buf
) ) , 1616 Some ( signature
( "Joe R. Developer" , "[email protected] " ) ) , 1717 "name and email can be mapped specifically"
1818 ) ;
1919
20- buf. clear ( ) ;
2120 assert_eq ! (
2221 snapshot. try_resolve( signature( "Jane" , "jane@laptop.(none)" ) . to_ref( & mut buf) ) ,
2322 Some ( signature
( "Jane Doe" , "[email protected] " ) ) , 2423 "fix name and email by email"
2524 ) ;
26- buf. clear ( ) ;
2725 assert_eq ! (
2826 snapshot. try_resolve( signature( "Jane" , "jane@desktop.(none)" ) . to_ref( & mut buf) ) ,
2927 Some ( signature
( "Jane Doe" , "[email protected] " ) ) , 3028 "fix name and email by other email"
3129 ) ;
3230
33- buf. clear ( ) ;
3431 assert_eq ! (
3532 snapshot
. try_resolve
( signature
( "janE" , "[email protected] " ) . to_ref
( & mut buf
) ) , 3633 Some ( signature
( "Jane Doe" , "[email protected] " ) ) , 3734 "name and email can be mapped specifically, case insensitive matching of name"
3835 ) ;
39- buf. clear ( ) ;
4036 assert_eq ! (
4137 snapshot. resolve( signature( "janE" , "jane@ipad.(none)" ) . to_ref( & mut buf) ) ,
4238 signature
( "janE" , "[email protected] " ) , 4339 "an email can be mapped by name and email specifically, both match case-insensitively"
4440 ) ;
4541
4642 let sig =
signature ( "Jane" , "[email protected] " ) ; 47- buf. clear ( ) ;
4843 assert_eq ! ( snapshot. try_resolve( sig. to_ref( & mut buf) ) , None , "unmatched email" ) ;
4944
50- buf. clear ( ) ;
5145 assert_eq ! (
5246 snapshot. resolve( sig. to_ref( & mut buf) ) ,
5347 sig,
5448 "resolution always works here, returning a copy of the original"
5549 ) ;
5650
5751 let sig =
signature ( "Jean" , "[email protected] " ) ; 58- buf. clear ( ) ;
5952 assert_eq ! (
6053 snapshot. try_resolve( sig. to_ref( & mut buf) ) ,
6154 None ,
6255 "matched email, unmatched name"
6356 ) ;
64- buf. clear ( ) ;
6557 assert_eq ! ( snapshot. resolve( sig. to_ref( & mut buf) ) , sig) ;
6658
6759 assert_eq ! (
@@ -95,17 +87,15 @@ fn non_name_and_name_mappings_will_not_clash() {
9587 "old-email" ,
9688 ) ,
9789 ] ;
98- let mut buf = Vec :: with_capacity ( 64 ) ;
90+ let mut buf = TimeBuf :: default ( ) ;
9991 for entries in [ entries. clone ( ) . into_iter ( ) . rev ( ) . collect :: < Vec < _ > > ( ) , entries] {
10092 let snapshot = Snapshot :: new ( entries) ;
10193
102- buf. clear ( ) ;
10394 assert_eq ! (
10495 snapshot. try_resolve( signature( "replace-by-email" , "Old-Email" ) . to_ref( & mut buf) ) ,
10596 Some ( signature( "new-name" , "old-email" ) ) ,
10697 "it can match by email only, and the email is normalized"
10798 ) ;
108- buf. clear ( ) ;
10999 assert_eq ! (
110100 snapshot. try_resolve( signature( "old-name" , "Old-Email" ) . to_ref( & mut buf) ) ,
111101 Some ( signature( "other-new-name" , "other-new-email" ) ) ,
@@ -130,28 +120,25 @@ fn non_name_and_name_mappings_will_not_clash() {
130120#[ test]
131121fn overwrite_entries ( ) {
132122 let snapshot = Snapshot :: from_bytes ( & fixture_bytes ( "overwrite.txt" ) ) ;
133- let mut buf = Vec :: with_capacity ( 64 ) ;
123+ let mut buf = TimeBuf :: default ( ) ;
134124 assert_eq ! (
135125 snapshot. try_resolve( signature( "does not matter" , "old-a-email" ) . to_ref( & mut buf) ) ,
136126 Some ( signature( "A-overwritten" , "old-a-email" ) ) ,
137127 "email only by email"
138128 ) ;
139129
140- buf. clear ( ) ;
141130 assert_eq ! (
142131 snapshot. try_resolve( signature( "to be replaced" , "old-b-EMAIL" ) . to_ref( & mut buf) ) ,
143132 Some ( signature( "B-overwritten" , "new-b-email-overwritten" ) ) ,
144133 "name and email by email"
145134 ) ;
146135
147- buf. clear ( ) ;
148136 assert_eq ! (
149137 snapshot. try_resolve( signature( "old-c" , "old-C-email" ) . to_ref( & mut buf) ) ,
150138 Some ( signature( "C-overwritten" , "new-c-email-overwritten" ) ) ,
151139 "name and email by name and email"
152140 ) ;
153141
154- buf. clear ( ) ;
155142 assert_eq ! (
156143 snapshot. try_resolve( signature( "unchanged" , "old-d-email" ) . to_ref( & mut buf) ) ,
157144 Some ( signature( "unchanged" , "new-d-email-overwritten" ) ) ,
@@ -178,6 +165,6 @@ fn signature(name: &str, email: &str) -> gix_actor::Signature {
178165 gix_actor:: Signature {
179166 name : name. into ( ) ,
180167 email : email. into ( ) ,
181- time : gix_date:: parse_raw ( "42 +0800" ) . unwrap ( ) ,
168+ time : gix_date:: parse_header ( "42 +0800" ) . unwrap ( ) ,
182169 }
183170}
0 commit comments