youtube_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package processor // import "miniflux.app/v2/internal/reader/processor"
  4. import (
  5. "testing"
  6. "time"
  7. )
  8. func TestParseISO8601(t *testing.T) {
  9. var scenarios = []struct {
  10. duration string
  11. expected time.Duration
  12. }{
  13. // Live streams and radio.
  14. {"PT0M0S", 0},
  15. // https://www.youtube.com/watch?v=HLrqNhgdiC0
  16. {"PT6M20S", (6 * time.Minute) + (20 * time.Second)},
  17. // https://www.youtube.com/watch?v=LZa5KKfqHtA
  18. {"PT5M41S", (5 * time.Minute) + (41 * time.Second)},
  19. // https://www.youtube.com/watch?v=yIxEEgEuhT4
  20. {"PT51M52S", (51 * time.Minute) + (52 * time.Second)},
  21. // https://www.youtube.com/watch?v=bpHf1XcoiFs
  22. {"PT80M42S", (1 * time.Hour) + (20 * time.Minute) + (42 * time.Second)},
  23. }
  24. for _, tc := range scenarios {
  25. result, err := parseISO8601(tc.duration)
  26. if err != nil {
  27. t.Errorf("Got an error when parsing %q: %v", tc.duration, err)
  28. }
  29. if tc.expected != result {
  30. t.Errorf(`Unexpected result, got %v for duration %q`, result, tc.duration)
  31. }
  32. }
  33. }