get_durations_test.go
764 bytes
1package youtube
2
3import (
4 "testing"
5 "time"
6)
7
8func TestParseISO8601Duration(t *testing.T) {
9 tests := []struct {
10 input string
11 expected time.Duration
12 }{
13 {"P0D", 0},
14 {"PT5M", 5 * time.Minute},
15 {"PT1H30M", 90 * time.Minute},
16 {"PT3M42S", 3*time.Minute + 42*time.Second},
17 {"P1DT5H3M42S", 29*time.Hour + 3*time.Minute + 42*time.Second},
18 {"P2DT0S", 48 * time.Hour},
19 {"P1D", 24 * time.Hour},
20 {"PT0S", 0},
21 }
22
23 for _, tt := range tests {
24 t.Run(tt.input, func(t *testing.T) {
25 got, err := parseISO8601Duration(tt.input)
26 if err != nil {
27 t.Fatalf("parseISO8601Duration(%q) returned error: %v", tt.input, err)
28 }
29 if got != tt.expected {
30 t.Errorf("parseISO8601Duration(%q) = %v, want %v", tt.input, got, tt.expected)
31 }
32 })
33 }
34}