forked from golang/build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_test.go
58 lines (52 loc) · 1.32 KB
/
git_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package maintner
import (
"reflect"
"testing"
"time"
)
func TestParsePerson(t *testing.T) {
var c Corpus
p, ct, err := c.parsePerson([]byte(" Foo Bar <[email protected]> 1257894000 -0800"))
if err != nil {
t.Fatal(err)
}
wantp := &GitPerson{Str: "Foo Bar <[email protected]>"}
if !reflect.DeepEqual(p, wantp) {
t.Errorf("person = %+v; want %+v", p, wantp)
}
wantct := time.Unix(1257894000, 0)
if !ct.Equal(wantct) {
t.Errorf("commit time = %v; want %v", ct, wantct)
}
zoneName, off := ct.Zone()
if want := "-0800"; zoneName != want {
t.Errorf("zone name = %q; want %q", zoneName, want)
}
if want := -28800; off != want {
t.Errorf("offset = %v; want %v", off, want)
}
p2, ct2, err := c.parsePerson([]byte("Foo Bar <[email protected]> 1257894001 -0800"))
if err != nil {
t.Fatal(err)
}
if p != p2 {
t.Errorf("gitPerson pointer values differ; not sharing memory")
}
if !ct2.Equal(ct.Add(time.Second)) {
t.Errorf("wrong time")
}
}
func BenchmarkParsePerson(b *testing.B) {
b.ReportAllocs()
in := []byte(" Foo Bar <[email protected]> 1257894000 -0800")
var c Corpus
for i := 0; i < b.N; i++ {
_, _, err := c.parsePerson(in)
if err != nil {
b.Fatal(err)
}
}
}