File tree 6 files changed +112
-19
lines changed
6 files changed +112
-19
lines changed Original file line number Diff line number Diff line change 5
5
go fmt ./...
6
6
7
7
test :
8
- go test ./cast -v
8
+ go test ./... -v
Original file line number Diff line number Diff line change
1
+ package editor
2
+
3
+ import (
4
+ "github.com/cirocosta/asciinema-edit/cast"
5
+ "github.com/pkg/errors"
6
+ )
7
+
8
+ // Cut removes a piece of the cast event stream as specified by
9
+ // `from` and `to`.
10
+ //
11
+ // It assumes that the provided `cast` is entirely valid (see
12
+ // `github.com/cirocosta/asciinema-edit/cast#Validate`).
13
+ //
14
+ // 1. search a time that is close to `from`; then
15
+ // 2. search a time that is close to `to`; then
16
+ // 3. remove all in between; then
17
+ // 4. adjust the time of the remaining.
18
+ func Cut (c * cast.Cast , from , to float64 ) (err error ) {
19
+ if c == nil {
20
+ err = errors .Errorf ("a cast must be specified" )
21
+ return
22
+ }
23
+
24
+ if len (c .EventStream ) == 0 {
25
+ err = errors .Errorf (
26
+ "a cast with non-empty event stream must be supplied" )
27
+ return
28
+ }
29
+
30
+ if from > to {
31
+ err = errors .Errorf (
32
+ "`from` cant be bigger than `to`" )
33
+ return
34
+ }
35
+
36
+ return
37
+ }
Original file line number Diff line number Diff line change
1
+ package editor_test
2
+
3
+ import (
4
+ . "github.com/onsi/ginkgo"
5
+ . "github.com/onsi/gomega"
6
+
7
+ "github.com/cirocosta/asciinema-edit/cast"
8
+ "github.com/cirocosta/asciinema-edit/editor"
9
+ )
10
+
11
+ var (
12
+ event1 = & cast.Event {
13
+ Time : 1 ,
14
+ Data : "event1" ,
15
+ }
16
+ event1_2 = & cast.Event {
17
+ Time : 1.2 ,
18
+ Data : "event1_2" ,
19
+ }
20
+ event1_6 = & cast.Event {
21
+ Time : 1.6 ,
22
+ Data : "event1_6" ,
23
+ }
24
+ event2 = & cast.Event {
25
+ Time : 2 ,
26
+ Data : "event2" ,
27
+ }
28
+ )
29
+
30
+ var _ = Describe ("Cut" , func () {
31
+ Context ("with nil cast" , func () {
32
+ It ("fails" , func () {
33
+ err := editor .Cut (nil , 1 , 2 )
34
+ Expect (err ).ToNot (Succeed ())
35
+ })
36
+ })
37
+
38
+ Context ("with an empty event stream" , func () {
39
+ var data = & cast.Cast {
40
+ EventStream : []* cast.Event {},
41
+ }
42
+
43
+ It ("errors" , func () {
44
+ err := editor .Cut (data , 1 , 2 )
45
+ Expect (err ).ToNot (Succeed ())
46
+ })
47
+ })
48
+
49
+ Context ("with non-empty event stream" , func () {
50
+ var (
51
+ err error
52
+ data * cast.Cast
53
+ )
54
+
55
+ BeforeEach (func () {
56
+ data = & cast.Cast {
57
+ EventStream : []* cast.Event {
58
+ event1 ,
59
+ event1_2 ,
60
+ event1_6 ,
61
+ event2 ,
62
+ },
63
+ }
64
+ })
65
+
66
+ It ("fails if `from` > `to`" , func () {
67
+ err = editor .Cut (data , 3 , 2 )
68
+ Expect (err ).ToNot (Succeed ())
69
+ })
70
+ })
71
+ })
Original file line number Diff line number Diff line change
1
+ // Package editor provides a set of functions to transform and
2
+ // deal with the post production of asciinema casts.
3
+ package editor
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments