(t *testing.T)
| 223 | } |
| 224 | } |
| 225 | func TestAppendTimes(t *testing.T) { |
| 226 | doOne := func(multiplier int, format string) { |
| 227 | array := make([]time.Time, 0) |
| 228 | want := append([]byte{}, '[') |
| 229 | want = append(want, ']') |
| 230 | got := enc.AppendTimes([]byte{}, array, format) |
| 231 | if !bytes.Equal(got, want) { |
| 232 | t.Errorf("AppendTimes(%v)\ngot: %s\nwant: %s", |
| 233 | array, |
| 234 | string(got), |
| 235 | string(want)) |
| 236 | } |
| 237 | |
| 238 | array = make([]time.Time, len(internal.TimeIntegerTestcases)) |
| 239 | want = append([]byte{}, '[') |
| 240 | for i, tt := range internal.TimeIntegerTestcases { |
| 241 | if tin, err := time.Parse(time.RFC3339, tt.RfcStr); err != nil { |
| 242 | fmt.Println("Cannot parse input", tt.RfcStr, ".. Skipping!") |
| 243 | continue |
| 244 | } else { |
| 245 | array[i] = tin |
| 246 | } |
| 247 | if multiplier == 0 { |
| 248 | want = append(want, '"') |
| 249 | formatted := array[i].Format(format) |
| 250 | want = append(want, []byte(fmt.Sprintf("%v", formatted))...) |
| 251 | want = append(want, '"') |
| 252 | } else { |
| 253 | scaled := tt.UnixInt * multiplier |
| 254 | want = append(want, []byte(fmt.Sprintf("%d", scaled))...) |
| 255 | } |
| 256 | if i < len(internal.TimeIntegerTestcases)-1 { |
| 257 | want = append(want, ',') |
| 258 | } |
| 259 | } |
| 260 | want = append(want, ']') |
| 261 | |
| 262 | got = enc.AppendTimes([]byte{}, array, format) |
| 263 | if !bytes.Equal(got, want) { |
| 264 | t.Errorf("AppendTimes(%v) %d %s\ngot: %s\nwant: %s", |
| 265 | array, multiplier, format, |
| 266 | string(got), |
| 267 | string(want)) |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | doOne(0, time.RFC3339) |
| 272 | doOne(1, timeFormatUnix) |
| 273 | doOne(1000, timeFormatUnixMs) |
| 274 | doOne(1000000, timeFormatUnixMicro) |
| 275 | doOne(1000000000, timeFormatUnixNano) |
| 276 | } |
| 277 | |
| 278 | func TestAppendDurationFloat(t *testing.T) { |
| 279 | for _, tt := range internal.DurTestcases { |
nothing calls this directly
no test coverage detected