branch: elpa/subed commit 50a47179ee764890409f471d8a8e9ce49a3e9dae Author: Random User <rnd...@posteo.de> Commit: Random User <rnd...@posteo.de>
Fix tests --- tests/test-subed-common.el | 266 ++++++++++++++++++++++++++++----------------- tests/test-subed-srt.el | 266 +++++++++++++++++++++++---------------------- 2 files changed, 303 insertions(+), 229 deletions(-) diff --git a/tests/test-subed-common.el b/tests/test-subed-common.el index 2b37bde..442348a 100644 --- a/tests/test-subed-common.el +++ b/tests/test-subed-common.el @@ -3,9 +3,32 @@ (require 'subed) (require 'subed-srt) +(defvar mock-srt-data + "1 +00:01:01,000 --> 00:01:05,123 +Foo. + +2 +00:02:02,234 --> 00:02:10,345 +Bar. + +3 +00:03:03,45 --> 00:03:15,5 +Baz. +") + +(defmacro with-temp-srt-buffer (&rest body) + "Call `subed-srt--init' in temporary buffer before running BODY." + (declare (indent defun)) + `(with-temp-buffer + ;; subed--init uses file extension to detect format + (setq buffer-file-name "test.srt") + (subed--init) + (progn ,@body))) + (describe "Iterating over subtitles" (it "without providing beginning and end." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-time-stop 1) (subed-for-each-subtitle nil nil nil @@ -39,7 +62,7 @@ (expect (point) :to-equal 99))) (describe "providing only the beginning" (it "forwards." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-time-start 1) (expect (point) :to-equal 3) @@ -54,7 +77,7 @@ (expect (subed-subtitle-text 3) :to-equal "B") (expect (point) :to-equal 3))) (it "backwards." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-time-stop 3) (expect (point) :to-equal 95) @@ -72,7 +95,7 @@ (describe "providing beginning and end," (describe "excluding subtitles above" (it "forwards." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-time-stop 1) (expect (point) :to-equal 20) @@ -87,7 +110,7 @@ (expect (subed-subtitle-text 3) :to-equal "B") (expect (point) :to-equal 20))) (it "backwards." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-time-start 3) (expect (point) :to-equal 79) @@ -104,7 +127,7 @@ ) (describe "excluding subtitles below" (it "forwards." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-text 3) (expect (point) :to-equal 106) @@ -119,7 +142,7 @@ (expect (subed-subtitle-text 3) :to-equal "Baz.") (expect (point) :to-equal 100))) (it "backwards." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-time-stop 2) (expect (point) :to-equal 58) @@ -143,7 +166,7 @@ (let ((foo (setf (symbol-function 'foo) (lambda (msecs) ())))) (spy-on 'foo) (add-hook 'subed-subtitle-time-adjusted-hook 'foo) - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-id 1) (expect (subed-adjust-subtitle-time-start 100) :to-equal 100) @@ -161,7 +184,7 @@ (expect 'foo :to-have-been-called-times 4)) (remove-hook 'subed-subtitle-time-adjusted-hook 'foo))) (it "adjusts the start/stop time." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-id 1) (expect (subed-adjust-subtitle-time-start 100) :to-equal 100) @@ -179,7 +202,7 @@ (describe "enforces limits" (describe "when decreasing start time" (it "of the first subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n")) @@ -190,7 +213,7 @@ (expect (subed-adjust-subtitle-time-start -1) :to-be nil) (expect (subed-subtitle-msecs-start) :to-be 0))) (it "of a non-first subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -206,7 +229,7 @@ (expect (subed-subtitle-msecs-start) :to-be 2100))) ) (it "when increasing start time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -222,7 +245,7 @@ (expect (subed-adjust-subtitle-time-start 1) :to-be nil) (expect (subed-subtitle-msecs-start) :to-be 4000))) (it "when decreasing stop time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -238,7 +261,7 @@ (expect (subed-subtitle-msecs-stop) :to-be 3000))) (describe "when increasing stop time" (it "of the last subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -249,7 +272,7 @@ (expect (subed-adjust-subtitle-time-stop 1000000):to-be 1000000) (expect (subed-subtitle-msecs-stop) :to-be 1004000))) (it "of a non-last subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -265,7 +288,7 @@ (expect (subed-subtitle-msecs-stop) :to-be 2900))) ) (it "without undershooting the target time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -276,7 +299,7 @@ (expect (subed-adjust-subtitle-time-stop 1) :to-be nil) (expect (subed-subtitle-msecs-stop) :to-equal 2000))) (it "without overshooting the target time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -289,7 +312,7 @@ ) (describe "ignores negative duration if the first argument is truthy" (it "when adjusting start time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n")) @@ -300,7 +323,7 @@ (expect (subed-subtitle-msecs-start) :to-be 2500) (expect (subed-subtitle-msecs-stop) :to-be 2000))) (it "when adjusting stop time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n")) @@ -313,7 +336,7 @@ ) (describe "ignores subtitle spacing if the second argument is truthy" (it "when adjusting start time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -328,7 +351,7 @@ (expect (subed-subtitle-msecs-start 2) :to-be 1999) (expect (subed-subtitle-msecs-stop 1) :to-be 2000))) (it "when adjusting stop time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -344,7 +367,7 @@ (expect (subed-subtitle-msecs-start 2) :to-be 2200))) ) (it "does nothing if no timestamp can be found." - (with-temp-buffer + (with-temp-srt-buffer (insert "foo") (goto-char (point-min)) (expect (subed-adjust-subtitle-time-start 123) :to-be nil) @@ -356,13 +379,13 @@ (describe "Copy start/stop time from player" :var (subed-mpv-playback-position) (it "does nothing in an empty buffer." - (with-temp-buffer + (with-temp-srt-buffer (let ((subed-mpv-playback-position 12345)) (expect (subed-copy-player-pos-to-start-time) :to-be nil) (expect (subed-copy-player-pos-to-stop-time) :to-be nil) (expect (buffer-string) :to-equal "")))) (it "does nothing if player position is unknown." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n")) @@ -373,7 +396,7 @@ "00:00:01,000 --> 00:00:02,000\n" "Foo.\n"))))) (it "sets start/stop time when possible." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n")) @@ -388,7 +411,7 @@ "00:01:02,123 --> 00:01:05,456\n" "Foo.\n"))))) (it "runs the appropriate hook." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n")) @@ -414,7 +437,7 @@ (describe "Moving" (it "adjusts start and stop time by the same amount." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n")) @@ -427,7 +450,7 @@ (expect (subed-subtitle-msecs-stop) :to-equal 1900) (expect (point) :to-equal orig-point)))) (it "adjusts start and stop time by the same amount when bumping into next subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:01,600\n" "Foo.\n\n" @@ -440,7 +463,7 @@ (expect (subed-subtitle-msecs-stop) :to-equal 1900) (expect (point) :to-equal orig-point)))) (it "adjusts start and stop time by the same amount when bumping into previous subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:01,600\n" "Foo.\n\n" @@ -453,7 +476,7 @@ (expect (subed-subtitle-msecs-stop) :to-equal 2700) (expect (point) :to-equal orig-point)))) (it "does not adjust anything if subtitle cannot be moved forward at all." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -468,7 +491,7 @@ (expect (subed-subtitle-msecs-stop 2) :to-equal 3000) (expect (point) :to-equal orig-point)))) (it "does not adjust anything if subtitle cannot be moved backward at all." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -484,7 +507,7 @@ (expect (point) :to-equal orig-point)))) (describe "adjusts subtitles in the active region," (it "excluding the first subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -515,7 +538,7 @@ (expect (subed-subtitle-msecs-stop 3) :to-equal 5900) (expect (point) :to-equal orig-point)))) (it "excluding the last subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -547,7 +570,7 @@ (expect (point) :to-equal orig-point)))) (describe "not changing spacing between subtitles" (it "when moving forward." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -570,7 +593,7 @@ (expect (subed-subtitle-msecs-stop 3) :to-equal 13000) (expect (point) :to-equal orig-point)))) (it "when moving backward." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -596,7 +619,7 @@ ) (describe "unless there is no space left" (it "when moving forward." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -619,7 +642,7 @@ (expect (subed-subtitle-msecs-stop 3) :to-equal 12000) (expect (point) :to-equal orig-point)))) (it "when moving backward." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -644,7 +667,7 @@ ) (describe "ignoring spacing for non-leading subtitles" (it "when moving forward." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:00,000 --> 00:00:01,000\n" "Foo.\n\n" @@ -667,7 +690,7 @@ (expect (subed-subtitle-msecs-stop 3) :to-equal 6000) (expect (point) :to-equal orig-point)))) (it "when moving backward." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -692,7 +715,7 @@ ) (describe "ignoring overlapping subtitles" (it "when moving forward." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:01,500\n" "Foo.\n\n" @@ -715,7 +738,7 @@ (expect (subed-subtitle-msecs-stop 3) :to-equal 6000) (expect (point) :to-equal orig-point)))) (it "when moving backward." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -739,7 +762,7 @@ (expect (point) :to-equal orig-point)))) ) (it "ignoring start time being larger than stop time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,500 --> 00:00:01,400\n" "Foo.\n\n" @@ -770,7 +793,7 @@ (expect (subed-subtitle-msecs-stop 3) :to-equal 6000) (expect (point) :to-equal orig-point)))) (it "ignoring stop time being smaller than start time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -801,7 +824,7 @@ (expect (subed-subtitle-msecs-stop 3) :to-equal 5500) (expect (point) :to-equal orig-point)))) (it "disables subtitle replay while moving subtitles." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-enable-replay-adjusted-subtitle :quiet) (spy-on 'subed-enable-replay-adjusted-subtitle :and-call-through) @@ -817,7 +840,7 @@ (expect 'subed-disable-replay-adjusted-subtitle :to-have-been-called-times 2) (expect 'subed-enable-replay-adjusted-subtitle :to-have-been-called-times 2))) (it "does not enable subtitle replay afterwards if it is disabled." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-disable-replay-adjusted-subtitle :quiet) (spy-on 'subed-enable-replay-adjusted-subtitle :and-call-through) @@ -833,7 +856,7 @@ (expect 'subed-disable-replay-adjusted-subtitle :to-have-been-called-times 2) (expect 'subed-enable-replay-adjusted-subtitle :to-have-been-called-times 0))) (it "seeks player to current subtitle if region is not active." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (spy-on 'subed-replay-adjusted-subtitle-p :and-return-value t) (spy-on 'subed-mpv-jump) @@ -844,7 +867,7 @@ (expect 'subed-mpv-jump :to-have-been-called-times 2) (expect 'subed-mpv-jump :to-have-been-called-with 183350))) (it "seeks player to first subtitle in active region." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (let ((beg 15) (end (point-max))) @@ -862,13 +885,12 @@ ) (describe "Inserting evenly spaced" - (before-each - (spy-on 'subed-regenerate-ids-soon)) (describe "in an empty buffer," (describe "appending" (it "a single subtile." (cl-loop for arg in (list nil 1) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (expect (subed-insert-subtitle arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" @@ -878,7 +900,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtiles." (cl-loop for arg in (list 2) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (expect (subed-insert-subtitle arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" @@ -893,7 +916,8 @@ (describe "prepending" (it "a single subtile." (cl-loop for arg in (list '- -1 (list 4)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (expect (subed-insert-subtitle arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" @@ -903,7 +927,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtiles." (cl-loop for arg in (list -2 (list -16)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (expect (subed-insert-subtitle arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" @@ -920,7 +945,8 @@ (describe "prepending between subtitles" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -943,7 +969,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -971,7 +998,8 @@ (describe "appending between subtitles" (it "a single subtitle." (cl-loop for arg in (list nil 1) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -994,7 +1022,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list 2) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1022,7 +1051,8 @@ (describe "prepending to the first subtitle" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:01:00,000 --> 00:01:01,000\n" "Foo.\n")) @@ -1039,7 +1069,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:01:00,000 --> 00:01:01,000\n" "Foo.\n")) @@ -1061,7 +1092,8 @@ (describe "appending to the last subtitle" (it "a single subtitle." (cl-loop for arg in (list nil 1) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n")) @@ -1078,7 +1110,7 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list 2) do - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n")) @@ -1099,7 +1131,8 @@ (describe "to append" (it "a single subtitle." (cl-loop for arg in (list nil 1) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1122,7 +1155,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list 2) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1151,7 +1185,8 @@ (describe "between subtitles" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:57,000 --> 00:00:59,100\n" "Foo.\n\n" @@ -1174,7 +1209,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:57,000 --> 00:00:59,100\n" "Foo.\n\n" @@ -1202,7 +1238,8 @@ (describe "before the first subtitle" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:00,500 --> 00:00:02,000\n" "Foo.\n")) @@ -1219,7 +1256,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:00,600 --> 00:00:01,500\n" "Foo.\n")) @@ -1245,7 +1283,8 @@ (describe "when prepending" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:55,000 --> 00:00:59,950\n" "Foo.\n\n" @@ -1268,7 +1307,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:57,000 --> 00:00:59,999\n" "Foo.\n\n" @@ -1296,7 +1336,8 @@ (describe "when appending" (it "a single subtitle." (cl-loop for arg in (list nil 1) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1319,7 +1360,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list 2) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1348,7 +1390,8 @@ (describe "before the first subtitle" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:00,050 --> 00:00:02,000\n" "Foo.\n")) @@ -1365,7 +1408,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:00,100 --> 00:00:01,500\n" "Foo.\n")) @@ -1389,13 +1433,12 @@ ) (describe "Inserting adjacent" - (before-each - (spy-on 'subed-regenerate-ids-soon)) (describe "in an empty buffer," (describe "appending" (it "a single subtile." (cl-loop for arg in (list nil 1) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (expect (subed-insert-subtitle-adjacent arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" @@ -1405,7 +1448,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtiles." (cl-loop for arg in (list 2) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (expect (subed-insert-subtitle-adjacent arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" @@ -1420,7 +1464,8 @@ (describe "prepending" (it "a single subtile." (cl-loop for arg in (list '- -1 (list 4)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (expect (subed-insert-subtitle-adjacent arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" @@ -1430,7 +1475,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtiles." (cl-loop for arg in (list -2 (list -16)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (expect (subed-insert-subtitle-adjacent arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" @@ -1447,7 +1493,8 @@ (describe "prepending between subtitles" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1470,7 +1517,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1498,7 +1546,8 @@ (describe "appending between subtitles" (it "a single subtitle." (cl-loop for arg in (list nil 1) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1521,7 +1570,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list 2) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1549,7 +1599,8 @@ (describe "prepending to the first subtitle" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:01:00,000 --> 00:01:01,000\n" "Foo.\n")) @@ -1566,7 +1617,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:01:00,000 --> 00:01:01,000\n" "Foo.\n")) @@ -1588,7 +1640,8 @@ (describe "appending to the last subtitle" (it "a single subtitle." (cl-loop for arg in (list nil 1) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n")) @@ -1605,7 +1658,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list 2) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n")) @@ -1628,7 +1682,8 @@ (describe "to append" (it "a single subtitle." (cl-loop for arg in (list nil 1) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1651,7 +1706,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list 2) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1680,7 +1736,8 @@ (describe "between subtitles" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1703,7 +1760,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1731,7 +1789,8 @@ (describe "before the first subtitle" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n")) @@ -1748,7 +1807,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:00,800 --> 00:00:03,000\n" "Foo.\n")) @@ -1774,7 +1834,8 @@ (describe "when prepending" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1797,7 +1858,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1825,7 +1887,8 @@ (describe "when appending" (it "a single subtitle." (cl-loop for arg in (list nil 1) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1848,7 +1911,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list 2) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" @@ -1877,7 +1941,8 @@ (describe "before the first subtitle" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:00,040 --> 00:00:05,000\n" "Foo.\n")) @@ -1894,7 +1959,8 @@ (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do - (with-temp-buffer + (with-temp-srt-buffer + (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:00,024 --> 00:00:05,000\n" "Foo.\n")) @@ -1932,10 +1998,12 @@ (subed--sync-player-to-point) (expect 'subed-mpv-jump :not :to-have-been-called)) (it "seeks player if point is on future subtitle." + (subed-srt--init) (setq subed-mpv-playback-position 6501) (subed--sync-player-to-point) (expect 'subed-mpv-jump :to-have-been-called-with 5000)) (it "seeks player if point is on past subtitle." + (subed-srt--init) (setq subed-mpv-playback-position 4999) (subed--sync-player-to-point) (expect 'subed-mpv-jump :to-have-been-called-with 5000)) diff --git a/tests/test-subed-srt.el b/tests/test-subed-srt.el index b7bf262..b8640bc 100644 --- a/tests/test-subed-srt.el +++ b/tests/test-subed-srt.el @@ -16,20 +16,26 @@ Bar. Baz. ") +(defmacro with-temp-srt-buffer (&rest body) + "Call `subed-srt--init' in temporary buffer before running BODY." + `(with-temp-buffer + (subed-srt--init) + (progn ,@body))) + (describe "Getting" (describe "the subtitle ID" (it "returns the subtitle ID if it can be found." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (expect (subed-srt--subtitle-id) :to-equal 2))) (it "returns nil if no subtitle ID can be found." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--subtitle-id) :to-equal nil))) ) (describe "the subtitle ID at playback time" (it "returns subtitle ID if time is equal to start time." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (cl-loop for target-id from 1 to 3 do (let ((msecs (subed-srt--subtitle-msecs-start target-id))) @@ -38,7 +44,7 @@ Baz. (subed-srt--jump-to-subtitle-id outset-id) (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal target-id))))))) (it "returns subtitle ID if time is equal to stop time." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (cl-loop for target-id from 1 to 3 do (let ((msecs (subed-srt--subtitle-msecs-stop target-id))) @@ -47,7 +53,7 @@ Baz. (subed-srt--jump-to-subtitle-id outset-id) (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal target-id))))))) (it "returns subtitle ID if time is between start and stop time." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (cl-loop for target-id from 1 to 3 do (let ((msecs (+ 1 (subed-srt--subtitle-msecs-start target-id)))) @@ -56,7 +62,7 @@ Baz. (subed-srt--jump-to-subtitle-id outset-id) (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal target-id))))))) (it "returns first subtitle ID if time is before the first subtitle's start time." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (let ((msecs (- (save-excursion (goto-char (point-min)) @@ -66,7 +72,7 @@ Baz. (subed-srt--jump-to-subtitle-id outset-id) (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal 1)))))) (it "returns last subtitle ID if time is after the last subtitle's start time." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (let ((msecs (+ (save-excursion (goto-char (point-max)) @@ -76,7 +82,7 @@ Baz. (subed-srt--jump-to-subtitle-id outset-id) (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal 3)))))) (it "returns previous subtitle ID when time is between subtitles." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (cl-loop for target-id from 1 to 2 do (let ((msecs (+ (subed-srt--subtitle-msecs-stop target-id) 1))) @@ -90,7 +96,7 @@ Baz. (subed-srt--jump-to-subtitle-id outset-id) (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal target-id))))))) (it "doesn't fail when start time is invalid." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 2) (let ((msecs (- (subed-srt--subtitle-msecs-start) 1))) @@ -100,13 +106,13 @@ Baz. ) (describe "the subtitle start/stop time" (it "returns the time in milliseconds." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (expect (subed-srt--subtitle-msecs-start) :to-equal (+ (* 2 60000) (* 2 1000) 234)) (expect (subed-srt--subtitle-msecs-stop) :to-equal (+ (* 2 60000) (* 10 1000) 345)))) (it "handles lack of digits in milliseconds gracefully." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-id 3) (expect (save-excursion (subed-jump-to-subtitle-time-start) @@ -114,38 +120,38 @@ Baz. (expect (subed-srt--subtitle-msecs-start) :to-equal (+ (* 3 60 1000) (* 3 1000) 450)) (expect (subed-srt--subtitle-msecs-stop) :to-equal (+ (* 3 60 1000) (* 15 1000) 500)))) (it "returns nil if time can't be found." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--subtitle-msecs-start) :to-be nil) (expect (subed-srt--subtitle-msecs-stop) :to-be nil))) ) (describe "the subtitle text" (describe "when text is empty" (it "and at the beginning with a trailing newline." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (kill-line) (expect (subed-srt--subtitle-text) :to-equal ""))) (it "and at the beginning without a trailing newline." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (kill-whole-line) (expect (subed-srt--subtitle-text) :to-equal ""))) (it "and in the middle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (kill-line) (expect (subed-srt--subtitle-text) :to-equal ""))) (it "and at the end with a trailing newline." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 3) (kill-line) (expect (subed-srt--subtitle-text) :to-equal ""))) (it "and at the end without a trailing newline." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 3) (kill-whole-line) @@ -153,12 +159,12 @@ Baz. ) (describe "when text is not empty" (it "and has no linebreaks." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (expect (subed-srt--subtitle-text) :to-equal "Bar."))) (it "and has linebreaks." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (insert "Bar.\n") @@ -167,7 +173,7 @@ Baz. ) (describe "the point within the subtitle" (it "returns the relative point if we can find an ID." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 2) (expect (subed-srt--subtitle-relative-point) :to-equal 0) @@ -182,7 +188,7 @@ Baz. (forward-line) (expect (subed-srt--subtitle-relative-point) :to-equal 0))) (it "returns nil if we can't find an ID." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 1) (insert "foo") @@ -193,28 +199,28 @@ Baz. (describe "Jumping" (describe "to current subtitle ID" (it "returns ID's point when point is already on the ID." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (expect (thing-at-point 'word) :to-equal "1") (expect (subed-srt--jump-to-subtitle-id) :to-equal 1) (expect (thing-at-point 'word) :to-equal "1"))) (it "returns ID's point when point is on the duration." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (search-backward ",234") (expect (thing-at-point 'word) :to-equal "02") (expect (subed-srt--jump-to-subtitle-id) :to-equal 39) (expect (thing-at-point 'word) :to-equal "2"))) (it "returns ID's point when point is on the text." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (search-backward "Baz.") (expect (thing-at-point 'word) :to-equal "Baz") (expect (subed-srt--jump-to-subtitle-id) :to-equal 77) (expect (thing-at-point 'word) :to-equal "3"))) (it "returns ID's point when point is between subtitles." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (search-forward "Bar.\n") @@ -222,18 +228,18 @@ Baz. (expect (subed-srt--jump-to-subtitle-id) :to-equal 39) (expect (thing-at-point 'word) :to-equal "2"))) (it "returns nil if buffer is empty." - (with-temp-buffer + (with-temp-srt-buffer (expect (buffer-string) :to-equal "") (expect (subed-srt--jump-to-subtitle-id) :to-equal nil))) (it "returns ID's point when buffer starts with blank lines." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat " \n \t \n" mock-srt-data)) (search-backward "Foo.") (expect (thing-at-point 'line) :to-equal "Foo.\n") (expect (subed-srt--jump-to-subtitle-id) :to-equal 7) (expect (thing-at-point 'word) :to-equal "1"))) (it "returns ID's point when subtitles are separated with blank lines." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (search-forward "Foo.\n") @@ -243,7 +249,7 @@ Baz. ) (describe "to specific subtitle ID" (it "returns ID's point if wanted ID exists." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-max)) (expect (subed-srt--jump-to-subtitle-id 2) :to-equal 39) @@ -253,7 +259,7 @@ Baz. (expect (subed-srt--jump-to-subtitle-id 3) :to-equal 77) (expect (thing-at-point 'word) :to-equal "3"))) (it "returns nil and does not move if wanted ID does not exists." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (search-forward "Foo") @@ -263,7 +269,7 @@ Baz. ) (describe "to subtitle ID at specific time" (it "returns ID's point if point changed." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-max)) (spy-on 'subed-srt--subtitle-id-at-msecs :and-return-value (point-min)) @@ -272,7 +278,7 @@ Baz. (expect 'subed-srt--subtitle-id-at-msecs :to-have-been-called-with 123450) (expect 'subed-srt--subtitle-id-at-msecs :to-have-been-called-times 1))) (it "returns nil if point didn't change." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char 75) (spy-on 'subed-srt--subtitle-id-at-msecs :and-return-value 75) @@ -283,7 +289,7 @@ Baz. ) (describe "to subtitle start time" (it "returns start time's point if movement was successful." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (expect (subed-srt--jump-to-subtitle-time-start) :to-equal 3) @@ -298,12 +304,12 @@ Baz. (expect (looking-at subed-srt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:03:03,45"))) (it "returns nil if movement failed." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--jump-to-subtitle-time-start) :to-equal nil))) ) (describe "to subtitle stop time" (it "returns stop time's point if movement was successful." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (expect (subed-srt--jump-to-subtitle-time-stop) :to-equal 20) @@ -318,12 +324,12 @@ Baz. (expect (looking-at subed-srt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:03:15,5"))) (it "returns nil if movement failed." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--jump-to-subtitle-time-stop) :to-equal nil))) ) (describe "to subtitle text" (it "returns subtitle text's point if movement was successful." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (expect (subed-srt--jump-to-subtitle-text) :to-equal 33) @@ -335,12 +341,12 @@ Baz. (expect (subed-srt--jump-to-subtitle-text) :to-equal 106) (expect (point) :to-equal (save-excursion (goto-char (point-max)) (search-backward "Baz."))))) (it "returns nil if movement failed." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--jump-to-subtitle-time-stop) :to-equal nil))) ) (describe "to end of subtitle text" (it "returns point if subtitle end can be found." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (expect (subed-srt--jump-to-subtitle-end) :to-be 37) @@ -356,16 +362,16 @@ Baz. (expect (subed-srt--jump-to-subtitle-end) :to-be 110) (expect (looking-back "^Baz.$") :to-be t))) (it "returns nil if subtitle end cannot be found." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--jump-to-subtitle-end) :to-be nil))) (it "returns nil if point did not move." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (kill-line) (expect (subed-srt--jump-to-subtitle-end) :to-be nil))) (it "works if text is empty with trailing newline." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (kill-line) @@ -383,7 +389,7 @@ Baz. (expect (subed-srt--jump-to-subtitle-end) :to-be 98) (expect (looking-at "^$") :to-be t))) (it "works if text is empty without trailing newline." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (kill-whole-line) @@ -409,7 +415,7 @@ Baz. ) (describe "to next subtitle ID" (it "returns point when there is a next subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 1) (expect (thing-at-point 'word) :to-equal "1") @@ -420,10 +426,10 @@ Baz. (expect (subed-srt--forward-subtitle-id) :to-be 77) (expect (thing-at-point 'word) :to-equal "3"))) (it "returns nil and doesn't move when there is no next subtitle." - (with-temp-buffer + (with-temp-srt-buffer (expect (thing-at-point 'word) :to-equal nil) (expect (subed-srt--forward-subtitle-id) :to-be nil)) - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (expect (thing-at-point 'word) :to-equal "Foo") @@ -433,13 +439,13 @@ Baz. (expect (thing-at-point 'word) :to-equal "00") (expect (subed-srt--forward-subtitle-id) :to-be 77) (expect (thing-at-point 'word) :to-equal "3")) - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 3) (expect (thing-at-point 'word) :to-equal "Baz") (expect (subed-srt--forward-subtitle-id) :to-be nil) (expect (thing-at-point 'word) :to-equal "Baz")) - (with-temp-buffer + (with-temp-srt-buffer (insert (concat mock-srt-data "\n\n")) (subed-srt--jump-to-subtitle-time-stop 3) (expect (thing-at-point 'word) :to-equal "00") @@ -448,7 +454,7 @@ Baz. ) (describe "to previous subtitle ID" (it "returns point when there is a previous subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (expect (thing-at-point 'word) :to-equal "Bar") @@ -459,21 +465,21 @@ Baz. (expect (subed-srt--backward-subtitle-id) :to-be 39) (expect (thing-at-point 'word) :to-equal "2"))) (it "returns nil and doesn't move when there is no previous subtitle." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--backward-subtitle-id) :to-be nil)) - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 1) (expect (thing-at-point 'word) :to-equal "1") (expect (subed-srt--backward-subtitle-id) :to-be nil) (expect (thing-at-point 'word) :to-equal "1")) - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (expect (thing-at-point 'word) :to-equal "Foo") (expect (subed-srt--backward-subtitle-id) :to-be nil) (expect (thing-at-point 'word) :to-equal "Foo")) - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "\n\n\n" mock-srt-data)) (subed-srt--jump-to-subtitle-time-stop 1) (expect (thing-at-point 'word) :to-equal "00") @@ -482,14 +488,14 @@ Baz. ) (describe "to next subtitle text" (it "returns point when there is a next subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 1) (expect (thing-at-point 'word) :to-equal "1") (expect (subed-srt--forward-subtitle-text) :to-be 71) (expect (thing-at-point 'word) :to-equal "Bar"))) (it "returns nil and doesn't move when there is no next subtitle." - (with-temp-buffer + (with-temp-srt-buffer (goto-char (point-max)) (insert (concat mock-srt-data "\n\n")) (subed-srt--jump-to-subtitle-id 3) @@ -499,14 +505,14 @@ Baz. ) (describe "to previous subtitle text" (it "returns point when there is a previous subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 3) (expect (thing-at-point 'word) :to-equal "3") (expect (subed-srt--backward-subtitle-text) :to-be 71) (expect (thing-at-point 'word) :to-equal "Bar"))) (it "returns nil and doesn't move when there is no previous subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (expect (thing-at-point 'word) :to-equal "1") @@ -515,14 +521,14 @@ Baz. ) (describe "to next subtitle end" (it "returns point when there is a next subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (expect (thing-at-point 'word) :to-equal "Bar") (expect (subed-srt--forward-subtitle-end) :to-be 110) (expect (thing-at-point 'word) :to-equal nil))) (it "returns nil and doesn't move when there is no next subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat mock-srt-data "\n\n")) (subed-srt--jump-to-subtitle-text 3) (end-of-line) @@ -532,14 +538,14 @@ Baz. ) (describe "to previous subtitle end" (it "returns point when there is a previous subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 3) (expect (thing-at-point 'word) :to-equal "3") (expect (subed-srt--backward-subtitle-text) :to-be 71) (expect (thing-at-point 'word) :to-equal "Bar"))) (it "returns nil and doesn't move when there is no previous subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (expect (thing-at-point 'word) :to-equal "1") @@ -548,14 +554,14 @@ Baz. ) (describe "to next subtitle start time" (it "returns point when there is a next subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (expect (thing-at-point 'word) :to-equal "Foo") (expect (subed-srt--forward-subtitle-time-start) :to-be 41) (expect (thing-at-point 'word) :to-equal "00"))) (it "returns nil and doesn't move when there is no next subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 3) (expect (thing-at-point 'word) :to-equal "3") @@ -564,14 +570,14 @@ Baz. ) (describe "to previous subtitle start time" (it "returns point when there is a previous subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 2) (expect (thing-at-point 'word) :to-equal "2") (expect (subed-srt--backward-subtitle-time-start) :to-be 3) (expect (thing-at-point 'word) :to-equal "00"))) (it "returns nil and doesn't move when there is no previous subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 1) (expect (thing-at-point 'word) :to-equal "1") @@ -580,14 +586,14 @@ Baz. ) (describe "to next subtitle stop time" (it "returns point when there is a next subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (expect (thing-at-point 'word) :to-equal "Foo") (expect (subed-srt--forward-subtitle-time-stop) :to-be 58) (expect (thing-at-point 'word) :to-equal "00"))) (it "returns nil and doesn't move when there is no next subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 3) (expect (thing-at-point 'word) :to-equal "3") @@ -596,14 +602,14 @@ Baz. ) (describe "to previous subtitle stop time" (it "returns point when there is a previous subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 3) (expect (thing-at-point 'word) :to-equal "3") (expect (subed-srt--backward-subtitle-time-stop) :to-be 58) (expect (thing-at-point 'word) :to-equal "00"))) (it "returns nil and doesn't move when there is no previous subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 1) (expect (thing-at-point 'word) :to-equal "1") @@ -614,7 +620,7 @@ Baz. (describe "Setting start/stop time" (it "of current subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-end 2) (subed-srt--set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (* 3 1000) 400)) @@ -638,7 +644,7 @@ Baz. "00:03:03,45 --> 00:03:15,5\n" "Baz.\n")))) (it "of specific subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-time-stop 3) (subed-srt--set-subtitle-time-start (+ (* 2 60 60 1000) (* 4 60 1000) (* 6 1000) 800) 1) @@ -663,7 +669,7 @@ Baz. "00:03:03,45 --> 03:05:07,900\n" "Baz.\n")))) (it "when milliseconds lack digits." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-id 3) (subed-srt--set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (* 3 1000) 4) 3) @@ -678,31 +684,31 @@ Baz. (describe "in an empty buffer" (describe "before" (it "passing nothing." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--prepend-subtitle) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n\n")) (expect (point) :to-equal 33))) (it "passing ID." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--prepend-subtitle 2) :to-equal 33) (expect (buffer-string) :to-equal (concat "2\n" "00:00:00,000 --> 00:00:01,000\n\n")) (expect (point) :to-equal 33))) (it "passing ID and start time." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--prepend-subtitle 3 60000) :to-equal 33) (expect (buffer-string) :to-equal (concat "3\n" "00:01:00,000 --> 00:01:01,000\n\n")) (expect (point) :to-equal 33))) (it "passing ID, start time and stop time." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--prepend-subtitle 4 60000 65000) :to-equal 33) (expect (buffer-string) :to-equal (concat "4\n" "00:01:00,000 --> 00:01:05,000\n\n")) (expect (point) :to-equal 33))) (it "passing ID, start time, stop time and text." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--prepend-subtitle 5 60000 65000 "Foo, bar\nbaz.") :to-equal 33) (expect (buffer-string) :to-equal (concat "5\n" "00:01:00,000 --> 00:01:05,000\n" @@ -711,31 +717,31 @@ Baz. ) (describe "after" (it "passing nothing." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--append-subtitle) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n\n")) (expect (point) :to-equal 33))) (it "passing ID." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--append-subtitle 2) :to-equal 33) (expect (buffer-string) :to-equal (concat "2\n" "00:00:00,000 --> 00:00:01,000\n\n")) (expect (point) :to-equal 33))) (it "passing ID and start time." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--append-subtitle 3 60000) :to-equal 33) (expect (buffer-string) :to-equal (concat "3\n" "00:01:00,000 --> 00:01:01,000\n\n")) (expect (point) :to-equal 33))) (it "passing ID, start time and stop time." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--append-subtitle 4 60000 65000) :to-equal 33) (expect (buffer-string) :to-equal (concat "4\n" "00:01:00,000 --> 00:01:05,000\n\n")) (expect (point) :to-equal 33))) (it "passing ID, start time, stop time and text." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--append-subtitle 5 60000 65000 "Foo, bar\nbaz.") :to-equal 33) (expect (buffer-string) :to-equal (concat "5\n" "00:01:00,000 --> 00:01:05,000\n" @@ -747,7 +753,7 @@ Baz. (describe "before the current subtitle" (describe "with point on the first subtitle" (it "passing nothing." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) @@ -761,7 +767,7 @@ Baz. "Foo.\n")) (expect (point) :to-equal 33))) (it "passing ID." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) @@ -775,7 +781,7 @@ Baz. "Foo.\n")) (expect (point) :to-equal 33))) (it "passing ID and start time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) @@ -789,7 +795,7 @@ Baz. "Foo.\n")) (expect (point) :to-equal 33))) (it "passing ID, start time and stop time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) @@ -803,7 +809,7 @@ Baz. "Foo.\n")) (expect (point) :to-equal 33))) (it "passing ID, start time, stop time and text." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) @@ -819,7 +825,7 @@ Baz. ) (describe "with point on a non-first subtitle" (it "passing nothing." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" @@ -839,7 +845,7 @@ Baz. "Bar.\n")) (expect (point) :to-equal 71))) (it "passing ID." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" @@ -859,7 +865,7 @@ Baz. "Bar.\n")) (expect (point) :to-equal 71))) (it "passing ID and start time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" @@ -879,7 +885,7 @@ Baz. "Bar.\n")) (expect (point) :to-equal 71))) (it "passing ID, start time and stop time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" @@ -899,7 +905,7 @@ Baz. "Bar.\n")) (expect (point) :to-equal 71))) (it "passing ID, start time, stop time and text." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" @@ -923,7 +929,7 @@ Baz. (describe "after the current subtitle" (describe "with point on the last subtitle" (it "passing nothing." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) @@ -937,7 +943,7 @@ Baz. "\n")) (expect (point) :to-equal 71))) (it "passing ID." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) @@ -951,7 +957,7 @@ Baz. "\n")) (expect (point) :to-equal 71))) (it "passing ID and start time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) @@ -965,7 +971,7 @@ Baz. "\n")) (expect (point) :to-equal 71))) (it "passing ID, start time and stop time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) @@ -979,7 +985,7 @@ Baz. "\n")) (expect (point) :to-equal 71))) (it "passing ID, start time, stop time and text." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) @@ -995,7 +1001,7 @@ Baz. ) (describe "with point on a non-last subtitle" (it "passing nothing." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -1015,7 +1021,7 @@ Baz. "Bar.\n")) (expect (point) :to-equal 71))) (it "passing ID." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -1035,7 +1041,7 @@ Baz. "Bar.\n")) (expect (point) :to-equal 71))) (it "passing ID and start time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -1055,7 +1061,7 @@ Baz. "Bar.\n")) (expect (point) :to-equal 71))) (it "passing ID, start time and stop time." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -1075,7 +1081,7 @@ Baz. "Bar.\n")) (expect (point) :to-equal 71))) (it "passing ID, start time, stop time and text." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" @@ -1097,7 +1103,7 @@ Baz. ) ) (it "when point is on empty text." - (with-temp-buffer + (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "\n")) @@ -1115,7 +1121,7 @@ Baz. (describe "Killing a subtitle" (it "removes the first subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (subed-srt--kill-subtitle) @@ -1126,7 +1132,7 @@ Baz. "00:03:03,45 --> 00:03:15,5\n" "Baz.\n")))) (it "removes it in between." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (subed-srt--kill-subtitle) @@ -1137,7 +1143,7 @@ Baz. "00:03:03,45 --> 00:03:15,5\n" "Baz.\n")))) (it "removes the last subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 3) (subed-srt--kill-subtitle) @@ -1149,7 +1155,7 @@ Baz. "Bar.\n")))) (describe "removes the previous subtitle when point is right above the ID" (it "of the last subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-id 3) (backward-char) @@ -1162,7 +1168,7 @@ Baz. "00:03:03,45 --> 00:03:15,5\n" "Baz.\n")))) (it "of a non-last subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-id 2) (backward-char) @@ -1179,10 +1185,10 @@ Baz. (describe "Validating" (it "works in empty buffer." - (with-temp-buffer + (with-temp-srt-buffer (expect (subed-srt--validate) :to-be nil))) (it "reports invalid IDs." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 1) (insert "x") @@ -1190,7 +1196,7 @@ Baz. 'error '("Found invalid subtitle ID: \"x1\"")) (expect (point) :to-equal 1))) (it "reports invalid start time." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-time-start 1) (forward-char 5) @@ -1199,7 +1205,7 @@ Baz. 'error '("Found invalid start time: \"00:0101,000 --> 00:01:05,123\"")) (expect (point) :to-equal 3))) (it "reports invalid stop time." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-time-stop 1) (forward-char 10) @@ -1208,7 +1214,7 @@ Baz. 'error '("Found invalid stop time: \"00:01:01,000 --> 00:01:05,1323\"")) (expect (point) :to-equal 20))) (it "reports invalid time separator." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-time-stop 1) (delete-char -1) @@ -1216,7 +1222,7 @@ Baz. 'error '("Found invalid separator between start and stop time: \"00:01:01,000 -->00:01:05,123\"")) (expect (point) :to-equal 15))) (it "does not report error when last subtitle text is empty." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 3) (kill-whole-line) @@ -1224,7 +1230,7 @@ Baz. (subed-srt--validate) (expect (point) :to-equal 104))) (it "preserves point if there is no error." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (forward-char 2) @@ -1234,7 +1240,7 @@ Baz. (describe "Sanitizing" (it "removes trailing tabs and spaces from all lines." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (while (re-search-forward "\n" nil t) @@ -1242,7 +1248,7 @@ Baz. (expect (buffer-string) :not :to-equal mock-srt-data) (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data)) - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (while (re-search-forward "\n" nil t) @@ -1251,7 +1257,7 @@ Baz. (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data))) (it "removes leading tabs and spaces from all lines." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (while (re-search-forward "\n" nil t) @@ -1259,7 +1265,7 @@ Baz. (expect (buffer-string) :not :to-equal mock-srt-data) (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data)) - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (while (re-search-forward "\n" nil t) @@ -1268,7 +1274,7 @@ Baz. (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data))) (it "removes excessive empty lines between subtitles." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (while (re-search-forward "\n\n" nil t) @@ -1277,7 +1283,7 @@ Baz. (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data))) (it "ensures double newline between subtitles if text of previous subtitle is empty." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (kill-whole-line) @@ -1301,7 +1307,7 @@ Baz. "00:03:03,45 --> 00:03:15,5\n" "Baz.\n")))) (it "removes empty lines from beginning of buffer." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (insert " \n\t\n") @@ -1309,7 +1315,7 @@ Baz. (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data))) (it "removes empty lines from end of buffer." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-max)) (insert " \n\t\n\n") @@ -1317,7 +1323,7 @@ Baz. (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data))) (it "ensures a single newline after the last subtitle." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-max)) (while (eq (char-before (point-max)) ?\n) @@ -1326,7 +1332,7 @@ Baz. (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data))) (it "ensures single newline after last subtitle if text is empty." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 3) (kill-whole-line) @@ -1350,7 +1356,7 @@ Baz. "00:03:03,45 --> 00:03:15,5\n" "\n")))) (it "ensures single space before and after time separators." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (re-search-forward " --> ") @@ -1366,7 +1372,7 @@ Baz. (describe "Renumbering" (it "ensures consecutive subtitle IDs." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (while (looking-at "^[0-9]$") @@ -1377,7 +1383,7 @@ Baz. (describe "Sorting" (it "orders subtitles by start time." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (re-search-forward "01:01") @@ -1404,7 +1410,7 @@ Baz. "Foo.\n")))) (describe "preserves point in the current subtitle" (it "when subtitle text is non-empty." - (with-temp-buffer + (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (re-search-forward "01:01") @@ -1414,7 +1420,7 @@ Baz. (subed-srt--sort) (expect (current-word) :to-equal "Foo"))) (it "when subtitle text is empty." - (with-temp-buffer + (with-temp-srt-buffer (insert "1\n00:12:01,000 --> 00:01:05,123\n") (goto-char (point-max)) (subed-srt--sort)