Skip to content

Commit

Permalink
1. Fixed Test cases
Browse files Browse the repository at this point in the history
2. Fixed SRT and STL strings join
  • Loading branch information
discovery-avishekgulshan committed Jun 10, 2021
1 parent badeecd commit d20efc5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion stl.go
Expand Up @@ -673,7 +673,7 @@ func stlVerticalPositionFromStyle(sa *StyleAttributes) int {
}

func (li LineItem) STLString() string {
rs := li.Text
rs := strings.TrimSpace(li.Text)
if li.InlineStyle != nil {
if li.InlineStyle.STLItalics != nil && *li.InlineStyle.STLItalics {
rs = string(rune(0x80)) + rs + string(rune(0x81))
Expand Down
4 changes: 3 additions & 1 deletion subtitles.go
Expand Up @@ -339,7 +339,9 @@ func (l Line) String() string {
for _, i := range l.Items {
texts = append(texts, i.Text)
}
return strings.Join(texts, " ")
t := strings.Join(texts, " ")
t = strings.ReplaceAll(t, " ", " ")
return t
}

// LineItem represents a formatted line item
Expand Down
8 changes: 4 additions & 4 deletions ttml_test.go
Expand Up @@ -19,9 +19,9 @@ func TestTTML(t *testing.T) {
assert.Equal(t, &astisub.Metadata{Framerate: 25, Language: astisub.LanguageFrench, Title: "Title test", TTMLCopyright: "Copyright test"}, s.Metadata)
// Styles
assert.Equal(t, 3, len(s.Styles))
assert.Equal(t, astisub.Style{ID: "style_0", InlineStyle: &astisub.StyleAttributes{TTMLColor: util.StringToPointer("white"), TTMLExtent: util.StringToPointer("100% 10%"), TTMLFontFamily: util.StringToPointer("sansSerif"), TTMLFontStyle: util.StringToPointer("normal"), TTMLOrigin: util.StringToPointer("0% 90%"), TTMLTextAlign: util.StringToPointer("center")}, Style: s.Styles["style_2"]}, *s.Styles["style_0"])
assert.Equal(t, astisub.Style{ID: "style_1", InlineStyle: &astisub.StyleAttributes{TTMLColor: util.StringToPointer("white"), TTMLExtent: util.StringToPointer("100% 13%"), TTMLFontFamily: util.StringToPointer("sansSerif"), TTMLFontStyle: util.StringToPointer("normal"), TTMLOrigin: util.StringToPointer("0% 87%"), TTMLTextAlign: util.StringToPointer("center")}}, *s.Styles["style_1"])
assert.Equal(t, astisub.Style{ID: "style_2", InlineStyle: &astisub.StyleAttributes{TTMLColor: util.StringToPointer("white"), TTMLExtent: util.StringToPointer("100% 20%"), TTMLFontFamily: util.StringToPointer("sansSerif"), TTMLFontStyle: util.StringToPointer("normal"), TTMLOrigin: util.StringToPointer("0% 80%"), TTMLTextAlign: util.StringToPointer("center")}}, *s.Styles["style_2"])
assert.Equal(t, astisub.Style{ID: "style_0", InlineStyle: &astisub.StyleAttributes{TTMLColor: util.StringToPointer("white"), TTMLExtent: util.StringToPointer("100% 10%"), TTMLFontFamily: util.StringToPointer("sansSerif"), TTMLFontStyle: util.StringToPointer("normal"), TTMLOrigin: util.StringToPointer("0% 90%"), TTMLTextAlign: util.StringToPointer("center"), WebVTTAlign: "center"}, Style: s.Styles["style_2"]}, *s.Styles["style_0"])
assert.Equal(t, astisub.Style{ID: "style_1", InlineStyle: &astisub.StyleAttributes{TTMLColor: util.StringToPointer("white"), TTMLExtent: util.StringToPointer("100% 13%"), TTMLFontFamily: util.StringToPointer("sansSerif"), TTMLFontStyle: util.StringToPointer("normal"), TTMLOrigin: util.StringToPointer("0% 87%"), TTMLTextAlign: util.StringToPointer("center"), WebVTTAlign: "center"}}, *s.Styles["style_1"])
assert.Equal(t, astisub.Style{ID: "style_2", InlineStyle: &astisub.StyleAttributes{TTMLColor: util.StringToPointer("white"), TTMLExtent: util.StringToPointer("100% 20%"), TTMLFontFamily: util.StringToPointer("sansSerif"), TTMLFontStyle: util.StringToPointer("normal"), TTMLOrigin: util.StringToPointer("0% 80%"), TTMLTextAlign: util.StringToPointer("center"), WebVTTAlign: "center"}}, *s.Styles["style_2"])
// Regions
assert.Equal(t, 3, len(s.Regions))
assert.Equal(t, astisub.Region{ID: "region_0", Style: s.Styles["style_0"], InlineStyle: &astisub.StyleAttributes{TTMLColor: util.StringToPointer("blue")}}, *s.Regions["region_0"])
Expand All @@ -32,7 +32,7 @@ func TestTTML(t *testing.T) {
assert.Equal(t, s.Styles["style_1"], s.Items[0].Style)
assert.Equal(t, &astisub.StyleAttributes{TTMLColor: util.StringToPointer("red")}, s.Items[0].InlineStyle)
assert.Equal(t, []astisub.Line{{Items: []astisub.LineItem{{Style: s.Styles["style_1"], InlineStyle: &astisub.StyleAttributes{TTMLColor: util.StringToPointer("black")}, Text: "(deep rumbling)"}}}}, s.Items[0].Lines)
assert.Equal(t, []astisub.Line{{Items: []astisub.LineItem{{InlineStyle: &astisub.StyleAttributes{}, Text: "MAN:"}}}, {Items: []astisub.LineItem{{InlineStyle: &astisub.StyleAttributes{}, Text: "How did we"}, {InlineStyle: &astisub.StyleAttributes{TTMLColor: util.StringToPointer("green")}, Style: s.Styles["style_1"], Text: "end up"}, {InlineStyle: &astisub.StyleAttributes{}, Text: "here?"}}}}, s.Items[1].Lines)
assert.Equal(t, []astisub.Line{{Items: []astisub.LineItem{{InlineStyle: &astisub.StyleAttributes{}, Text: "MAN:"}}}, {Items: []astisub.LineItem{{InlineStyle: &astisub.StyleAttributes{}, Text: "How did we "}, {InlineStyle: &astisub.StyleAttributes{TTMLColor: util.StringToPointer("green")}, Style: s.Styles["style_1"], Text: "end up "}, {InlineStyle: &astisub.StyleAttributes{}, Text: "here?"}}}}, s.Items[1].Lines)
assert.Equal(t, []astisub.Line{{Items: []astisub.LineItem{{InlineStyle: &astisub.StyleAttributes{}, Style: s.Styles["style_1"], Text: "This place is horrible."}}}}, s.Items[2].Lines)
assert.Equal(t, []astisub.Line{{Items: []astisub.LineItem{{InlineStyle: &astisub.StyleAttributes{}, Style: s.Styles["style_1"], Text: "Smells like balls."}}}}, s.Items[3].Lines)
assert.Equal(t, []astisub.Line{{Items: []astisub.LineItem{{InlineStyle: &astisub.StyleAttributes{}, Style: s.Styles["style_2"], Text: "We don't belong"}}}, {Items: []astisub.LineItem{{InlineStyle: &astisub.StyleAttributes{}, Style: s.Styles["style_1"], Text: "in this shithole."}}}}, s.Items[4].Lines)
Expand Down

0 comments on commit d20efc5

Please sign in to comment.