Skip to content

Commit

Permalink
google#4306 - extends test case with line and position anchor verific…
Browse files Browse the repository at this point in the history
…ations
  • Loading branch information
szaboa committed Oct 1, 2018
1 parent fc5eb12 commit 75a7385
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private String processLine(String currentLine, ArrayList<String> tags) {
// Extract tags
int replacedCharacters = 0;
StringBuilder processedLine = new StringBuilder(trimmedLine);
Matcher matcher = SUBRIP_TAG_PATTERN.matcher(processedLine);
Matcher matcher = SUBRIP_TAG_PATTERN.matcher(trimmedLine);

while (matcher.find()) {
String tag = matcher.group();
Expand Down
36 changes: 36 additions & 0 deletions library/core/src/test/assets/subrip/typical_with_tags
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,39 @@ This { \an2} is the fourth subtitle.
5
00:00:013,567 --> 00:00:14,901
This {\an2} is the fifth subtitle with multiple {\xyz} valid {\qwe} tags.

6
00:00:015,567 --> 00:00:15,901
This {\an1} is a lines.

7
00:00:016,567 --> 00:00:16,901
This {\an2} is a line.

8
00:00:017,567 --> 00:00:17,901
This {\an3} is a line.

9
00:00:018,567 --> 00:00:18,901
This {\an4} is a line.

10
00:00:019,567 --> 00:00:19,901
This {\an5} is a line.

11
00:00:020,567 --> 00:00:20,901
This {\an6} is a line.

12
00:00:021,567 --> 00:00:22,901
This {\an7} is a line.

13
00:00:023,567 --> 00:00:23,901
This {\an8} is a line.

14
00:00:024,567 --> 00:00:24,901
This {\an9} is a line.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import static com.google.common.truth.Truth.assertThat;

import com.google.android.exoplayer2.testutil.TestUtil;
import com.google.android.exoplayer2.text.Cue;

import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -174,6 +176,71 @@ public void testDecodeCueWithTag() throws IOException{

assertThat(subtitle.getCues(subtitle.getEventTime(8)).get(0).text.toString())
.isEqualTo("This is the fifth subtitle with multiple valid tags.");

// Verify positions

// {/an1}
assertThat(subtitle.getCues(subtitle.getEventTime(10)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_START);

assertThat(subtitle.getCues(subtitle.getEventTime(10)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_END);

// {/an2}
assertThat(subtitle.getCues(subtitle.getEventTime(12)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);

assertThat(subtitle.getCues(subtitle.getEventTime(12)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_END);

// {/an3}
assertThat(subtitle.getCues(subtitle.getEventTime(14)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_END);

assertThat(subtitle.getCues(subtitle.getEventTime(14)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_END);

// {/an4}
assertThat(subtitle.getCues(subtitle.getEventTime(16)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_START);

assertThat(subtitle.getCues(subtitle.getEventTime(16)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);

// {/an5}
assertThat(subtitle.getCues(subtitle.getEventTime(18)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);

assertThat(subtitle.getCues(subtitle.getEventTime(18)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);

// {/an6}
assertThat(subtitle.getCues(subtitle.getEventTime(20)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_END);

assertThat(subtitle.getCues(subtitle.getEventTime(20)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);

// {/an7}
assertThat(subtitle.getCues(subtitle.getEventTime(22)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_START);

assertThat(subtitle.getCues(subtitle.getEventTime(22)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_START);

// {/an8}
assertThat(subtitle.getCues(subtitle.getEventTime(24)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_MIDDLE);

assertThat(subtitle.getCues(subtitle.getEventTime(24)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_START);

// {/an9}
assertThat(subtitle.getCues(subtitle.getEventTime(26)).get(0).positionAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_END);

assertThat(subtitle.getCues(subtitle.getEventTime(26)).get(0).lineAnchor)
.isEqualTo(Cue.ANCHOR_TYPE_START);
}

private static void assertTypicalCue1(SubripSubtitle subtitle, int eventIndex) {
Expand Down

0 comments on commit 75a7385

Please sign in to comment.