forked from rs/vast
-
Notifications
You must be signed in to change notification settings - Fork 2
/
offset_test.go
45 lines (41 loc) · 1.08 KB
/
offset_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
package vast
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestOffsetMarshaler(t *testing.T) {
b, err := (&Offset{}).MarshalText()
if assert.NoError(t, err) {
assert.Equal(t, "0%", string(b))
}
b, err = (&Offset{Percent: .1}).MarshalText()
if assert.NoError(t, err) {
assert.Equal(t, "10%", string(b))
}
d := Duration(0)
b, err = (&Offset{Duration: &d}).MarshalText()
if assert.NoError(t, err) {
assert.Equal(t, "00:00:00", string(b))
}
}
func TestOffsetUnmarshaler(t *testing.T) {
var o Offset
if assert.NoError(t, o.UnmarshalText([]byte("0%"))) {
assert.Nil(t, o.Duration)
assert.Equal(t, float32(0.0), o.Percent)
}
o = Offset{}
if assert.NoError(t, o.UnmarshalText([]byte("10%"))) {
assert.Nil(t, o.Duration)
assert.Equal(t, float32(0.1), o.Percent)
}
o = Offset{}
if assert.NoError(t, o.UnmarshalText([]byte("00:00:00"))) {
if assert.NotNil(t, o.Duration) {
assert.Equal(t, Duration(0), *o.Duration)
}
assert.Equal(t, float32(0), o.Percent)
}
o = Offset{}
assert.EqualError(t, o.UnmarshalText([]byte("abc%")), "invalid offset: abc%")
}