Skip to content

Commit

Permalink
Fix tests for truncated header
Browse files Browse the repository at this point in the history
Didn't fully considering different versions of ellipsis string.
  • Loading branch information
dajva committed Nov 12, 2024
1 parent c4cefb8 commit d797e0e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
52 changes: 26 additions & 26 deletions test/rg-header.el-test.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(require 'cl-lib)
(require 'mule-util)

(defvar rg-unit/long-search-pattern "everything everywhere all at once")

Expand Down Expand Up @@ -62,31 +61,32 @@ Instead DO-RETURN will be returned when the function is called."
(ert-deftest rg-unit/search-pattern-truncation-in-header ()
"Tests `rg-header-truncate-search-pattern'."
;; When predicate is true.
(rg-unit/mock-truncation-predicate (:max 11 :predicate always)
(should (string=
(concat "everything" (truncate-string-ellipsis))
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))

(rg-unit/mock-truncation-predicate (:max 5 :predicate always)
(should (string=
"ever…"
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))

(rg-unit/mock-truncation-predicate (:max (length rg-unit/long-search-pattern) :predicate always)
(should (string=
"everything everywhere all at once"
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))

;; When predicate is false.
(rg-unit/mock-truncation-predicate (:max 11 :predicate ignore)
(should (string=
"everything everywhere all at once"
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))

(rg-unit/mock-truncation-predicate (:predicate ignore)
(should (string=
"everything everywhere all at once"
(rg-header-truncate-search-pattern rg-unit/long-search-pattern)))))
(let ((ellipsis-len (length (rg-truncate-string-ellipsis))))
(rg-unit/mock-truncation-predicate (:max 11 :predicate always)
(should (string=
(concat (substring "everything" 0 (- 11 ellipsis-len)) (rg-truncate-string-ellipsis))
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))

(rg-unit/mock-truncation-predicate (:max 5 :predicate always)
(should (string=
(concat (substring "ever" 0 (- 5 ellipsis-len)) (rg-truncate-string-ellipsis))
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))

(rg-unit/mock-truncation-predicate (:max (length rg-unit/long-search-pattern) :predicate always)
(should (string=
"everything everywhere all at once"
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))

;; When predicate is false.
(rg-unit/mock-truncation-predicate (:max 11 :predicate ignore)
(should (string=
"everything everywhere all at once"
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))

(rg-unit/mock-truncation-predicate (:predicate ignore)
(should (string=
"everything everywhere all at once"
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))))

(ert-deftest rg-unit/search-help-for-header ()
"Tests `rg-header-search-help'."
Expand Down
6 changes: 6 additions & 0 deletions test/test-helper.el
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
(require 'seq)
(require 'tramp)
(require 'wgrep-rg)
(require 'mule-util)

(defun rg-regexp-anywhere (needle)
(s-replace "%%%%" needle "\\( \\|^\\)%%%%\\( \\|$\\)"))
Expand Down Expand Up @@ -189,4 +190,9 @@ backward."
"Compare if SET1 and SET2 contain the same elements."
(not (cl-set-exclusive-or set1 set2 :test #'equal)))

(defun rg-truncate-string-ellipsis ()
(if (fboundp 'truncate-string-ellipsis)
(truncate-string-ellipsis)
truncate-string-ellipsis))

;;; test-helper.el ends here

0 comments on commit d797e0e

Please sign in to comment.