From 292c7c5454b464e5e31771b880ab7dab2e30ec2c Mon Sep 17 00:00:00 2001 From: Nhan Nguyen Date: Mon, 13 Nov 2023 07:46:23 +0700 Subject: [PATCH] [webvtt/test] Testcase for webvtt tags --- webvtt_internal_test.go | 20 +++++++++---------- webvtt_test.go | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/webvtt_internal_test.go b/webvtt_internal_test.go index adf44df..ce97faa 100644 --- a/webvtt_internal_test.go +++ b/webvtt_internal_test.go @@ -96,39 +96,39 @@ func TestCueVoiceSpanRegex(t *testing.T) { }{ { give: ` this is the content`, - want: ` 中文`, + want: `中文`, }, { give: ` this is the content`, - want: ` 中文`, + want: `中文`, }, { give: ` this is the content`, - want: ` 中文`, + want: `中文`, }, { give: ` this is the content`, - want: ` 言語の`, + want: `言語の`, }, { give: ` this is the content`, - want: ` 언어`, + want: `언어`, }, { give: ` this is the content`, - want: ` foo bar`, + want: `foo bar`, }, { give: ` 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]) }) } } diff --git a/webvtt_test.go b/webvtt_test.go index 9e5b5d3..f6db966 100644 --- a/webvtt_test.go +++ b/webvtt_test.go @@ -162,3 +162,46 @@ Sentence with an & in the middle Sentence with an < in the middle `, b.String()) } + +func TestWebVTTTags(t *testing.T) { + testData := `WEBVTT + + 00:01:00.000 --> 00:02:00.000 + Italic with underline text some extra + + 00:02:00.000 --> 00:03:00.000 + English here Yellow text on blue background + + 00:03:00.000 --> 00:04:00.000 + Joe's words are red in italic + + 00:04:00.000 --> 00:05:00.000 + Text here` + + 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 +Italic with underline text some extra + +2 +00:02:00.000 --> 00:03:00.000 +English here Yellow text on blue background + +3 +00:03:00.000 --> 00:04:00.000 +Joe's words are red in italic + +4 +00:04:00.000 --> 00:05:00.000 +Text here +`, b.String()) +}