mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 10:30:25 -08:00
Optional space and unit in `file-size-human-readable' (bug#35756)
To improve readability of strings produced by `file-size-human-readable', add two optional arguments: - SPACE, to provide a string (typically a space or non-breaking space) to put between the number and unit. For compatibility, the default is an empty string. - UNIT, a string to use as unit. For compatibility, the default is "B" in `iec' mode and the empty string otherwise. Also fix a glitch with small numbers in `iec' mode which caused a stray "i" in the result. * lisp/files.el (file-size-human-readable): Add optional SPACE and UNIT arguments and handle small numbers correctly. (files--ask-user-about-large-file, warn-maybe-out-of-memory): Call with `iec' and space. * test/lisp/files-tests.el (files-test-file-size-human-readable): New test. * lisp/url/url-http.el (url-http-simple-after-change-function) (url-http-content-length-after-change-function): Call with `iec' and space. * etc/NEWS (Lisp Changes): Mention the change.
This commit is contained in:
parent
b439b3bb5a
commit
866f527ddf
4 changed files with 69 additions and 23 deletions
|
|
@ -1259,5 +1259,28 @@ renaming only, rather than modified in-place."
|
|||
(ignore-errors (advice-remove #'write-region advice))
|
||||
(ignore-errors (delete-file temp-file-name)))))
|
||||
|
||||
(ert-deftest files-test-file-size-human-readable ()
|
||||
(should (equal (file-size-human-readable 13) "13"))
|
||||
(should (equal (file-size-human-readable 13 'si) "13"))
|
||||
(should (equal (file-size-human-readable 13 'iec) "13B"))
|
||||
(should (equal (file-size-human-readable 10000) "9.8k"))
|
||||
(should (equal (file-size-human-readable 10000 'si) "10k"))
|
||||
(should (equal (file-size-human-readable 10000 'iec) "9.8KiB"))
|
||||
(should (equal (file-size-human-readable 4294967296 nil) "4G"))
|
||||
(should (equal (file-size-human-readable 4294967296 'si) "4.3G"))
|
||||
(should (equal (file-size-human-readable 4294967296 'iec) "4GiB"))
|
||||
(should (equal (file-size-human-readable 13 nil " ") "13"))
|
||||
(should (equal (file-size-human-readable 13 'si " ") "13"))
|
||||
(should (equal (file-size-human-readable 13 'iec " ") "13 B"))
|
||||
(should (equal (file-size-human-readable 10000 nil " ") "9.8 k"))
|
||||
(should (equal (file-size-human-readable 10000 'si " ") "10 k"))
|
||||
(should (equal (file-size-human-readable 10000 'iec " ") "9.8 KiB"))
|
||||
(should (equal (file-size-human-readable 4294967296 nil " ") "4 G"))
|
||||
(should (equal (file-size-human-readable 4294967296 'si " ") "4.3 G"))
|
||||
(should (equal (file-size-human-readable 4294967296 'iec " ") "4 GiB"))
|
||||
(should (equal (file-size-human-readable 10000 nil " " "bit") "9.8 kbit"))
|
||||
(should (equal (file-size-human-readable 10000 'si " " "bit") "10 kbit"))
|
||||
(should (equal (file-size-human-readable 10000 'iec " " "bit") "9.8 Kibit")))
|
||||
|
||||
(provide 'files-tests)
|
||||
;;; files-tests.el ends here
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue