Skip to content

Commit d797e0e

Browse files
committed
Fix tests for truncated header
Didn't fully considering different versions of ellipsis string.
1 parent c4cefb8 commit d797e0e

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

test/rg-header.el-test.el

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
(require 'cl-lib)
2-
(require 'mule-util)
32

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

@@ -62,31 +61,32 @@ Instead DO-RETURN will be returned when the function is called."
6261
(ert-deftest rg-unit/search-pattern-truncation-in-header ()
6362
"Tests `rg-header-truncate-search-pattern'."
6463
;; When predicate is true.
65-
(rg-unit/mock-truncation-predicate (:max 11 :predicate always)
66-
(should (string=
67-
(concat "everything" (truncate-string-ellipsis))
68-
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))
69-
70-
(rg-unit/mock-truncation-predicate (:max 5 :predicate always)
71-
(should (string=
72-
"ever…"
73-
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))
74-
75-
(rg-unit/mock-truncation-predicate (:max (length rg-unit/long-search-pattern) :predicate always)
76-
(should (string=
77-
"everything everywhere all at once"
78-
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))
79-
80-
;; When predicate is false.
81-
(rg-unit/mock-truncation-predicate (:max 11 :predicate ignore)
82-
(should (string=
83-
"everything everywhere all at once"
84-
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))
85-
86-
(rg-unit/mock-truncation-predicate (:predicate ignore)
87-
(should (string=
88-
"everything everywhere all at once"
89-
(rg-header-truncate-search-pattern rg-unit/long-search-pattern)))))
64+
(let ((ellipsis-len (length (rg-truncate-string-ellipsis))))
65+
(rg-unit/mock-truncation-predicate (:max 11 :predicate always)
66+
(should (string=
67+
(concat (substring "everything" 0 (- 11 ellipsis-len)) (rg-truncate-string-ellipsis))
68+
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))
69+
70+
(rg-unit/mock-truncation-predicate (:max 5 :predicate always)
71+
(should (string=
72+
(concat (substring "ever" 0 (- 5 ellipsis-len)) (rg-truncate-string-ellipsis))
73+
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))
74+
75+
(rg-unit/mock-truncation-predicate (:max (length rg-unit/long-search-pattern) :predicate always)
76+
(should (string=
77+
"everything everywhere all at once"
78+
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))
79+
80+
;; When predicate is false.
81+
(rg-unit/mock-truncation-predicate (:max 11 :predicate ignore)
82+
(should (string=
83+
"everything everywhere all at once"
84+
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))
85+
86+
(rg-unit/mock-truncation-predicate (:predicate ignore)
87+
(should (string=
88+
"everything everywhere all at once"
89+
(rg-header-truncate-search-pattern rg-unit/long-search-pattern))))))
9090

9191
(ert-deftest rg-unit/search-help-for-header ()
9292
"Tests `rg-header-search-help'."

test/test-helper.el

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
(require 'seq)
4242
(require 'tramp)
4343
(require 'wgrep-rg)
44+
(require 'mule-util)
4445

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

193+
(defun rg-truncate-string-ellipsis ()
194+
(if (fboundp 'truncate-string-ellipsis)
195+
(truncate-string-ellipsis)
196+
truncate-string-ellipsis))
197+
192198
;;; test-helper.el ends here

0 commit comments

Comments
 (0)