File: segmentItem_test.go

package info (click to toggle)
golang-github-etherlabsio-go-m3u8 1.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 348 kB
  • sloc: makefile: 3
file content (55 lines) | stat: -rw-r--r-- 1,270 bytes parent folder | download | duplicates (2)
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
package test

import (
	"testing"

	"github.com/AlekSi/pointer"
	"github.com/etherlabsio/go-m3u8/m3u8"
	"github.com/stretchr/testify/assert"
)

func TestSegmentItem_Parse(t *testing.T) {
	time, err := m3u8.ParseTime("2010-02-19T14:54:23Z")
	assert.Nil(t, err)

	item := &m3u8.SegmentItem{
		Duration: 10.991,
		Segment:  "test.ts",
		ProgramDateTime: &m3u8.TimeItem{
			Time: time,
		},
	}

	assert.Equal(t, "#EXTINF:10.991,\n#EXT-X-PROGRAM-DATE-TIME:2010-02-19T14:54:23Z\ntest.ts", item.String())

	item = &m3u8.SegmentItem{
		Duration: 10.991,
		Segment:  "test.ts",
		Comment:  pointer.ToString("anything"),
	}

	assert.Equal(t, "#EXTINF:10.991,anything\ntest.ts", item.String())

	item = &m3u8.SegmentItem{
		Duration: 10.991,
		Segment:  "test.ts",
		Comment:  pointer.ToString("anything"),
		ByteRange: &m3u8.ByteRange{
			Length: pointer.ToInt(4500),
			Start:  pointer.ToInt(600),
		},
	}

	assert.Equal(t, "#EXTINF:10.991,anything\n#EXT-X-BYTERANGE:4500@600\ntest.ts", item.String())

	item = &m3u8.SegmentItem{
		Duration: 10.991,
		Segment:  "test.ts",
		Comment:  pointer.ToString("anything"),
		ByteRange: &m3u8.ByteRange{
			Length: pointer.ToInt(4500),
		},
	}

	assert.Equal(t, "#EXTINF:10.991,anything\n#EXT-X-BYTERANGE:4500\ntest.ts", item.String())
}