@@ -3767,25 +3767,30 @@ Detail: https://github.com/jrblevin/markdown-mode/issues/79"
37673767 (kill-buffer )))))
37683768
37693769(defadvice markdown-live-preview-window-eww
3770- (around markdown-create-fake-eww disable)
3770+ (around markdown-test- create-fake-eww disable)
37713771 (setq ad-return-value (get-buffer-create " *eww*" )))
37723772
3773- (defmacro markdown-temp -eww (&rest body )
3773+ (defmacro markdown-test-fake -eww (&rest body )
37743774 `(progn
3775- ,@(if (featurep 'eww ) body
3775+ ,@(if (require 'eww nil t ) body
37763776 `((ad-enable-advice #'markdown-live-preview-window-eww
3777- 'around 'markdown-create-fake-eww )
3777+ 'around 'markdown-test- create-fake-eww )
37783778 (ad-activate #'markdown-live-preview-window-eww )
37793779 ,@body
37803780 (ad-disable-advice #'markdown-live-preview-window-eww
3781- 'around 'markdown-create-fake-eww )
3781+ 'around 'markdown-test- create-fake-eww )
37823782 (ad-activate #'markdown-live-preview-window-eww )))))
37833783
3784+ (defmacro markdown-test-eww-or-nothing (test &rest body )
3785+ (if (require 'eww nil t ) `(progn ,@body )
3786+ (message " no eww found: skipping %s " test)
3787+ nil ))
3788+
37843789(ert-deftest test-markdown-ext/live-preview-exports ()
37853790 (markdown-test-temp-file " inline.text"
37863791 (unless (require 'eww nil t )
37873792 (should-error (markdown-live-preview-mode )))
3788- (markdown-temp -eww
3793+ (markdown-test-fake -eww
37893794 (markdown-live-preview-mode )
37903795 (should (buffer-live-p markdown-live-preview-buffer))
37913796 (should (eq (current-buffer )
@@ -3798,7 +3803,7 @@ Detail: https://github.com/jrblevin/markdown-mode/issues/79"
37983803 (should (buffer-live-p markdown-live-preview-buffer)))))
37993804
38003805(ert-deftest test-markdown-ext/live-preview-delete-exports ()
3801- (markdown-temp -eww
3806+ (markdown-test-fake -eww
38023807 (let ((markdown-live-preview-delete-export 'delete-on-destroy )
38033808 file-output)
38043809 (markdown-test-temp-file " inline.text"
@@ -3820,6 +3825,49 @@ Detail: https://github.com/jrblevin/markdown-mode/issues/79"
38203825 (should (file-exists-p file-output)))
38213826 (delete-file file-output)))))
38223827
3828+ (ert-deftest test-markdown-ext/live-preview-follow-min-max ()
3829+ (markdown-test-eww-or-nothing " live-preview-follow-min-max"
3830+ (markdown-test-temp-file " inline.text"
3831+ (markdown-live-preview-mode )
3832+ (should (buffer-live-p markdown-live-preview-buffer))
3833+ (should (window-live-p (get-buffer-window markdown-live-preview-buffer)))
3834+ (with-selected-window (get-buffer-window markdown-live-preview-buffer)
3835+ (goto-char (point-min )))
3836+ (goto-char (point-min ))
3837+ (insert " a test " )
3838+ (markdown-live-preview-export)
3839+ (let (final-pt final-win-st-diff)
3840+ ; ; test that still starts at point-min
3841+ (with-selected-window (get-buffer-window markdown-live-preview-buffer)
3842+ (should (= (window-point ) 1 ))
3843+ (should (= (markdown-visual-lines-between-points
3844+ (window-start ) (window-point ))
3845+ 0 ))
3846+ (set-window-point (selected-window ) (point-max ))
3847+ (setq final-pt (window-point )
3848+ final-win-st-diff (markdown-visual-lines-between-points
3849+ (window-start ) (window-point ))))
3850+ (goto-char (point-min ))
3851+ (insert " this is " )
3852+ (markdown-live-preview-export)
3853+ (with-selected-window (get-buffer-window markdown-live-preview-buffer)
3854+ (should (= (window-point ) (+ final-pt (length " this is " ))))
3855+ (should (= (markdown-visual-lines-between-points
3856+ (window-start ) (window-point ))
3857+ final-win-st-diff))
3858+ ; ; test that still starts at point-max, with correct line difference
3859+ (goto-char (floor (/ (float (- (point-max ) (point-min ))) 2 )))
3860+ (setq final-pt (window-point )
3861+ final-win-st-diff (markdown-visual-lines-between-points
3862+ (window-start ) final-pt)))
3863+ (markdown-live-preview-export)
3864+ ; ; test that still starts at same point, with correct line difference
3865+ (with-selected-window (get-buffer-window markdown-live-preview-buffer)
3866+ (should (= (window-point ) final-pt))
3867+ (should (= (markdown-visual-lines-between-points
3868+ (window-start ) (window-point ))
3869+ final-win-st-diff)))))))
3870+
38233871(provide 'markdown-test )
38243872
38253873; ;; markdown-test.el ends here
0 commit comments