forked from martinlindhe/subtitles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssa_test.go
43 lines (37 loc) · 1.23 KB
/
ssa_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package subtitles
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewFromSsa(t *testing.T) {
in := "[Events]\n" +
"Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text\n" +
"Dialogue: 0,0:01:06.37,0:01:08.04,Default,,0000,0000,0000,,Honey, I'm home!\n" +
"Dialogue: 0,0:01:09.05,0:01:10.69,Default,,0000,0000,0000,,Hi.\\n- Hi, love.\n"
expected := Subtitle{[]Caption{{
1,
makeTime(0, 1, 6, 370),
makeTime(0, 1, 8, 40),
[]string{"Honey, I'm home!"},
}, {
2,
makeTime(0, 1, 9, 50),
makeTime(0, 1, 10, 690),
[]string{"Hi.", "- Hi, love."},
}}}
res, err := NewFromSSA(in)
assert.Equal(t, nil, err)
assert.Equal(t, expected, res)
}
func TestParseSsaFormat(t *testing.T) {
assert.Equal(t, -1, parseSsaFormat("xxx", "some"))
assert.Equal(t, 9, parseSsaFormat("Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text", "Text"))
}
func TestParseSsaTime(t *testing.T) {
t1, _ := parseSsaTime("0:01:06.37")
assert.Equal(t, makeTime(0, 1, 6, 370), t1)
}
func TestColumnCountFromSsaFormat(t *testing.T) {
columns := columnCountFromSsaFormat("Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text")
assert.Equal(t, 10, columns)
}