[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/subed 00f315b318 2/5: Default to new 'adjust value for sub
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/subed 00f315b318 2/5: Default to new 'adjust value for subed-enforce-time-boundaries |
Date: |
Tue, 7 Mar 2023 19:01:15 -0500 (EST) |
branch: elpa/subed
commit 00f315b3184d223c68fcece9a81adb257b90c33f
Author: Sacha Chua <sacha@sachachua.com>
Commit: Sacha Chua <sacha@sachachua.com>
Default to new 'adjust value for subed-enforce-time-boundaries
* subed/subed-common.el (set-subtitle-time-start): Add ignore-overlap
argument.
(set-subtitle-time-stop): Add ignore-overlap argument.
(subed-adjust-subtitle-time-start): Use the logic in
set-subtitle-time-start instead.
(subed-adjust-subtitle-time-stop): Use the logic in
set-subtitle-time-stop instead.
* subed/subed-config.el (subed-enforce-time-boundaries): Default to
adjusting times. Allow users to set the behavior to report errors instead.
* tests/test-subed-common.el ("Setting subtitle start time"): Add
tests for overlaps and negative duration.
("Setting subtitle stop time"): Add tests for overlaps and negative
duration.
* tests/test-subed-srt.el ("SRT"): Allow overlaps and negative
durations for quick tests.
* tests/test-subed-vtt.el ("VTT"): Allow overlaps and negative
durations for quick tests.
---
subed/subed-common.el | 123 ++++++++++++++------------
subed/subed-config.el | 18 ++--
tests/test-subed-common.el | 212 ++++++++++++++++++++++++++++++++++++++++++++-
tests/test-subed-srt.el | 8 +-
tests/test-subed-vtt.el | 12 +--
5 files changed, 302 insertions(+), 71 deletions(-)
diff --git a/subed/subed-common.el b/subed/subed-common.el
index 8b0f6ea9ab..fbf995097a 100644
--- a/subed/subed-common.el
+++ b/subed/subed-common.el
@@ -349,7 +349,8 @@ If SUB-ID is not given, set the text of the current
subtitle."
(subed-define-generic-function set-subtitle-time-start (msecs
&optional sub-id
-
ignore-negative-duration)
+
ignore-negative-duration
+
ignore-overlap)
"Set subtitle start time to MSECS milliseconds.
If SUB-ID is not given, set the start of the current subtitle.
@@ -359,21 +360,46 @@ Unless either IGNORE-NEGATIVE-DURATION is non-nil or
the start time will be after the stop time. Zero-length
subtitles are allowed.
+Unless either IGNORE-OVERLAP is non-nil or `subed-enforce-time-boundaries'
+is nil, ensure that there are no gaps between subtitles
+smaller than `subed-subtitle-spacing' milliseconds by adjusting
+MSECS if necessary.
+
Return the new subtitle start time in milliseconds."
(save-excursion
(when (or (not sub-id)
(and sub-id (subed-jump-to-subtitle-id sub-id)))
+ (when (and
+ (not ignore-negative-duration)
+ subed-enforce-time-boundaries
+ (> msecs
(subed-subtitle-msecs-stop)))
+ (if (eq subed-enforce-time-boundaries 'error)
+ (error "Start time %s will be
after stop time %s"
+
(subed-msecs-to-timestamp msecs)
+
(subed-msecs-to-timestamp (subed-subtitle-msecs-stop)))
+ (let ((subed-enforce-time-boundaries
nil))
+ (subed-set-subtitle-time-stop
msecs))))
(when (and subed-enforce-time-boundaries
- (not
ignore-negative-duration)
- (> msecs
(subed-subtitle-msecs-stop)))
- (error "Start time %d will be after stop time
%d" msecs (subed-subtitle-msecs-stop)))
- (when (and (subed-jump-to-subtitle-time-start sub-id)
+ (not
ignore-overlap))
+ (subed-save-excursion
+ (when (and (subed-backward-subtitle-time-stop)
+
subed-subtitle-spacing
+
(> (subed-subtitle-msecs-stop)
+
(- msecs subed-subtitle-spacing)))
+ (if (eq subed-enforce-time-boundaries
'error)
+ (error "Start time %s
will be too close to previous stop time of %s"
+
(subed-msecs-to-timestamp msecs)
+
(subed-msecs-to-timestamp (subed-subtitle-msecs-stop)))
+ (let
((subed-enforce-time-boundaries nil))
+
(subed-set-subtitle-time-stop (- msecs subed-subtitle-spacing)))))))
+ (when (and (subed-jump-to-subtitle-time-start sub-id)
(looking-at subed--regexp-timestamp))
(replace-match
(save-match-data (subed-msecs-to-timestamp msecs)))))))
(subed-define-generic-function set-subtitle-time-stop (msecs &optional sub-id
-
ignore-negative-duration)
+
ignore-negative-duration
+
ignore-overlap)
"Set subtitle stop time to MSECS milliseconds.
If SUB-ID is not given, set the stop of the current subtitle.
@@ -383,6 +409,11 @@ Unless either IGNORE-NEGATIVE-DURATION is non-nil or
the start time will be after the stop time. Zero-length
subtitles are allowed.
+Unless either IGNORE-OVERLAP is non-nil or `subed-enforce-time-boundaries'
+is nil, ensure that there are no gaps between subtitles
+smaller than `subed-subtitle-spacing' milliseconds by adjusting
+MSECS if necessary.
+
Return the new subtitle stop time in milliseconds."
(save-excursion
(when (or (not sub-id)
@@ -391,7 +422,25 @@ Return the new subtitle stop time in milliseconds."
(when (and subed-enforce-time-boundaries
(not
ignore-negative-duration)
(<
msecs (subed-subtitle-msecs-start)))
- (error "Stop time %d will be before
start time %d" msecs (subed-subtitle-msecs-start))))
+ (if (eq subed-enforce-time-boundaries
'error)
+ (error "Stop time %s
will be before start time %s"
+
(subed-msecs-to-timestamp msecs)
+
(subed-msecs-to-timestamp (subed-subtitle-msecs-start)))
+ (let
((subed-enforce-time-boundaries nil))
+
(subed-set-subtitle-time-start msecs)))))
+ (when (and subed-enforce-time-boundaries
+ (not
ignore-overlap))
+ (subed-save-excursion
+ (when (and (subed-forward-subtitle-time-stop)
+
subed-subtitle-spacing
+
(< (subed-subtitle-msecs-start)
+
(+ msecs subed-subtitle-spacing)))
+ (if (eq subed-enforce-time-boundaries
'error)
+ (error "Stop time %s
will be too close to next start time of %s"
+
(subed-msecs-to-timestamp msecs)
+
(subed-msecs-to-timestamp (subed-subtitle-msecs-start)))
+ (let
((subed-enforce-time-boundaries nil))
+
(subed-set-subtitle-time-start (+ msecs subed-subtitle-spacing)))))))
(when (and
(subed-jump-to-subtitle-time-stop)
(looking-at
subed--regexp-timestamp))
@@ -613,7 +662,7 @@ Unless either IGNORE-NEGATIVE-DURATION is non-nil or
stop time isn't smaller than the start time. Zero-length
subtitles are always allowed.
-Unless either IGNORE-OVERLAP is non-nilor `subed-enforce-time-boundaries'
+Unless either IGNORE-OVERLAP is non-nil or `subed-enforce-time-boundaries'
is nil, ensure that there are no gaps between subtitles
smaller than `subed-subtitle-spacing' milliseconds by adjusting
MSECS if necessary.
@@ -624,29 +673,13 @@ nil if nothing changed."
(let* ((msecs-start (subed-subtitle-msecs-start))
(msecs-new (when msecs-start (+ msecs-start msecs))))
(when msecs-new
- (if (> msecs 0)
- ;; Adding to start time
- (unless (or ignore-negative-duration
- (not subed-enforce-time-boundaries))
- (let ((msecs-stop (subed-subtitle-msecs-stop)))
- (setq msecs-new (min msecs-new msecs-stop))))
- ;; Subtracting from start time
- (unless (or ignore-overlap
- (not subed-enforce-time-boundaries))
- (let* ((msecs-prev-stop (save-excursion (when
(subed-backward-subtitle-id)
-
(subed-subtitle-msecs-stop))))
- (msecs-min (if msecs-prev-stop
- (+ msecs-prev-stop subed-subtitle-spacing) 0)))
- (when msecs-min
- (setq msecs-new (max msecs-new msecs-min))))))
;; MSECS-NEW must be bigger than the current start time if we are adding
;; or smaller if we are subtracting.
- (when (and (>= msecs-new 0) ;; Ignore
negative times
- (or (and (> msecs 0) (> msecs-new msecs-start)) ;; Adding
- (and (< msecs 0) (< msecs-new msecs-start)))) ;;
Subtracting
- (subed-set-subtitle-time-start msecs-new nil ignore-negative-duration)
- (subed--run-subtitle-time-adjusted-hook)
- (- msecs-new msecs-start)))))
+ (subed-set-subtitle-time-start msecs-new nil
+
ignore-negative-duration
+
ignore-overlap)
+ (subed--run-subtitle-time-adjusted-hook)
+ (- msecs-new msecs-start))))
(defun subed-adjust-subtitle-time-stop (msecs &optional
ignore-negative-duration
@@ -668,30 +701,14 @@ nil if nothing changed."
(subed-disable-sync-point-to-player-temporarily)
(let* ((msecs-stop (subed-subtitle-msecs-stop))
(msecs-new (when msecs-stop (+ msecs-stop msecs))))
- (when msecs-new
- (if (> msecs 0)
- ;; Adding to stop time
- (unless (or ignore-overlap
- (not subed-enforce-time-boundaries))
- (let* ((msecs-next-start (save-excursion (when
(subed-forward-subtitle-id)
-
(subed-subtitle-msecs-start))))
- (msecs-max (when msecs-next-start
- (- msecs-next-start subed-subtitle-spacing))))
- (when msecs-max
- (setq msecs-new (min msecs-new msecs-max)))))
- ;; Subtracting from stop time
- (unless (or ignore-negative-duration
- (not subed-enforce-time-boundaries))
- (let ((msecs-start (subed-subtitle-msecs-start)))
- (setq msecs-new (max msecs-new msecs-start)))))
- ;; MSECS-NEW must be bigger than the current stop time if we are adding
or
- ;; smaller if we are subtracting.
- (when (and (>= msecs-new 0) ;; Ignore
negative times
- (or (and (> msecs 0) (> msecs-new msecs-stop)) ;; Adding
- (and (< msecs 0) (< msecs-new msecs-stop)))) ;;
Subtracting
- (subed-set-subtitle-time-stop msecs-new nil ignore-negative-duration)
- (subed--run-subtitle-time-adjusted-hook)
- (- msecs-new msecs-stop)))))
+ ;; MSECS-NEW must be bigger than the current stop time if we are adding or
+ ;; smaller if we are subtracting.
+ (when (and (>= msecs-new 0) ;; Ignore
negative times
+ (or (and (> msecs 0) (> msecs-new msecs-stop)) ;; Adding
+ (and (< msecs 0) (< msecs-new msecs-stop)))) ;; Subtracting
+ (subed-set-subtitle-time-stop msecs-new nil ignore-negative-duration
ignore-overlap)
+ (subed--run-subtitle-time-adjusted-hook)
+ (- msecs-new msecs-stop))))
(defun subed-increase-start-time (&optional arg)
"Add `subed-milliseconds-adjust' milliseconds to start time.
diff --git a/subed/subed-config.el b/subed/subed-config.el
index fe8dc917b2..4f82726aa5 100644
--- a/subed/subed-config.el
+++ b/subed/subed-config.el
@@ -159,11 +159,19 @@ If set to zero or smaller, playback is paused."
:type 'float
:group 'subed)
-(defcustom subed-enforce-time-boundaries t
- "Non-nil means refuse time adjustments that result in invalid subtitles.
-For example, refuse adjustments that result in overlapping
-subtitles or negative duration."
- :type 'boolean
+(defcustom subed-enforce-time-boundaries 'adjust
+ "How to manage changes that cause overlapping subtitles or negative
durations.
+- 'adjust means adjust the stop or start time of the current subtitle to
+ keep duration >= 0, and adjust the previous or next subtitle as needed
+ to maintain `subed-subtitle-spacing'.
+- 'error means report an error.
+- nil means perform the change without checking.
+
+Other values aside from the ones specified above will be treated as 'adjust."
+ :type '(choice
+ (const :tag "Adjust other times as
needed" adjust)
+ (const :tag "Report an error" error)
+ (const :tag "Do not check" nil))
:group 'subed)
(defcustom subed-sanitize-functions
diff --git a/tests/test-subed-common.el b/tests/test-subed-common.el
index 1ccb3c00de..d61d0db2b0 100644
--- a/tests/test-subed-common.el
+++ b/tests/test-subed-common.el
@@ -162,10 +162,100 @@ Baz.
)
)
(describe "Setting subtitle start time"
+ (describe "when this causes an overlap"
+ (describe "when time boundaries are enforced by errors"
+ :var ((subed-subtitle-spacing 100))
+ (it "continues when setting the first
subtitle's start time."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 1)
+ (let ((subed-enforce-time-boundaries
'error))
+ (subed-set-subtitle-time-start
30000))
+ (expect (subed-subtitle-msecs-start)
:to-equal 30000)))
+ (it "ignores the previous subtitle's stop time
if there's enough spacing."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 2)
+ (let ((subed-enforce-time-boundaries
'error))
+ (subed-set-subtitle-time-start
(subed-timestamp-to-msecs "00:01:10,000")))
+ (expect (subed-subtitle-msecs-start)
:to-equal (subed-timestamp-to-msecs "00:01:10,000"))
+ (expect (subed-subtitle-msecs-stop 1)
:to-equal (subed-timestamp-to-msecs "00:01:05,123"))))
+ (it "ignores the previous subtitle's stop time
if spacing is unspecified."
+ (let ((subed-subtitle-spacing nil)
+
(subed-enforce-time-boundaries 'error))
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 2)
+ (subed-set-subtitle-time-start
(subed-timestamp-to-msecs "00:01:05,000"))
+ (expect
(subed-subtitle-msecs-start) :to-equal (subed-timestamp-to-msecs
"00:01:05,000"))
+ (expect
(subed-subtitle-msecs-stop 1) :to-equal (subed-timestamp-to-msecs
"00:01:05,123")))))
+ (it "reports an error if the change violates
spacing."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 2)
+ (let ((subed-enforce-time-boundaries
'error)
+
(subed-subtitle-spacing 100))
+ (expect
(subed-set-subtitle-time-start (subed-timestamp-to-msecs "00:01:05,000"))
:to-throw 'error)))))
+ (describe "when time boundaries are enforced by
adjusting"
+ (it "continues when setting the first
subtitle's start time."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 1)
+ (let ((subed-enforce-time-boundaries
'adjust)
+
(subed-subtitle-spacing 100))
+ (subed-set-subtitle-time-start
(subed-timestamp-to-msecs "00:01:00,000")))
+ (expect (subed-subtitle-msecs-start)
:to-equal (subed-timestamp-to-msecs "00:01:00,000"))))
+ (it "ignores the previous subtitle's stop time
if there's enough spacing."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 2)
+ (let ((subed-enforce-time-boundaries
'adjust)
+
(subed-subtitle-spacing 100))
+ (subed-set-subtitle-time-start
(subed-timestamp-to-msecs "00:01:10,000")))
+ (expect (subed-subtitle-msecs-start)
:to-equal (subed-timestamp-to-msecs "00:01:10,000"))
+ (expect (subed-subtitle-msecs-stop 1)
:to-equal (subed-timestamp-to-msecs "00:01:05,123"))))
+ (it "ignores the previous subtitle's stop time
if spacing is unspecified."
+ (let ((subed-subtitle-spacing nil)
+
(subed-enforce-time-boundaries 'adjust))
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 2)
+ (subed-set-subtitle-time-start
(subed-timestamp-to-msecs "00:01:05,000"))
+ (expect
(subed-subtitle-msecs-start) :to-equal (subed-timestamp-to-msecs
"00:01:05,000"))
+ (expect
(subed-subtitle-msecs-stop 1) :to-equal (subed-timestamp-to-msecs
"00:01:05,123")))))
+ (it "adjusts the previous subtitle's stop time
to maintain spacing."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 2)
+ (let ((subed-enforce-time-boundaries
'adjust)
+
(subed-subtitle-spacing 100))
+ (subed-set-subtitle-time-start
(subed-timestamp-to-msecs "00:01:05,000")))
+ (expect (subed-subtitle-msecs-start)
:to-equal (subed-timestamp-to-msecs "00:01:05,000"))
+ (expect (subed-subtitle-msecs-stop 1)
:to-equal (subed-timestamp-to-msecs "00:01:04,900"))))
+ (it "adjusts the previous subtitle's stop time,
but not the one before it."
+ ;; TODO: Decide if we want to change
this expectation
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 3)
+ (let ((subed-enforce-time-boundaries
'adjust)
+
(subed-subtitle-spacing 100))
+ (subed-set-subtitle-time-start
(subed-timestamp-to-msecs "00:01:05,000")))
+ (expect (subed-subtitle-msecs-start)
:to-equal (subed-timestamp-to-msecs "00:01:05,000"))
+ (expect (subed-subtitle-msecs-stop 2)
:to-equal (subed-timestamp-to-msecs "00:01:04,900"))
+ (expect (subed-subtitle-msecs-stop 1)
:to-equal (subed-timestamp-to-msecs "00:01:05,123"))))
+ (it "adjusts the current subtitle's stop time
to at least the start time."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 2)
+ (let ((subed-enforce-time-boundaries
'adjust)
+
(subed-subtitle-spacing 100))
+ (subed-set-subtitle-time-start
(subed-timestamp-to-msecs "00:02:11,000")))
+ (expect (subed-subtitle-msecs-start)
:to-equal (subed-timestamp-to-msecs "00:02:11,000"))
+ (expect (subed-subtitle-msecs-stop 1)
:to-equal (subed-timestamp-to-msecs "00:01:05,123"))))))
(describe "when it will result in invalid duration"
:var ((temp-time (+ (* 3 60 1000) (* 17 1000))))
(it "throws an error when enforcing time boundaries."
- (let ((subed-enforce-time-boundaries t))
+ (let ((subed-enforce-time-boundaries 'error))
(with-temp-srt-buffer
(insert mock-srt-data)
(subed-jump-to-subtitle-id 3)
@@ -179,13 +269,129 @@ Baz.
(subed-set-subtitle-time-start
temp-time)
(expect (subed-subtitle-msecs-start)
:to-equal temp-time))))
(it "changes it when negative durations are allowed."
- (let ((subed-enforce-time-boundaries t))
+ (let ((subed-enforce-time-boundaries 'error))
(with-temp-srt-buffer
(insert mock-srt-data)
(subed-jump-to-subtitle-id 3)
(subed-set-subtitle-time-start
temp-time nil t)
(expect (subed-subtitle-msecs-start)
:to-equal temp-time))))))
-
+ (describe "Setting subtitle stop time"
+ (describe "when this causes an overlap"
+ (describe "when time boundaries are enforced by errors"
+ :var ((subed-subtitle-spacing 100))
+ (it "continues when setting the last subtitle's
stop time."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 3)
+ (let ((subed-enforce-time-boundaries
'error))
+ (subed-set-subtitle-time-stop
(subed-timestamp-to-msecs "00:03:30,000")))
+ (expect (subed-subtitle-msecs-stop)
:to-equal (subed-timestamp-to-msecs "00:03:30,000"))))
+ (it "ignores the next subtitle's start time if
there's enough spacing."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 2)
+ (let ((subed-enforce-time-boundaries
'error))
+ (subed-set-subtitle-time-stop
(subed-timestamp-to-msecs "00:03:01,000")))
+ (expect (subed-subtitle-msecs-stop)
:to-equal (subed-timestamp-to-msecs "00:03:01,000"))
+ (expect (subed-subtitle-msecs-start 3)
:to-equal (subed-timestamp-to-msecs "00:03:03,45"))))
+ (it "ignores the next subtitle's start time if
spacing is unspecified."
+ (let ((subed-subtitle-spacing nil)
+
(subed-enforce-time-boundaries 'error))
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 2)
+ (let
((subed-enforce-time-boundaries 'error))
+
(subed-set-subtitle-time-stop (subed-timestamp-to-msecs "00:03:05,000")))
+ (expect
(subed-subtitle-msecs-stop) :to-equal (subed-timestamp-to-msecs "00:03:05,000"))
+ (expect
(subed-subtitle-msecs-start 3) :to-equal (subed-timestamp-to-msecs
"00:03:03,45")))))
+ (it "reports an error if the change violates
spacing."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 2)
+ (let ((subed-enforce-time-boundaries
'error)
+
(subed-subtitle-spacing 100))
+ (expect
(subed-set-subtitle-time-stop (subed-timestamp-to-msecs "00:03:05,000"))
+
:to-throw 'error)))))
+ (describe "when time boundaries are enforced by
adjusting"
+ :var ((subed-subtitle-spacing 100))
+ (it "continues when setting the last subtitle's
stop time."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 3)
+ (let ((subed-enforce-time-boundaries
'adjust))
+ (subed-set-subtitle-time-stop
(subed-timestamp-to-msecs "00:03:30,000")))
+ (expect (subed-subtitle-msecs-stop)
:to-equal (subed-timestamp-to-msecs "00:03:30,000"))))
+ (it "ignores the next subtitle's start time if
there's enough spacing."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 2)
+ (let ((subed-enforce-time-boundaries
'adjust))
+ (subed-set-subtitle-time-stop
(subed-timestamp-to-msecs "00:03:01,000")))
+ (expect (subed-subtitle-msecs-stop)
:to-equal (subed-timestamp-to-msecs "00:03:01,000"))
+ (expect (subed-subtitle-msecs-start 3)
:to-equal (subed-timestamp-to-msecs "00:03:03,45"))))
+ (it "ignores the next subtitle's start time if
spacing is unspecified."
+ (let ((subed-subtitle-spacing nil))
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 2)
+ (let
((subed-enforce-time-boundaries 'adjust))
+
(subed-set-subtitle-time-stop (subed-timestamp-to-msecs "00:03:05,000")))
+ (expect
(subed-subtitle-msecs-stop) :to-equal (subed-timestamp-to-msecs "00:03:05,000"))
+ (expect
(subed-subtitle-msecs-start 3) :to-equal (subed-timestamp-to-msecs
"00:03:03,45")))))
+ (it "adjusts the next subtitle's start time to
maintain spacing."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 2)
+ (let ((subed-enforce-time-boundaries
'adjust)
+
(subed-subtitle-spacing 100))
+ (subed-set-subtitle-time-stop
(subed-timestamp-to-msecs "00:03:05,000")))
+ (expect (subed-subtitle-msecs-stop)
:to-equal (subed-timestamp-to-msecs "00:03:05,000"))
+ (expect (subed-subtitle-msecs-start 3)
:to-equal (subed-timestamp-to-msecs "00:03:05,100"))))
+ (it "adjusts the next subtitle's stop time, but
not the one after it."
+ ;; TODO: Decide if we want to change
this expectation
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 1)
+ (let ((subed-enforce-time-boundaries
'adjust)
+
(subed-subtitle-spacing 100))
+ (subed-set-subtitle-time-stop
(subed-timestamp-to-msecs "00:03:05,000")))
+ (expect (subed-subtitle-msecs-stop)
:to-equal (subed-timestamp-to-msecs "00:03:05,000"))
+ (expect (subed-subtitle-msecs-start 2)
:to-equal (subed-timestamp-to-msecs "00:03:05,100"))
+ (expect (subed-subtitle-msecs-start 3)
:to-equal (subed-timestamp-to-msecs "00:03:03,45"))))))
+ (describe "when it will result in invalid duration"
+ (it "adjusts the start time as needed."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 3)
+ (let ((subed-enforce-time-boundaries 'adjust)
+ (temp-time
(subed-timestamp-to-msecs "00:03:01,000")))
+ (subed-set-subtitle-time-stop
temp-time)
+ (expect (subed-subtitle-msecs-start)
:to-equal temp-time)
+ (expect (subed-subtitle-msecs-stop)
:to-equal temp-time))))
+ (it "throws an error when enforcing time boundaries."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 3)
+ (let ((subed-enforce-time-boundaries 'error)
+ (temp-time
(subed-timestamp-to-msecs "00:03:01,000")))
+ (expect (subed-set-subtitle-time-stop
temp-time)
+
:to-throw 'error))))
+ (it "changes it when ignoring time boundaries."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 3)
+ (let ((subed-enforce-time-boundaries nil)
+ (temp-time
(subed-timestamp-to-msecs "00:03:01,000")))
+ (subed-set-subtitle-time-stop
temp-time)
+ (expect (subed-subtitle-msecs-stop)
:to-equal temp-time))))
+ (it "changes it when negative durations are allowed."
+ (with-temp-srt-buffer
+ (insert mock-srt-data)
+ (subed-jump-to-subtitle-id 3)
+ (let ((subed-enforce-time-boundaries 'error)
+ (temp-time
(subed-timestamp-to-msecs "00:03:01,000")))
+ (subed-set-subtitle-time-stop
temp-time nil t)
+ (expect (subed-subtitle-msecs-stop)
:to-equal temp-time))))))
(describe "Adjusting subtitle start/stop time"
:var (subed-subtitle-time-adjusted-hook)
(it "runs the appropriate hook."
diff --git a/tests/test-subed-srt.el b/tests/test-subed-srt.el
index b28e616958..d01d05eb98 100644
--- a/tests/test-subed-srt.el
+++ b/tests/test-subed-srt.el
@@ -624,7 +624,7 @@ Baz.
(with-temp-srt-buffer
(insert mock-srt-data)
(subed-jump-to-subtitle-end 2)
- (subed-set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (* 3
1000) 400) nil t)
+ (subed-set-subtitle-time-start (subed-timestamp-to-msecs "1:02:03,400")
nil t t)
(expect (buffer-string) :to-equal (concat "1\n"
"00:01:01,000 -->
00:01:05,123\n"
"Foo.\n\n"
@@ -634,7 +634,7 @@ Baz.
"3\n"
"00:03:03,45 --> 00:03:15,5\n"
"Baz.\n"))
- (subed-set-subtitle-time-stop (+ (* 5 60 60 1000) (* 6 60 1000) (* 7
1000) 800) nil t)
+ (subed-set-subtitle-time-stop (subed-timestamp-to-msecs "5:06:07,800")
nil t t)
(expect (buffer-string) :to-equal (concat "1\n"
"00:01:01,000 -->
00:01:05,123\n"
"Foo.\n\n"
@@ -648,7 +648,7 @@ Baz.
(with-temp-srt-buffer
(insert mock-srt-data)
(subed-jump-to-subtitle-time-stop 3)
- (subed-set-subtitle-time-start (+ (* 2 60 60 1000) (* 4 60 1000) (* 6
1000) 800) 1 t)
+ (subed-set-subtitle-time-start (+ (* 2 60 60 1000) (* 4 60 1000) (* 6
1000) 800) 1 t t)
(expect (buffer-string) :to-equal (concat "1\n"
"02:04:06,800 -->
00:01:05,123\n"
"Foo.\n\n"
@@ -659,7 +659,7 @@ Baz.
"00:03:03,45 --> 00:03:15,5\n"
"Baz.\n"))
(subed-jump-to-subtitle-text 1)
- (subed-set-subtitle-time-stop (+ (* 3 60 60 1000) (* 5 60 1000) (* 7
1000) 900) 3 t)
+ (subed-set-subtitle-time-stop (+ (* 3 60 60 1000) (* 5 60 1000) (* 7
1000) 900) 3 t t)
(expect (buffer-string) :to-equal (concat "1\n"
"02:04:06,800 -->
00:01:05,123\n"
"Foo.\n\n"
diff --git a/tests/test-subed-vtt.el b/tests/test-subed-vtt.el
index 82b827eec4..a06dada324 100644
--- a/tests/test-subed-vtt.el
+++ b/tests/test-subed-vtt.el
@@ -579,7 +579,7 @@ Baz.
(with-temp-vtt-buffer
(insert mock-vtt-data)
(subed-jump-to-subtitle-end "00:02:02.234")
- (subed-set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (* 3
1000) 400) nil t)
+ (subed-set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (* 3
1000) 400) nil t t)
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"00:01:01.000 -->
00:01:05.123\n"
"Foo.\n\n"
@@ -587,7 +587,7 @@ Baz.
"Bar.\n\n"
"00:03:03.45 --> 00:03:15.5\n"
"Baz.\n"))
- (subed-set-subtitle-time-stop (+ (* 5 60 60 1000) (* 6 60 1000) (* 7
1000) 800) nil t)
+ (subed-set-subtitle-time-stop (+ (* 5 60 60 1000) (* 6 60 1000) (* 7
1000) 800) nil t t)
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"00:01:01.000 -->
00:01:05.123\n"
"Foo.\n\n"
@@ -599,7 +599,7 @@ Baz.
(with-temp-vtt-buffer
(insert mock-vtt-data)
(subed-jump-to-subtitle-time-stop "00:01:01.000")
- (subed-set-subtitle-time-start (+ (* 2 60 60 1000) (* 4 60 1000) (* 6
1000) 800) 1 t)
+ (subed-set-subtitle-time-start (+ (* 2 60 60 1000) (* 4 60 1000) (* 6
1000) 800) 1 t t)
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"02:04:06.800 -->
00:01:05.123\n"
"Foo.\n\n"
@@ -608,7 +608,7 @@ Baz.
"00:03:03.45 --> 00:03:15.5\n"
"Baz.\n"))
(subed-jump-to-subtitle-text "00:03:03.45")
- (subed-set-subtitle-time-stop (+ (* 3 60 60 1000) (* 5 60 1000) (* 7
1000) 900) 3 t)
+ (subed-set-subtitle-time-stop (+ (* 3 60 60 1000) (* 5 60 1000) (* 7
1000) 900) 3 t t)
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"02:04:06.800 -->
00:01:05.123\n"
"Foo.\n\n"
@@ -620,11 +620,11 @@ Baz.
(with-temp-vtt-buffer
(insert mock-vtt-data)
(subed-jump-to-subtitle-id "00:03:03.45")
- (subed-set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (* 3
1000) 4) 3 t)
+ (subed-set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (* 3
1000) 4) 3 t t)
(expect (save-excursion (subed-jump-to-subtitle-time-start)
(thing-at-point 'line))
:to-equal "01:02:03.004 --> 00:03:15.5\n")
- (subed-set-subtitle-time-stop (+ (* 2 60 60 1000) (* 3 60 1000) (* 4
1000) 60) 3 t)
+ (subed-set-subtitle-time-stop (+ (* 2 60 60 1000) (* 3 60 1000) (* 4
1000) 60) 3 t t)
(expect (save-excursion (subed-jump-to-subtitle-time-start)
(thing-at-point 'line))
:to-equal "01:02:03.004 --> 02:03:04.060\n"))))
- [nongnu] elpa/subed updated (28a75a6f68 -> 43fcde0c3a), ELPA Syncer, 2023/03/07
- [nongnu] elpa/subed 82e137352d 3/5: Handle subed-enforce-time-boundaries values of error, adjust, and clip, ELPA Syncer, 2023/03/07
- [nongnu] elpa/subed 43fcde0c3a 5/5: v1.1.0 Mention subed-enforce-time-boundaries values, ELPA Syncer, 2023/03/07
- [nongnu] elpa/subed 00f315b318 2/5: Default to new 'adjust value for subed-enforce-time-boundaries,
ELPA Syncer <=
- [nongnu] elpa/subed f8ce6d4e6c 1/5: Enforce time boundaries when setting start or stop time, ELPA Syncer, 2023/03/07
- [nongnu] elpa/subed 0810c97a76 4/5: Tweak tests some more for wording, coverage reporting, ELPA Syncer, 2023/03/07