mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
* utils: vtt: add tests In lieu of documentation. * utils: vtt: rewrite for correctness and simplicity Now handles fractional seconds and negative values correctly.
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
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)
|
|
}
|
|
}
|