Skip to content

Commit

Permalink
[webvtt/test] Testcase for webvtt tags
Browse files Browse the repository at this point in the history
  • Loading branch information
NhanNguyen700 committed Nov 13, 2023
1 parent 99cfd59 commit 292c7c5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
20 changes: 10 additions & 10 deletions webvtt_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,39 +96,39 @@ func TestCueVoiceSpanRegex(t *testing.T) {
}{
{
give: `<v 中文> this is the content</v>`,
want: ` 中文`,
want: `中文`,
},
{
give: `<v 中文> this is the content`,
want: ` 中文`,
want: `中文`,
},
{
give: `<v.abc 中文> this is the content</v>`,
want: ` 中文`,
want: `中文`,
},
{
give: `<v.jp 言語の> this is the content`,
want: ` 言語の`,
want: `言語の`,
},
{
give: `<v.ko 언어> this is the content`,
want: ` 언어`,
want: `언어`,
},
{
give: `<v foo bar> this is the content`,
want: ` foo bar`,
want: `foo bar`,
},
{
give: `<v هذا عربي> this is the content`,
want: ` هذا عربي`,
want: `هذا عربي`,
},
}

for _, tt := range tests {
t.Run(tt.want, func(t *testing.T) {
results := webVTTRegexpStartTag.FindStringSubmatch(tt.give)
assert.True(t, len(results) == 4)
assert.Equal(t, tt.want, results[3])
results := webVTTRegexpTag.FindStringSubmatch(tt.give)
assert.True(t, len(results) == 5)
assert.Equal(t, tt.want, results[4])
})
}
}
43 changes: 43 additions & 0 deletions webvtt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,46 @@ Sentence with an &amp; in the middle
Sentence with an &lt; in the middle
`, b.String())
}

func TestWebVTTTags(t *testing.T) {
testData := `WEBVTT
00:01:00.000 --> 00:02:00.000
<u><i>Italic with underline text</i></u> some extra
00:02:00.000 --> 00:03:00.000
<lang en>English here</lang> <c.yellow.bg_blue>Yellow text on blue background</c>
00:03:00.000 --> 00:04:00.000
<v Joe><c.red><i>Joe's words are red in italic</i></c>
00:04:00.000 --> 00:05:00.000
<customed_tag.class1.class2>Text here</customed_tag>`

s, err := astisub.ReadFromWebVTT(strings.NewReader(testData))
require.NoError(t, err)

require.Len(t, s.Items, 4)

b := &bytes.Buffer{}
err = s.WriteToWebVTT(b)
require.NoError(t, err)
require.Equal(t, `WEBVTT
1
00:01:00.000 --> 00:02:00.000
<u><i>Italic with underline text</i></u> some extra
2
00:02:00.000 --> 00:03:00.000
<lang en>English here</lang> <c.yellow.bg_blue>Yellow text on blue background</c>
3
00:03:00.000 --> 00:04:00.000
<v Joe><c.red><i>Joe's words are red in italic</i></c>
4
00:04:00.000 --> 00:05:00.000
<customed_tag.class1.class2>Text here</customed_tag>
`, b.String())
}

0 comments on commit 292c7c5

Please sign in to comment.