-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filter: flip added, which reverts the line order
- Loading branch information
1 parent
464943a
commit a60ebde
Showing
4 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package subtitles | ||
|
||
// filterFlip reverts the line order of each caption | ||
func (subtitle *Subtitle) filterFlip() *Subtitle { | ||
for i, cap := range subtitle.Captions { | ||
flipped := []string{} | ||
for _, line := range cap.Text { | ||
flipped = append([]string{line}, flipped...) | ||
} | ||
subtitle.Captions[i].Text = flipped | ||
} | ||
return subtitle | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package subtitles | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFilterFlip(t *testing.T) { | ||
in := Subtitle{Captions: []Caption{{ | ||
Seq: 1, | ||
Start: makeTime(0, 0, 4, 630), | ||
End: makeTime(0, 0, 6, 18), | ||
Text: []string{"Line one", "Line two"}, | ||
}}} | ||
expected := Subtitle{[]Caption{{ | ||
1, | ||
makeTime(0, 0, 4, 630), | ||
makeTime(0, 0, 6, 18), | ||
[]string{"Line two", "Line one"}, | ||
}}} | ||
assert.Equal(t, &expected, in.filterFlip()) | ||
} |