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