LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package time_test | 5 package time_test |
6 | 6 |
7 import ( | 7 import ( |
8 "strconv" | 8 "strconv" |
9 "strings" | 9 "strings" |
10 "testing" | 10 "testing" |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 {"Mon Jan _2 15:04:05.000 2006", "Thu Feb 4 23:00:59x01 2010", "cannot
parse"}, | 380 {"Mon Jan _2 15:04:05.000 2006", "Thu Feb 4 23:00:59x01 2010", "cannot
parse"}, |
381 {"Mon Jan _2 15:04:05.000 2006", "Thu Feb 4 23:00:59.xxx 2010", "cannot
parse"}, | 381 {"Mon Jan _2 15:04:05.000 2006", "Thu Feb 4 23:00:59.xxx 2010", "cannot
parse"}, |
382 {"Mon Jan _2 15:04:05.000 2006", "Thu Feb 4 23:00:59.-123 2010", "fract
ional second out of range"}, | 382 {"Mon Jan _2 15:04:05.000 2006", "Thu Feb 4 23:00:59.-123 2010", "fract
ional second out of range"}, |
383 } | 383 } |
384 | 384 |
385 func TestParseErrors(t *testing.T) { | 385 func TestParseErrors(t *testing.T) { |
386 for _, test := range parseErrorTests { | 386 for _, test := range parseErrorTests { |
387 _, err := Parse(test.format, test.value) | 387 _, err := Parse(test.format, test.value) |
388 if err == nil { | 388 if err == nil { |
389 t.Errorf("expected error for %q %q", test.format, test.v
alue) | 389 t.Errorf("expected error for %q %q", test.format, test.v
alue) |
390 » » } else if strings.Index(err.String(), test.expect) < 0 { | 390 » » } else if strings.Index(err.Error(), test.expect) < 0 { |
391 t.Errorf("expected error with %q for %q %q; got %s", tes
t.expect, test.format, test.value, err) | 391 t.Errorf("expected error with %q for %q %q; got %s", tes
t.expect, test.format, test.value, err) |
392 } | 392 } |
393 } | 393 } |
394 } | 394 } |
395 | 395 |
396 func TestNoonIs12PM(t *testing.T) { | 396 func TestNoonIs12PM(t *testing.T) { |
397 noon := Time{Hour: 12} | 397 noon := Time{Hour: 12} |
398 const expect = "12:00PM" | 398 const expect = "12:00PM" |
399 got := noon.Format("3:04PM") | 399 got := noon.Format("3:04PM") |
400 if got != expect { | 400 if got != expect { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 for i := 0; i < b.N; i++ { | 495 for i := 0; i < b.N; i++ { |
496 time.Format("Mon Jan 2 15:04:05 2006") | 496 time.Format("Mon Jan 2 15:04:05 2006") |
497 } | 497 } |
498 } | 498 } |
499 | 499 |
500 func BenchmarkParse(b *testing.B) { | 500 func BenchmarkParse(b *testing.B) { |
501 for i := 0; i < b.N; i++ { | 501 for i := 0; i < b.N; i++ { |
502 Parse(ANSIC, "Mon Jan 2 15:04:05 2006") | 502 Parse(ANSIC, "Mon Jan 2 15:04:05 2006") |
503 } | 503 } |
504 } | 504 } |
LEFT | RIGHT |