forked from asticode/go-astisub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
srt_test.go
48 lines (40 loc) · 1.1 KB
/
srt_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
package astisub_test
import (
"bytes"
"io/ioutil"
"testing"
"github.com/asticode/go-astisub"
"github.com/stretchr/testify/assert"
)
func TestSRT(t *testing.T) {
// Open
s, err := astisub.OpenFile("./testdata/example-in.srt")
assert.NoError(t, err)
assertSubtitleItems(t, s)
// No subtitles to write
w := &bytes.Buffer{}
err = astisub.Subtitles{}.WriteToSRT(w)
assert.EqualError(t, err, astisub.ErrNoSubtitlesToWrite.Error())
// Write
c, err := ioutil.ReadFile("./testdata/example-out.srt")
assert.NoError(t, err)
err = s.WriteToSRT(w)
assert.NoError(t, err)
assert.Equal(t, string(c), w.String())
}
func TestSRTMissingSequence(t *testing.T) {
// Open
s, err := astisub.OpenFile("./testdata/missing-sequence-in.srt")
assert.NoError(t, err)
assertSubtitleItems(t, s)
// No subtitles to write
w := &bytes.Buffer{}
err = astisub.Subtitles{}.WriteToSRT(w)
assert.EqualError(t, err, astisub.ErrNoSubtitlesToWrite.Error())
// Write
c, err := ioutil.ReadFile("./testdata/example-out.srt")
assert.NoError(t, err)
err = s.WriteToSRT(w)
assert.NoError(t, err)
assert.Equal(t, string(c), w.String())
}