Added a test for the empty unit, moved bad unit test into a separate test function

This commit is contained in:
Fredric Silberberg 2014-09-18 13:03:44 -04:00
parent a144a70a61
commit 72c638432f
2 changed files with 13 additions and 1 deletions

View File

@ -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))

View File

@ -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) {