mirror of
				https://github.com/golang/go.git
				synced 2025-10-31 16:50:58 +00:00 
			
		
		
		
	archive/tar: add want field to BenchmarkParsePAXTIme test cases
This commit is contained in:
		
							parent
							
								
									b4dfedb407
								
							
						
					
					
						commit
						106d25e5cf
					
				
					 1 changed files with 41 additions and 7 deletions
				
			
		|  | @ -444,26 +444,60 @@ func BenchmarkParsePAXTIme(b *testing.B) { | ||||||
| 	tests := []struct { | 	tests := []struct { | ||||||
| 		name string | 		name string | ||||||
| 		in   string | 		in   string | ||||||
|  | 		want time.Time | ||||||
| 		ok   bool | 		ok   bool | ||||||
| 	}{ | 	}{ | ||||||
| 		{"NoNanos", "123456", true}, | 		{ | ||||||
| 		{"ExactNanos", "1.123456789", true}, | 			name: "NoNanos", | ||||||
| 		{"WithNanoPadding", "1.123", true}, | 			in:   "123456", | ||||||
| 		{"WithNanoTruncate", "1.123456789123", true}, | 			want: time.Unix(123456, 0), | ||||||
| 		{"TrailingError", "1.123abc", false}, | 			ok:   true, | ||||||
| 		{"LeadingError", "1.abc123", false}, | 		}, | ||||||
|  | 		{ | ||||||
|  | 			name: "ExactNanos", | ||||||
|  | 			in:   "1.123456789", | ||||||
|  | 			want: time.Unix(1, 123456789), | ||||||
|  | 			ok:   true, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			name: "WithNanoPadding", | ||||||
|  | 			in:   "1.123", | ||||||
|  | 			want: time.Unix(1, 123000000), | ||||||
|  | 			ok:   true, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			name: "WithNanoTruncate", | ||||||
|  | 			in:   "1.123456789123", | ||||||
|  | 			want: time.Unix(1, 123456789), | ||||||
|  | 			ok:   true, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			name: "TrailingError", | ||||||
|  | 			in:   "1.123abc", | ||||||
|  | 			want: time.Time{}, | ||||||
|  | 			ok:   false, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			name: "LeadingError", | ||||||
|  | 			in:   "1.abc123", | ||||||
|  | 			want: time.Time{}, | ||||||
|  | 			ok:   false, | ||||||
|  | 		}, | ||||||
| 	} | 	} | ||||||
| 	for _, tt := range tests { | 	for _, tt := range tests { | ||||||
| 		b.Run(tt.name, func(b *testing.B) { | 		b.Run(tt.name, func(b *testing.B) { | ||||||
| 			b.ReportAllocs() | 			b.ReportAllocs() | ||||||
| 			for b.Loop() { | 			for b.Loop() { | ||||||
| 				_, err := parsePAXTime(tt.in) | 				ts, err := parsePAXTime(tt.in) | ||||||
| 				if (err == nil) != tt.ok { | 				if (err == nil) != tt.ok { | ||||||
| 					if err != nil { | 					if err != nil { | ||||||
| 						b.Fatal(err) | 						b.Fatal(err) | ||||||
| 					} | 					} | ||||||
| 					b.Fatal("expected error") | 					b.Fatal("expected error") | ||||||
| 				} | 				} | ||||||
|  | 				if !ts.Equal(tt.want) { | ||||||
|  | 					b.Fatalf("time mismatch: got %v, want %v", ts, tt.want) | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 1911860538
						1911860538