summaryrefslogtreecommitdiff
path: root/test/lisp/files-tests.el
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2019-05-13 17:05:24 +0200
committerMattias EngdegÄrd <mattiase@acm.org>2019-06-23 20:30:50 +0200
commit866f527ddf21050a827fa47e04cfe6163f1c7053 (patch)
tree411dae7879dc84717f0bfd11087633d32762b5a7 /test/lisp/files-tests.el
parentb439b3bb5a44bc61cec3f5c8e3e3ea37760dfb29 (diff)
downloademacs-866f527ddf21050a827fa47e04cfe6163f1c7053.tar.gz
emacs-866f527ddf21050a827fa47e04cfe6163f1c7053.tar.bz2
emacs-866f527ddf21050a827fa47e04cfe6163f1c7053.zip
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.
Diffstat (limited to 'test/lisp/files-tests.el')
-rw-r--r--test/lisp/files-tests.el23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index fe2e958f1c3..aa5dbe7acf9 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -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