This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
forked from asticode/go-astisub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stl_test.go
98 lines (86 loc) · 3.05 KB
/
stl_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
package astisub_test
import (
"bytes"
"io/ioutil"
"os"
"testing"
"time"
"github.com/asticode/go-astikit"
"github.com/publica-project/go-astisub-p"
"github.com/stretchr/testify/assert"
)
func TestSTL(t *testing.T) {
// Init
creationDate, _ := time.Parse("060102", "170702")
revisionDate, _ := time.Parse("060102", "010101")
// Open
s, err := astisub.OpenFile("./testdata/example-in.stl")
assert.NoError(t, err)
assertSubtitleItems(t, s)
// Metadata
assert.Equal(t, &astisub.Metadata{
Framerate: 25,
Language: astisub.LanguageFrench,
STLCreationDate: &creationDate,
STLMaximumNumberOfDisplayableCharactersInAnyTextRow: astikit.IntPtr(40),
STLMaximumNumberOfDisplayableRows: astikit.IntPtr(23),
STLPublisher: "Copyright test",
STLDisplayStandardCode: "1",
STLRevisionDate: &revisionDate,
STLSubtitleListReferenceCode: "12345678",
STLCountryOfOrigin: "FRA",
Title: "Title test"},
s.Metadata)
// No subtitles to write
w := &bytes.Buffer{}
err = astisub.Subtitles{}.WriteToSTL(w)
assert.EqualError(t, err, astisub.ErrNoSubtitlesToWrite.Error())
// Write
c, err := ioutil.ReadFile("./testdata/example-out.stl")
assert.NoError(t, err)
err = s.WriteToSTL(w)
assert.NoError(t, err)
assert.Equal(t, string(c), w.String())
}
func TestOPNSTL(t *testing.T) {
// Init
creationDate, _ := time.Parse("060102", "200110")
revisionDate, _ := time.Parse("060102", "200110")
// Open
s, err := astisub.OpenFile("./testdata/example-opn-in.stl")
assert.NoError(t, err)
// Metadata
assert.Equal(t, &astisub.Metadata{
Framerate: 25,
Language: astisub.LanguageEnglish,
STLCountryOfOrigin: "NOR",
STLCreationDate: &creationDate,
STLDisplayStandardCode: "0",
STLMaximumNumberOfDisplayableCharactersInAnyTextRow: astikit.IntPtr(38),
STLMaximumNumberOfDisplayableRows: astikit.IntPtr(11),
STLPublisher: "",
STLRevisionDate: &revisionDate,
STLRevisionNumber: 1,
Title: ""},
s.Metadata)
// No subtitles to write
w := &bytes.Buffer{}
err = astisub.Subtitles{}.WriteToSTL(w)
assert.EqualError(t, err, astisub.ErrNoSubtitlesToWrite.Error())
// Write
c, err := ioutil.ReadFile("./testdata/example-opn-out.stl")
assert.NoError(t, err)
err = s.WriteToSTL(w)
assert.NoError(t, err)
assert.Equal(t, string(c), w.String())
}
func TestIgnoreTimecodeStartOfProgramme(t *testing.T) {
opts := astisub.STLOptions{IgnoreTimecodeStartOfProgramme: true}
r, err := os.Open("./testdata/example-in-nonzero-offset.stl")
assert.NoError(t, err)
defer r.Close()
s, err := astisub.ReadFromSTL(r, opts)
assert.NoError(t, err)
firstStart := 99 * time.Second
assert.Equal(t, firstStart, s.Items[0].StartAt, "first start at 0")
}