diff options
author | Ludovic Courtès <ludo@gnu.org> | 2014-04-08 22:01:44 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2014-04-08 22:01:44 +0200 |
commit | 1d6243cf70269acdaf32f1ad61beba241f130484 (patch) | |
tree | c095e485d515820680f74ae2bd321d00d91190de /tests | |
parent | c397e502ca4f9a929e213e1c728b942a007ee278 (diff) | |
download | guix-1d6243cf70269acdaf32f1ad61beba241f130484.tar.gz |
ui: Add 'size->number'.
* guix/scripts/gc.scm (size->number): Remove. * guix/ui.scm (size->number): New procedure. * tests/ui.scm ("size->number, bytes", "size->number, MiB", "size->number, GiB", "size->number, 1.2GiB", "size->number, invalid unit"): New tests.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ui.scm | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/ui.scm b/tests/ui.scm index 08ee3967a8..886223ef54 100644 --- a/tests/ui.scm +++ b/tests/ui.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2013 Ludovic Courtès <ludo@gnu.org> +;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org> ;;; ;;; This file is part of GNU Guix. ;;; @@ -166,6 +166,29 @@ interface, and powerful string processing.") #f (string->duration "d")) +(test-equal "size->number, bytes" + 42 + (size->number "42")) + +(test-equal "size->number, MiB" + (* 42 (expt 2 20)) + (size->number "42MiB")) + +(test-equal "size->number, GiB" + (* 3 (expt 2 30)) + (size->number "3GiB")) + +(test-equal "size->number, 1.2GiB" + (inexact->exact (round (* 1.2 (expt 2 30)))) + (size->number "1.2GiB")) + +(test-assert "size->number, invalid unit" + (catch 'quit + (lambda () + (size->number "9X")) + (lambda args + #t))) + (test-end "ui") |