Skip to content

Commit

Permalink
Fix an old bug where editing submode-specific views wouldn't mark the…
Browse files Browse the repository at this point in the history
…m as "need saving"; add tests.
  • Loading branch information
doublep committed Sep 21, 2023
1 parent b3a68e8 commit 5423b12
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
6 changes: 3 additions & 3 deletions logview.el
Original file line number Diff line number Diff line change
Expand Up @@ -4097,9 +4097,9 @@ only edits after it get discarded."
(dolist (view (logview--views))
(unless (equal (plist-get view :submode) logview-filter-edit--editing-views-for-submode)
(push view combined-views)))
(setq logview--views (nreverse combined-views)))
(setq logview--views new-views
logview--views-need-saving t))
(setf logview--views (nreverse combined-views)))
(setf logview--views new-views))
(setf logview--views-need-saving t)
(logview--after-updating-view-definitions)
(with-current-buffer parent
(logview--update-mode-name)))
Expand Down
49 changes: 45 additions & 4 deletions test/logview.el
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
,@etc)))


(defun logview--test-view-customizations (&rest views)
`((logview--views '(,@views))
(logview--views-initialized t)
(logview--views-need-saving nil)))


(ert-deftest logview-test-log4j-standard-1 ()
(logview--test-with-file "log4j/en-1.log"
(should (equal logview--submode-name "SLF4J"))
Expand Down Expand Up @@ -354,10 +360,7 @@
;; implement.
(ert-deftest logview-test-sections-1 ()
(logview--test-with-file "log4j/sections-1.log"
:extra-customizations '((logview--views
'((:name "sections" :filters "lv INFO\na+ my\\.Server\nm+ serving request")))
(logview--views-initialized t)
(logview--views-need-saving nil))
:extra-customizations (logview--test-view-customizations '(:name "sections" :filters "lv INFO\na+ my\\.Server\nm+ serving request"))
(logview-set-section-view "sections")
(dolist (narrowing '((1 . 1) (2 . 1)))
(save-restriction
Expand Down Expand Up @@ -520,6 +523,44 @@
(should (string= (logview--test-current-message) "serving request 4 (in a different thread)")))))))))))


(ert-deftest logview-test-view-editing-1 ()
(logview--test-with-file "log4j/en-1.log"
:extra-customizations (logview--test-view-customizations)
(logview--do-test-view-editing t)))

(ert-deftest logview-test-view-editing-2 ()
(logview--test-with-file "log4j/en-1.log"
:extra-customizations (logview--test-view-customizations)
(logview--do-test-view-editing nil)))

(defun logview--do-test-view-editing (global)
(if global (logview-edit-all-views) (logview-edit-submode-views))
(insert (format "
view errors%s
LV ERROR
" (if global "" "\nsubmode SLF4J")))
(logview-filter-edit-save)
(should (equal logview--views `((:name "errors" :submode ,(unless global "SLF4J") :filters "LV ERROR"))))
(should logview--views-need-saving)
;; Pretend they are saved. Edit name of the created view.
(setf logview--views-need-saving nil)
(if global (logview-edit-all-views) (logview-edit-submode-views))
(goto-char 1)
(re-search-forward "errors")
(replace-match "error view")
;; Apply changes intermediately.
(logview-filter-edit-apply)
(should (equal logview--views `((:name "error view" :submode ,(unless global "SLF4J") :filters "LV ERROR"))))
(should logview--views-need-saving)
(setf logview--views-need-saving nil)
(goto-char 1)
(re-search-forward "error view")
(replace-match "Error view")
(logview-filter-edit-save)
(should (equal logview--views `((:name "Error view" :submode ,(unless global "SLF4J") :filters "LV ERROR"))))
(should logview--views-need-saving))


(define-derived-mode logview--test-derived-mode logview-mode
"Logview-derived"
(font-lock-add-keywords nil `((,(rx bow "Class" eow) (0 'bold prepend))) t))
Expand Down

0 comments on commit 5423b12

Please sign in to comment.