From 1d6243cf70269acdaf32f1ad61beba241f130484 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 8 Apr 2014 22:01:44 +0200 Subject: 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. --- tests/ui.scm | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'tests/ui.scm') 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 +;;; Copyright © 2013, 2014 Ludovic Courtès ;;; ;;; 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") -- cgit 1.4.1