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