@@ -4,55 +4,65 @@ use gix_testtools::fixture_bytes;
44#[ test]
55fn try_resolve ( ) {
66 let snapshot = Snapshot :: from_bytes ( & fixture_bytes ( "typical.txt" ) ) ;
7+ let mut buf = Vec :: with_capacity ( 64 ) ;
78 assert_eq ! (
8- snapshot. try_resolve( signature( "Foo" , "Joe@example.com" ) . to_ref( ) ) ,
9+ snapshot. try_resolve( signature( "Foo" , "Joe@example.com" ) . to_ref( & mut buf ) ) ,
910 Some ( signature( "Joe R. Developer" , "joe@example.com" ) ) ,
1011 "resolved signatures contain all original fields, and normalize the email as well to match the one that it was looked up with"
1112 ) ;
13+ buf. clear ( ) ;
1214 assert_eq ! (
13- snapshot. try_resolve( signature( "Joe" , "bugs@example.com" ) . to_ref( ) ) ,
15+ snapshot. try_resolve( signature( "Joe" , "bugs@example.com" ) . to_ref( & mut buf ) ) ,
1416 Some ( signature( "Joe R. Developer" , "joe@example.com" ) ) ,
1517 "name and email can be mapped specifically"
1618 ) ;
1719
20+ buf. clear ( ) ;
1821 assert_eq ! (
19- snapshot. try_resolve( signature( "Jane" , "jane@laptop.(none)" ) . to_ref( ) ) ,
22+ snapshot. try_resolve( signature( "Jane" , "jane@laptop.(none)" ) . to_ref( & mut buf ) ) ,
2023 Some ( signature( "Jane Doe" , "jane@example.com" ) ) ,
2124 "fix name and email by email"
2225 ) ;
26+ buf. clear ( ) ;
2327 assert_eq ! (
24- snapshot. try_resolve( signature( "Jane" , "jane@desktop.(none)" ) . to_ref( ) ) ,
28+ snapshot. try_resolve( signature( "Jane" , "jane@desktop.(none)" ) . to_ref( & mut buf ) ) ,
2529 Some ( signature( "Jane Doe" , "jane@example.com" ) ) ,
2630 "fix name and email by other email"
2731 ) ;
2832
33+ buf. clear ( ) ;
2934 assert_eq ! (
30- snapshot. try_resolve( signature( "janE" , "Bugs@example.com" ) . to_ref( ) ) ,
35+ snapshot. try_resolve( signature( "janE" , "Bugs@example.com" ) . to_ref( & mut buf ) ) ,
3136 Some ( signature( "Jane Doe" , "jane@example.com" ) ) ,
3237 "name and email can be mapped specifically, case insensitive matching of name"
3338 ) ;
39+ buf. clear ( ) ;
3440 assert_eq ! (
35- snapshot. resolve( signature( "janE" , "jane@ipad.(none)" ) . to_ref( ) ) ,
41+ snapshot. resolve( signature( "janE" , "jane@ipad.(none)" ) . to_ref( & mut buf ) ) ,
3642 signature( "janE" , "jane@example.com" ) ,
3743 "an email can be mapped by name and email specifically, both match case-insensitively"
3844 ) ;
3945
4046 let sig = signature ( "Jane" , "other@example.com" ) ;
41- assert_eq ! ( snapshot. try_resolve( sig. to_ref( ) ) , None , "unmatched email" ) ;
47+ buf. clear ( ) ;
48+ assert_eq ! ( snapshot. try_resolve( sig. to_ref( & mut buf) ) , None , "unmatched email" ) ;
4249
50+ buf. clear ( ) ;
4351 assert_eq ! (
44- snapshot. resolve( sig. to_ref( ) ) ,
52+ snapshot. resolve( sig. to_ref( & mut buf ) ) ,
4553 sig,
4654 "resolution always works here, returning a copy of the original"
4755 ) ;
4856
4957 let sig = signature ( "Jean" , "bugs@example.com" ) ;
58+ buf. clear ( ) ;
5059 assert_eq ! (
51- snapshot. try_resolve( sig. to_ref( ) ) ,
60+ snapshot. try_resolve( sig. to_ref( & mut buf ) ) ,
5261 None ,
5362 "matched email, unmatched name"
5463 ) ;
55- assert_eq ! ( snapshot. resolve( sig. to_ref( ) ) , sig) ;
64+ buf. clear ( ) ;
65+ assert_eq ! ( snapshot. resolve( sig. to_ref( & mut buf) ) , sig) ;
5666
5767 assert_eq ! (
5868 snapshot. entries( ) ,
@@ -85,16 +95,19 @@ fn non_name_and_name_mappings_will_not_clash() {
8595 "old-email" ,
8696 ) ,
8797 ] ;
98+ let mut buf = Vec :: with_capacity ( 64 ) ;
8899 for entries in [ entries. clone ( ) . into_iter ( ) . rev ( ) . collect :: < Vec < _ > > ( ) , entries] {
89100 let snapshot = Snapshot :: new ( entries) ;
90101
102+ buf. clear ( ) ;
91103 assert_eq ! (
92- snapshot. try_resolve( signature( "replace-by-email" , "Old-Email" ) . to_ref( ) ) ,
104+ snapshot. try_resolve( signature( "replace-by-email" , "Old-Email" ) . to_ref( & mut buf ) ) ,
93105 Some ( signature( "new-name" , "old-email" ) ) ,
94106 "it can match by email only, and the email is normalized"
95107 ) ;
108+ buf. clear ( ) ;
96109 assert_eq ! (
97- snapshot. try_resolve( signature( "old-name" , "Old-Email" ) . to_ref( ) ) ,
110+ snapshot. try_resolve( signature( "old-name" , "Old-Email" ) . to_ref( & mut buf ) ) ,
98111 Some ( signature( "other-new-name" , "other-new-email" ) ) ,
99112 "it can match by email and name as well"
100113 ) ;
@@ -117,26 +130,30 @@ fn non_name_and_name_mappings_will_not_clash() {
117130#[ test]
118131fn overwrite_entries ( ) {
119132 let snapshot = Snapshot :: from_bytes ( & fixture_bytes ( "overwrite.txt" ) ) ;
133+ let mut buf = Vec :: with_capacity ( 64 ) ;
120134 assert_eq ! (
121- snapshot. try_resolve( signature( "does not matter" , "old-a-email" ) . to_ref( ) ) ,
135+ snapshot. try_resolve( signature( "does not matter" , "old-a-email" ) . to_ref( & mut buf ) ) ,
122136 Some ( signature( "A-overwritten" , "old-a-email" ) ) ,
123137 "email only by email"
124138 ) ;
125139
140+ buf. clear ( ) ;
126141 assert_eq ! (
127- snapshot. try_resolve( signature( "to be replaced" , "old-b-EMAIL" ) . to_ref( ) ) ,
142+ snapshot. try_resolve( signature( "to be replaced" , "old-b-EMAIL" ) . to_ref( & mut buf ) ) ,
128143 Some ( signature( "B-overwritten" , "new-b-email-overwritten" ) ) ,
129144 "name and email by email"
130145 ) ;
131146
147+ buf. clear ( ) ;
132148 assert_eq ! (
133- snapshot. try_resolve( signature( "old-c" , "old-C-email" ) . to_ref( ) ) ,
149+ snapshot. try_resolve( signature( "old-c" , "old-C-email" ) . to_ref( & mut buf ) ) ,
134150 Some ( signature( "C-overwritten" , "new-c-email-overwritten" ) ) ,
135151 "name and email by name and email"
136152 ) ;
137153
154+ buf. clear ( ) ;
138155 assert_eq ! (
139- snapshot. try_resolve( signature( "unchanged" , "old-d-email" ) . to_ref( ) ) ,
156+ snapshot. try_resolve( signature( "unchanged" , "old-d-email" ) . to_ref( & mut buf ) ) ,
140157 Some ( signature( "unchanged" , "new-d-email-overwritten" ) ) ,
141158 "email by email"
142159 ) ;
@@ -161,6 +178,6 @@ fn signature(name: &str, email: &str) -> gix_actor::Signature {
161178 gix_actor:: Signature {
162179 name : name. into ( ) ,
163180 email : email. into ( ) ,
164- time : b "42 +0800". into ( ) ,
181+ time : gix_date :: parse_raw ( "42 +0800" ) . unwrap ( ) ,
165182 }
166183}
0 commit comments