MCPcopy Create free account
hub / github.com/antonmedv/gitmal / TestParsePatchDate

Function TestParsePatchDate

pkg/gitdiff/patch_header_test.go:8–72  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestParsePatchDate(t *testing.T) {
9 expected := time.Date(2020, 4, 9, 8, 7, 6, 0, time.UTC)
10
11 tests := map[string]struct {
12 Input string
13 Output time.Time
14 Err interface{}
15 }{
16 "default": {
17 Input: "Thu Apr 9 01:07:06 2020 -0700",
18 Output: expected,
19 },
20 "defaultLocal": {
21 Input: "Thu Apr 9 01:07:06 2020",
22 Output: time.Date(2020, 4, 9, 1, 7, 6, 0, time.Local),
23 },
24 "iso": {
25 Input: "2020-04-09 01:07:06 -0700",
26 Output: expected,
27 },
28 "isoStrict": {
29 Input: "2020-04-09T01:07:06-07:00",
30 Output: expected,
31 },
32 "rfc": {
33 Input: "Thu, 9 Apr 2020 01:07:06 -0700",
34 Output: expected,
35 },
36 "short": {
37 Input: "2020-04-09",
38 Output: time.Date(2020, 4, 9, 0, 0, 0, 0, time.Local),
39 },
40 "raw": {
41 Input: "1586419626 -0700",
42 Output: expected,
43 },
44 "unix": {
45 Input: "1586419626",
46 Output: expected,
47 },
48 "unknownFormat": {
49 Input: "4/9/2020 01:07:06 PDT",
50 Err: "unknown date format",
51 },
52 "empty": {
53 Input: "",
54 },
55 }
56
57 for name, test := range tests {
58 t.Run(name, func(t *testing.T) {
59 d, err := ParsePatchDate(test.Input)
60 if test.Err != nil {
61 assertError(t, test.Err, err, "parsing date")
62 return
63 }
64 if err != nil {
65 t.Fatalf("unexpected error parsing date: %v", err)

Callers

nothing calls this directly

Calls 3

ParsePatchDateFunction · 0.85
assertErrorFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected