From 72c638432f2e7eb4d706ffa03e2559ceabd0c984 Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Thu, 18 Sep 2014 13:03:44 -0400 Subject: [PATCH] Added a test for the empty unit, moved bad unit test into a separate test function --- free/main.go | 2 +- free/main_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/free/main.go b/free/main.go index cc8b9e5..d1c8a43 100644 --- a/free/main.go +++ b/free/main.go @@ -23,7 +23,7 @@ func ConvertUnit(stringUnit string) (jsh.Unit, error) { return jsh.GB, nil case "tB": return jsh.TB, nil - case "": + case "": // On some systems (Arch, for example) bytes are just the empty string return jsh.B, nil default: return 0, errors.New(fmt.Sprintf("Unknown unit: %s\n", stringUnit)) diff --git a/free/main_test.go b/free/main_test.go index 2714907..c60e170 100644 --- a/free/main_test.go +++ b/free/main_test.go @@ -24,11 +24,23 @@ func TestConvertUnit(t *testing.T) { testUnitError(jsh.GB, t) testUnitError(jsh.TB, t) + // Test the empty unit, because this exists on some systems + actual, error := ConvertUnit("") + if error != nil { + t.Error(error) + } + if actual != jsh.B { + t.Errorf("Conversion error: expected %s, received %s", jsh.B.ToString(), actual.ToString()) + } +} + +func TestConvertBadUnit(t *testing.T) { // Testing a bad unit conversion actual, error := ConvertUnit("pB") if error == nil { t.Error("Expected an error for unit pB, received value of ", actual) } + } func TestParseGoodLine(t *testing.T) {