@@ -4,55 +4,65 @@ use gix_testtools::fixture_bytes;
4
4
#[ test]
5
5
fn try_resolve ( ) {
6
6
let snapshot = Snapshot :: from_bytes ( & fixture_bytes ( "typical.txt" ) ) ;
7
+ let mut buf = Vec :: with_capacity ( 64 ) ;
7
8
assert_eq ! (
8
- snapshot
. try_resolve
( signature
( "Foo" , "[email protected] " ) . to_ref
( ) ) ,
9
+ snapshot
. try_resolve
( signature
( "Foo" , "[email protected] " ) . to_ref
( & mut buf ) ) ,
9
10
Some ( signature
( "Joe R. Developer" , "[email protected] " ) ) ,
10
11
"resolved signatures contain all original fields, and normalize the email as well to match the one that it was looked up with"
11
12
) ;
13
+ buf. clear ( ) ;
12
14
assert_eq ! (
13
- snapshot
. try_resolve
( signature
( "Joe" , "[email protected] " ) . to_ref
( ) ) ,
15
+ snapshot
. try_resolve
( signature
( "Joe" , "[email protected] " ) . to_ref
( & mut buf ) ) ,
14
16
Some ( signature
( "Joe R. Developer" , "[email protected] " ) ) ,
15
17
"name and email can be mapped specifically"
16
18
) ;
17
19
20
+ buf. clear ( ) ;
18
21
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 ) ) ,
20
23
Some ( signature
( "Jane Doe" , "[email protected] " ) ) ,
21
24
"fix name and email by email"
22
25
) ;
26
+ buf. clear ( ) ;
23
27
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 ) ) ,
25
29
Some ( signature
( "Jane Doe" , "[email protected] " ) ) ,
26
30
"fix name and email by other email"
27
31
) ;
28
32
33
+ buf. clear ( ) ;
29
34
assert_eq ! (
30
- snapshot
. try_resolve
( signature
( "janE" , "[email protected] " ) . to_ref
( ) ) ,
35
+ snapshot
. try_resolve
( signature
( "janE" , "[email protected] " ) . to_ref
( & mut buf ) ) ,
31
36
Some ( signature
( "Jane Doe" , "[email protected] " ) ) ,
32
37
"name and email can be mapped specifically, case insensitive matching of name"
33
38
) ;
39
+ buf. clear ( ) ;
34
40
assert_eq ! (
35
- snapshot. resolve( signature( "janE" , "jane@ipad.(none)" ) . to_ref( ) ) ,
41
+ snapshot. resolve( signature( "janE" , "jane@ipad.(none)" ) . to_ref( & mut buf ) ) ,
36
42
signature
( "janE" , "[email protected] " ) ,
37
43
"an email can be mapped by name and email specifically, both match case-insensitively"
38
44
) ;
39
45
40
46
let sig =
signature ( "Jane" , "[email protected] " ) ;
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" ) ;
42
49
50
+ buf. clear ( ) ;
43
51
assert_eq ! (
44
- snapshot. resolve( sig. to_ref( ) ) ,
52
+ snapshot. resolve( sig. to_ref( & mut buf ) ) ,
45
53
sig,
46
54
"resolution always works here, returning a copy of the original"
47
55
) ;
48
56
49
57
let sig =
signature ( "Jean" , "[email protected] " ) ;
58
+ buf. clear ( ) ;
50
59
assert_eq ! (
51
- snapshot. try_resolve( sig. to_ref( ) ) ,
60
+ snapshot. try_resolve( sig. to_ref( & mut buf ) ) ,
52
61
None ,
53
62
"matched email, unmatched name"
54
63
) ;
55
- assert_eq ! ( snapshot. resolve( sig. to_ref( ) ) , sig) ;
64
+ buf. clear ( ) ;
65
+ assert_eq ! ( snapshot. resolve( sig. to_ref( & mut buf) ) , sig) ;
56
66
57
67
assert_eq ! (
58
68
snapshot. entries( ) ,
@@ -85,16 +95,19 @@ fn non_name_and_name_mappings_will_not_clash() {
85
95
"old-email" ,
86
96
) ,
87
97
] ;
98
+ let mut buf = Vec :: with_capacity ( 64 ) ;
88
99
for entries in [ entries. clone ( ) . into_iter ( ) . rev ( ) . collect :: < Vec < _ > > ( ) , entries] {
89
100
let snapshot = Snapshot :: new ( entries) ;
90
101
102
+ buf. clear ( ) ;
91
103
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 ) ) ,
93
105
Some ( signature( "new-name" , "old-email" ) ) ,
94
106
"it can match by email only, and the email is normalized"
95
107
) ;
108
+ buf. clear ( ) ;
96
109
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 ) ) ,
98
111
Some ( signature( "other-new-name" , "other-new-email" ) ) ,
99
112
"it can match by email and name as well"
100
113
) ;
@@ -117,26 +130,30 @@ fn non_name_and_name_mappings_will_not_clash() {
117
130
#[ test]
118
131
fn overwrite_entries ( ) {
119
132
let snapshot = Snapshot :: from_bytes ( & fixture_bytes ( "overwrite.txt" ) ) ;
133
+ let mut buf = Vec :: with_capacity ( 64 ) ;
120
134
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 ) ) ,
122
136
Some ( signature( "A-overwritten" , "old-a-email" ) ) ,
123
137
"email only by email"
124
138
) ;
125
139
140
+ buf. clear ( ) ;
126
141
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 ) ) ,
128
143
Some ( signature( "B-overwritten" , "new-b-email-overwritten" ) ) ,
129
144
"name and email by email"
130
145
) ;
131
146
147
+ buf. clear ( ) ;
132
148
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 ) ) ,
134
150
Some ( signature( "C-overwritten" , "new-c-email-overwritten" ) ) ,
135
151
"name and email by name and email"
136
152
) ;
137
153
154
+ buf. clear ( ) ;
138
155
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 ) ) ,
140
157
Some ( signature( "unchanged" , "new-d-email-overwritten" ) ) ,
141
158
"email by email"
142
159
) ;
@@ -161,6 +178,6 @@ fn signature(name: &str, email: &str) -> gix_actor::Signature {
161
178
gix_actor:: Signature {
162
179
name : name. into ( ) ,
163
180
email : email. into ( ) ,
164
- time : b "42 +0800". into ( ) ,
181
+ time : gix_date :: parse_raw ( "42 +0800" ) . unwrap ( ) ,
165
182
}
166
183
}
0 commit comments