Reject exactly negative transcript timestamps
This commit is contained in:
@@ -111,6 +111,38 @@ func TestParseAcceptsNumericSegmentIDs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseTimestampPrecisionAndSign(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name, start, end string
|
||||
wantError bool
|
||||
}{
|
||||
{"tiny negative start", "-1e-1000", "0", true},
|
||||
{"tiny negative end", "0", "-1e-1000", true},
|
||||
{"tiny positive", "1e-1000", "2e-1000", false},
|
||||
{"negative zero", "-0", "0", false},
|
||||
{"ordinary", "1.25", "2.5", false},
|
||||
{"precise reversed", "2e-1000", "1e-1000", true},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
raw := validJSONWithSegment(`"id":1,"start":` + tt.start + `,"end":` + tt.end + `,"speaker":"Narrator","text":"Text"`)
|
||||
doc, err := New().Parse(context.Background(), contracts.ParseRequest{Raw: raw})
|
||||
if (err != nil) != tt.wantError {
|
||||
t.Fatalf("Parse() error = %v, want error %t", err, tt.wantError)
|
||||
}
|
||||
if strings.HasPrefix(tt.name, "tiny negative") && !strings.Contains(err.Error(), "negative") {
|
||||
t.Fatalf("Parse() error = %v, want negative timestamp error", err)
|
||||
}
|
||||
if err == nil {
|
||||
start, _ := Start(doc.Units[0])
|
||||
end, _ := End(doc.Units[0])
|
||||
if start != json.Number(tt.start) || end != json.Number(tt.end) {
|
||||
t.Fatalf("timestamps = %q, %q, want %q, %q", start, end, tt.start, tt.end)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRequestSourceIDOverridesMetadataIDs(t *testing.T) {
|
||||
raw := readFixture(t, "testdata/valid_minimal.json")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user