branch: elpa/subed commit 9078a46b745b92fd57454af5e782332308014bae Author: Random User <rnd...@posteo.de> Commit: Random User <rnd...@posteo.de>
subed-srt--validate: Don't complain if buffer contains only whitespace --- subed/subed-srt.el | 3 ++- tests/test-subed-srt.el | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/subed/subed-srt.el b/subed/subed-srt.el index 83bd2d4..c9ddb9b 100644 --- a/subed/subed-srt.el +++ b/subed/subed-srt.el @@ -504,7 +504,8 @@ scheduled call is canceled and another call is scheduled in (save-match-data (let ((orig-point (point))) (goto-char (point-min)) - (while (re-search-forward (format "\\(%s[[^\\']]\\|\\`\\)" subed-srt--regexp-separator) nil t) + (while (and (re-search-forward (format "\\(%s[[^\\']]\\|\\`\\)" subed-srt--regexp-separator) nil t) + (looking-at "[[:alnum:]]")) (unless (looking-at "^[0-9]+$") (error "Found invalid subtitle ID: %S" (substring (or (thing-at-point 'line :no-properties) "\n") 0 -1))) (forward-line) diff --git a/tests/test-subed-srt.el b/tests/test-subed-srt.el index 2ae1832..a4af646 100644 --- a/tests/test-subed-srt.el +++ b/tests/test-subed-srt.el @@ -1186,7 +1186,24 @@ Baz. (describe "Validating" (it "works in empty buffer." (with-temp-srt-buffer - (expect (subed-srt--validate) :to-be nil))) + (subed-srt--validate))) + (it "works in buffer that contains only newlines." + (with-temp-srt-buffer + (cl-loop for _ from 1 to 10 do + (insert "\n") + (subed-srt--validate)))) + (it "works in buffer that contains only spaces." + (with-temp-srt-buffer + (cl-loop for _ from 1 to 10 do + (insert " ") + (subed-srt--validate)))) + (it "works in buffer that contains only spaces and newlines." + (with-temp-srt-buffer + (cl-loop for _ from 1 to 10 do + (if (eq (random 2) 0) + (insert " ") + (insert "\n")) + (subed-srt--validate)))) (it "reports invalid IDs." (with-temp-srt-buffer (insert mock-srt-data)