mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
utils: vtt: test + rewrite (#1284)
* utils: vtt: add tests In lieu of documentation. * utils: vtt: rewrite for correctness and simplicity Now handles fractional seconds and negative values correctly.
This commit is contained in:
42
pkg/utils/vtt_test.go
Normal file
42
pkg/utils/vtt_test.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestZeroTimestamp(t *testing.T) {
|
||||
if want, got := "00:00:00.000", GetVTTTime(0); want != got {
|
||||
t.Errorf("TestZeroTimestamp: GetVTTTime(0) = %v; want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidTimestamp(t *testing.T) {
|
||||
s := 0.1
|
||||
if want, got := "00:00:00.100", GetVTTTime(s); want != got {
|
||||
t.Errorf("TestValidTimestamp: GetVTTTime(%v) = %v; want %v", s, got, want)
|
||||
}
|
||||
s = ((24+1)*60+1)*60 + 1 + 0.1
|
||||
if want, got := "25:01:01.100", GetVTTTime(s); want != got {
|
||||
t.Errorf("TestValidTimestamp: GetVTTTime(%v) = %v; want %v", s, got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// Negative timestamps are not defined by WebVTT.
|
||||
func TestNegativeTimestamp(t *testing.T) {
|
||||
if want, got := "00:00:00.000", GetVTTTime(-1); want != got {
|
||||
t.Errorf("TestNegativeTimestamp: GetVTTTime(-1) = %v; want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidTimestamp(t *testing.T) {
|
||||
if want, got := "00:00:00.000", GetVTTTime(math.NaN()); want != got {
|
||||
t.Errorf("TestInvalidTimestamp: GetVTTTime(NaN) = %v; want %v", got, want)
|
||||
}
|
||||
if want, got := "00:00:00.000", GetVTTTime(math.Inf(1)); want != got {
|
||||
t.Errorf("TestInvalidTimestamp: GetVTTTime(Inf) = %v; want %v", got, want)
|
||||
}
|
||||
if want, got := "00:00:00.000", GetVTTTime(math.Inf(-1)); want != got {
|
||||
t.Errorf("TestInvalidTimestamp: GetVTTTime(-Inf) = %v; want %v", got, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user