Skip to content

Commit

Permalink
Factor out a pluralize function
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilfred committed Nov 26, 2016
1 parent 7a4a02f commit b2f4bd0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
26 changes: 13 additions & 13 deletions elisp-refs.el
Original file line number Diff line number Diff line change
Expand Up @@ -469,20 +469,20 @@ propertize them."
'path path)
(buffer-string)))

(defun elisp-refs--pluralize (number thing)
"Human-friendly description of NUMBER occurrences of THING."
(format "%s %s%s"
(elisp-refs--format-int number)
thing
(if (equal number 1) "" "s")))

(defun elisp-refs--format-count (symbol ref-count file-count)
(let ((ref-count-str
(if (equal ref-count 1)
"1 reference"
(format "%s references" (elisp-refs--format-int ref-count))))
(file-count-str
(cond
((zerop file-count)
"")
((equal file-count 1)
" in 1 file")
(t
(format " in %s files" (elisp-refs--format-int file-count))))))
(format "Found %s to %s%s." ref-count-str symbol file-count-str)))
(format "Found %s to %s%s."
(elisp-refs--pluralize ref-count "reference")
symbol
(if (zerop file-count)
""
(format " in %s" (elisp-refs--pluralize file-count "file")))))

;; TODO: if we have multiple matches on one line, we repeatedly show
;; that line. That's slighly confusing.
Expand Down
6 changes: 6 additions & 0 deletions test/unit-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ whilst visiting that file."
(should (equal (elisp-refs--format-int -1234) "-1,234"))
(should (equal (elisp-refs--format-int 1234567) "1,234,567")))

(ert-deftest elisp-refs--pluralize ()
(should (equal (elisp-refs--pluralize 0 "thing") "0 things"))
(should (equal (elisp-refs--pluralize 1 "thing") "1 thing"))
(should (equal (elisp-refs--pluralize 2 "thing") "2 things"))
(should (equal (elisp-refs--pluralize 1001 "thing") "1,001 things")))

(ert-deftest elisp-refs--unindent-split-properties ()
"Ensure we can still unindent when properties are split
into separate region. Regression test for a very subtle bug."
Expand Down

0 comments on commit b2f4bd0

Please sign in to comment.