Add test suite.
[srt2vtt.git] / tests / subrip.scm
1 ;;; srt2vtt --- SRT to WebVTT converter
2 ;;; Copyright © 2015 David Thompson <davet@gnu.org>
3 ;;;
4 ;;; srt2vtt is free software; you can redistribute it and/or modify it
5 ;;; under the terms of the GNU General Public License as published by
6 ;;; the Free Software Foundation; either version 3 of the License, or
7 ;;; (at your option) any later version.
8 ;;;
9 ;;; srt2vtt is distributed in the hope that it will be useful, but
10 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 ;;; General Public License for more details.
13 ;;;
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with srt2vtt.  If not, see <http://www.gnu.org/licenses/>.
16
17 (define-module (tests subrip)
18   #:use-module (srfi srfi-64)
19   #:use-module (tests utils)
20   #:use-module (srt2vtt)
21   #:use-module (srt2vtt subrip))
22
23 (test-begin "subrip")
24
25 (test-group "read-subrip"
26   (define (read-subrip-string str)
27     (call-with-input-string str read-subrip))
28
29   (test-equal (make-subtitle 1
30                              '(1 2 3 4)
31                              '(5 6 7 8)
32                              '("foo" "bar" "baz"))
33     (read-subrip-string
34      "1
35 01:02:03,004 --> 05:06:07,008
36 foo
37 bar
38 baz
39 "))
40
41   ;; Blank subtitle text
42   (test-equal (make-subtitle 1
43                              '(1 2 3 4)
44                              '(5 6 7 8)
45                              '(""))
46     (read-subrip-string
47      "1
48 01:02:03,004 --> 05:06:07,008
49
50 ")))
51
52 (test-equal "read-subrips"
53   (list (make-subtitle 1
54                        '(1 2 3 4)
55                        '(5 6 7 8)
56                        '("foo"))
57         (make-subtitle 2
58                        '(9 10 11 12)
59                        '(13 14 15 16)
60                        '("bar" "baz")))
61   (call-with-input-string "1
62 01:02:03,004 --> 05:06:07,008
63 foo
64
65 2
66 09:10:11,012 --> 13:14:15,016
67 bar
68 baz
69 "
70     read-subrips))
71
72 (test-end "subrip")
73
74 (test-exit)