github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/video/subtitle/srt/subrip_test.go (about)

     1  // Copyright 2014 <chaishushan{AT}gmail.com>. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package srt
     6  
     7  import (
     8  	"reflect"
     9  	"testing"
    10  )
    11  
    12  func TestSubtitle(t *testing.T) {
    13  	for i := 0; i < len(testSubtitleSuits); i++ {
    14  		golden := testSubtitleSuits[i].subtitles
    15  		s, err := ParseData([]byte(testSubtitleSuits[i].text))
    16  		if err != nil {
    17  			t.Fatalf("%d: parse failed, err = %v", i, err)
    18  		}
    19  		if !reflect.DeepEqual(s, golden) {
    20  			t.Fatalf("%d: expected = %q,\ngot = %q", i, golden, s)
    21  		}
    22  	}
    23  }
    24  
    25  var testSubtitleSuits = []struct {
    26  	text      string
    27  	subtitles []Subtitle
    28  }{
    29  	{
    30  		text: `
    31  1
    32  00:00:10,500 --> 00:00:13,000
    33  Elephant's Dream
    34  
    35  2
    36  00:00:15,000 --> 00:00:18,000
    37  At the left we can see...
    38  `,
    39  		subtitles: []Subtitle{
    40  			{
    41  				Number:    1,
    42  				Position:  [4]int{},
    43  				StartTime: makeDuration(0, 0, 10, 500),
    44  				EndTime:   makeDuration(0, 0, 13, 0),
    45  				Texts:     []string{`Elephant's Dream`},
    46  			},
    47  			{
    48  				Number:    2,
    49  				Position:  [4]int{},
    50  				StartTime: makeDuration(0, 0, 15, 0),
    51  				EndTime:   makeDuration(0, 0, 18, 0),
    52  				Texts:     []string{`At the left we can see...`},
    53  			},
    54  		},
    55  	},
    56  
    57  	{
    58  		text: `
    59  1
    60  00:00:10,500 --> 00:00:13,000 X1:63 X2:223 Y1:43 Y2:58
    61  <i>Elephant's Dream</i>
    62  
    63  2
    64  00:00:15,000 --> 00:00:18,000 X1:53 X2:303 Y1:438 Y2:453
    65  <font color="cyan">At the left we can see...</font>
    66  `,
    67  		subtitles: []Subtitle{
    68  			{
    69  				Number:    1,
    70  				Position:  [4]int{63, 223, 43, 58},
    71  				StartTime: makeDuration(0, 0, 10, 500),
    72  				EndTime:   makeDuration(0, 0, 13, 0),
    73  				Texts:     []string{`<i>Elephant's Dream</i>`},
    74  			},
    75  			{
    76  				Number:    2,
    77  				Position:  [4]int{53, 303, 438, 453},
    78  				StartTime: makeDuration(0, 0, 15, 0),
    79  				EndTime:   makeDuration(0, 0, 18, 0),
    80  				Texts:     []string{`<font color="cyan">At the left we can see...</font>`},
    81  			},
    82  		},
    83  	},
    84  
    85  	{
    86  		text: `
    87  1
    88  00:00:16,240 --> 00:00:18,020
    89  你干什么
    90  Hey, what are you doing?
    91  
    92  2
    93  00:00:22,140 --> 00:00:23,380
    94  天哪
    95  Jesus!
    96  
    97  3
    98  00:00:23,730 --> 00:00:24,560
    99  你看清肇事的车了吗
   100  Did you get a good look?
   101  `,
   102  		subtitles: []Subtitle{
   103  			{
   104  				Number:    1,
   105  				Position:  [4]int{},
   106  				StartTime: makeDuration(0, 0, 16, 240),
   107  				EndTime:   makeDuration(0, 0, 18, 20),
   108  				Texts:     []string{`你干什么`, `Hey, what are you doing?`},
   109  			},
   110  			{
   111  				Number:    2,
   112  				Position:  [4]int{},
   113  				StartTime: makeDuration(0, 0, 22, 140),
   114  				EndTime:   makeDuration(0, 0, 23, 380),
   115  				Texts:     []string{`天哪`, `Jesus!`},
   116  			},
   117  			{
   118  				Number:    3,
   119  				Position:  [4]int{},
   120  				StartTime: makeDuration(0, 0, 23, 730),
   121  				EndTime:   makeDuration(0, 0, 24, 560),
   122  				Texts:     []string{`你看清肇事的车了吗`, `Did you get a good look?`},
   123  			},
   124  		},
   125  	},
   126  }