forked from martinlindhe/subtitles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtt_test.go
53 lines (45 loc) · 848 Bytes
/
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
package subtitles
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
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"
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())
}