@@ -69,84 +69,62 @@ func TestParsePatchDate(t *testing.T) {
6969
7070 tests := map [string ]struct {
7171 Input string
72- Output PatchDate
72+ Output time.Time
73+ Err interface {}
7374 }{
7475 "default" : {
75- Input : "Thu Apr 9 01:07:06 2020 -0700" ,
76- Output : PatchDate {
77- Parsed : expected ,
78- Raw : "Thu Apr 9 01:07:06 2020 -0700" ,
79- },
76+ Input : "Thu Apr 9 01:07:06 2020 -0700" ,
77+ Output : expected ,
8078 },
8179 "defaultLocal" : {
82- Input : "Thu Apr 9 01:07:06 2020" ,
83- Output : PatchDate {
84- Parsed : time .Date (2020 , 4 , 9 , 1 , 7 , 6 , 0 , time .Local ),
85- Raw : "Thu Apr 9 01:07:06 2020" ,
86- },
80+ Input : "Thu Apr 9 01:07:06 2020" ,
81+ Output : time .Date (2020 , 4 , 9 , 1 , 7 , 6 , 0 , time .Local ),
8782 },
8883 "iso" : {
89- Input : "2020-04-09 01:07:06 -0700" ,
90- Output : PatchDate {
91- Parsed : expected ,
92- Raw : "2020-04-09 01:07:06 -0700" ,
93- },
84+ Input : "2020-04-09 01:07:06 -0700" ,
85+ Output : expected ,
9486 },
9587 "isoStrict" : {
96- Input : "2020-04-09T01:07:06-07:00" ,
97- Output : PatchDate {
98- Parsed : expected ,
99- Raw : "2020-04-09T01:07:06-07:00" ,
100- },
88+ Input : "2020-04-09T01:07:06-07:00" ,
89+ Output : expected ,
10190 },
10291 "rfc" : {
103- Input : "Thu, 9 Apr 2020 01:07:06 -0700" ,
104- Output : PatchDate {
105- Parsed : expected ,
106- Raw : "Thu, 9 Apr 2020 01:07:06 -0700" ,
107- },
92+ Input : "Thu, 9 Apr 2020 01:07:06 -0700" ,
93+ Output : expected ,
10894 },
10995 "short" : {
110- Input : "2020-04-09" ,
111- Output : PatchDate {
112- Parsed : time .Date (2020 , 4 , 9 , 0 , 0 , 0 , 0 , time .Local ),
113- Raw : "2020-04-09" ,
114- },
96+ Input : "2020-04-09" ,
97+ Output : time .Date (2020 , 4 , 9 , 0 , 0 , 0 , 0 , time .Local ),
11598 },
11699 "raw" : {
117- Input : "1586419626 -0700" ,
118- Output : PatchDate {
119- Parsed : expected ,
120- Raw : "1586419626 -0700" ,
121- },
100+ Input : "1586419626 -0700" ,
101+ Output : expected ,
122102 },
123103 "unix" : {
124- Input : "1586419626" ,
125- Output : PatchDate {
126- Parsed : expected ,
127- Raw : "1586419626" ,
128- },
104+ Input : "1586419626" ,
105+ Output : expected ,
129106 },
130107 "unknownFormat" : {
131108 Input : "4/9/2020 01:07:06 PDT" ,
132- Output : PatchDate {
133- Raw : "4/9/2020 01:07:06 PDT" ,
134- },
109+ Err : "unknown date format" ,
135110 },
136111 "empty" : {
137- Input : "" ,
138- Output : PatchDate {},
112+ Input : "" ,
139113 },
140114 }
141115
142116 for name , test := range tests {
143117 t .Run (name , func (t * testing.T ) {
144- d := ParsePatchDate (test .Input )
145- if test .Output .Raw != d .Raw {
146- t .Errorf ("incorrect raw date: expected %q, actual %q" , test .Output .Raw , d .Raw )
118+ d , err := ParsePatchDate (test .Input )
119+ if test .Err != nil {
120+ assertError (t , test .Err , err , "parsing date" )
121+ return
147122 }
148- if ! test .Output .Parsed .Equal (d .Parsed ) {
149- t .Errorf ("incorrect parsed date: expected %v, actual %v" , test .Output .Parsed , d .Parsed )
123+ if err != nil {
124+ t .Fatalf ("unexpected error parsing date: %v" , err )
125+ }
126+ if ! test .Output .Equal (d ) {
127+ t .Errorf ("incorrect parsed date: expected %v, actual %v" , test .Output , d )
150128 }
151129 })
152130 }
@@ -158,10 +136,7 @@ func TestParsePatchHeader(t *testing.T) {
158136 Name : "Morton Haypenny" ,
159137160138 }
161- expectedDate := & PatchDate {
162- Parsed : time .Date (2020 , 04 , 11 , 15 , 21 , 23 , 0 , time .FixedZone ("PDT" , - 7 * 60 * 60 )),
163- Raw : "Sat Apr 11 15:21:23 2020 -0700" ,
164- }
139+ expectedDate := time .Date (2020 , 04 , 11 , 15 , 21 , 23 , 0 , time .FixedZone ("PDT" , - 7 * 60 * 60 ))
165140 expectedTitle := "A sample commit to test header parsing"
166141 expectedBody := "The medium format shows the body, which\n may wrap on to multiple lines.\n \n Another body line."
167142
@@ -258,14 +233,11 @@ may wrap on to multiple lines.
258233Another body line.
259234` ,
260235 Header : PatchHeader {
261- SHA : expectedSHA ,
262- Author : expectedIdentity ,
263- AuthorDate : & PatchDate {
264- Parsed : expectedDate .Parsed ,
265- Raw : "Sat, 11 Apr 2020 15:21:23 -0700" ,
266- },
267- Title : "[PATCH] " + expectedTitle ,
268- Body : expectedBody ,
236+ SHA : expectedSHA ,
237+ Author : expectedIdentity ,
238+ AuthorDate : expectedDate ,
239+ Title : "[PATCH] " + expectedTitle ,
240+ Body : expectedBody ,
269241 },
270242 },
271243 "unwrapTitle" : {
346318 }
347319
348320 assertPatchIdentity (t , "author" , exp .Author , act .Author )
349- assertPatchDate (t , "author" , exp .AuthorDate , act .AuthorDate )
321+ if ! exp .AuthorDate .Equal (act .AuthorDate ) {
322+ t .Errorf ("incorrect parsed author date: expected %v, but got %v" , exp .AuthorDate , act .AuthorDate )
323+ }
350324
351325 assertPatchIdentity (t , "committer" , exp .Committer , act .Committer )
352- assertPatchDate (t , "committer" , exp .CommitterDate , act .CommitterDate )
326+ if ! exp .CommitterDate .Equal (act .CommitterDate ) {
327+ t .Errorf ("incorrect parsed committer date: expected %v, but got %v" , exp .CommitterDate , act .CommitterDate )
328+ }
353329
354330 if exp .Title != act .Title {
355331 t .Errorf ("incorrect parsed title:\n expected: %q\n actual: %q" , exp .Title , act .Title )
@@ -372,15 +348,3 @@ func assertPatchIdentity(t *testing.T, kind string, exp, act *PatchIdentity) {
372348 t .Errorf ("incorrect parsed %s, expected %+v, bot got %+v" , kind , exp , act )
373349 }
374350}
375-
376- func assertPatchDate (t * testing.T , kind string , exp , act * PatchDate ) {
377- switch {
378- case exp == nil && act == nil :
379- case exp == nil && act != nil :
380- t .Errorf ("incorrect parsed %s date: expected nil, but got %+v" , kind , act )
381- case exp != nil && act == nil :
382- t .Errorf ("incorrect parsed %s date: expected %+v, but got nil" , kind , exp )
383- case exp .Raw != act .Raw || ! exp .Parsed .Equal (act .Parsed ):
384- t .Errorf ("incorrect parsed %s date, expected %+v, bot got %+v" , kind , exp , act )
385- }
386- }
0 commit comments