-
Notifications
You must be signed in to change notification settings - Fork 15
/
vtt_test.go
119 lines (104 loc) · 2.14 KB
/
vtt_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package subtitles
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseVTT(t *testing.T) {
txt := "WEBVTT\n" +
"\n" +
"00:00:00.000 --> 00:00:05.560\n" +
"I Vetenskapens värld: ett experiment\n" +
"jag aldrig kommer att glömma.\n" +
"\n" +
"00:00:10.840 --> 00:00:15.760\n" +
"Om en person får kämpa\n" +
"för att hålla sig vaken–\n"
res, err := NewFromVTT(txt)
assert.Equal(t, nil, err)
expected := Subtitle{
[]Caption{{
1,
makeTime(0, 0, 0, 0),
makeTime(0, 0, 5, 560),
[]string{
"I Vetenskapens värld: ett experiment",
"jag aldrig kommer att glömma.",
}}, {
2,
makeTime(0, 0, 10, 840),
makeTime(0, 0, 15, 760),
[]string{
"Om en person får kämpa",
"för att hålla sig vaken–",
}}}}
assert.Equal(t, expected, res)
}
func TestParseVTTWithSequenceNumber(t *testing.T) {
txt := "WEBVTT\n" +
"\n" +
"1\n" +
"00:00:32.140 --> 00:00:33.240\n" +
"Er det slik?\n" +
"\n" +
"2\n" +
"00:00:41.120 --> 00:00:45.100\n" +
"Ja.\n"
res, err := NewFromVTT(txt)
assert.Equal(t, nil, err)
expected := Subtitle{
[]Caption{{
1,
makeTime(0, 0, 32, 140),
makeTime(0, 0, 33, 240),
[]string{
"Er det slik?",
}}, {
2,
makeTime(0, 0, 41, 120),
makeTime(0, 0, 45, 100),
[]string{
"Ja.",
}}}}
assert.Equal(t, expected, res)
}
func TestAsVTT(t *testing.T) {
expected := "WEBVTT\n" +
"\n" +
"00:04.630 --> 00:06.018\n" +
"Go ninja!\n" +
"\n" +
"01:09.630 --> 01:11.005\n" +
"No ninja!\n\n"
assert.Equal(t, true, looksLikeVTT(expected))
in := Subtitle{[]Caption{{
1,
makeTime(0, 0, 4, 630),
makeTime(0, 0, 6, 18),
[]string{"Go ninja!"},
}, {
2,
makeTime(0, 1, 9, 630),
makeTime(0, 1, 11, 005),
[]string{"No ninja!"},
}}}
assert.Equal(t, expected, in.AsVTT())
}
func ExampleNewFromSRT() {
in := "1\n" +
"00:00:04,630 --> 00:00:06,018\n" +
"Go ninja!\n" +
"\n" +
"1\n" +
"00:01:09,630 --> 00:01:11,005\n" +
"No ninja!\n"
res, _ := NewFromSRT(in)
// Output: WEBVTT
//
// 00:04.630 --> 00:06.018
// Go ninja!
//
// 01:09.630 --> 01:11.005
// No ninja!
fmt.Println(res.AsVTT())
}