Commit 265d2ec2 authored by Aaron Raddon's avatar Aaron Raddon

add coerce-bool to string closes #26

parent a9009387
......@@ -30,6 +30,11 @@ func CoerceString(v interface{}) (string, error) {
return strconv.FormatFloat(float64(val), 'f', -1, 32), nil
case float64:
return strconv.FormatFloat(val, 'f', -1, 64), nil
case bool:
if val {
return "true", nil
}
return "false", nil
case []byte:
if string(val) == "null" || string(val) == "NULL" {
return "", nil
......
......@@ -13,11 +13,13 @@ func TestCoerce(t *testing.T) {
"float": 45.3,
"string": "22",
"stringf": "22.2",
"boolt": true,
}
assert.True(t, CoerceStringShort(data["int"]) == "4", "get int as string")
assert.True(t, CoerceStringShort(data["float"]) == "45.3", "get float as string: %v", data["float"])
assert.True(t, CoerceStringShort(data["string"]) == "22", "get string as string: %v", data["string"])
assert.True(t, CoerceStringShort(data["stringf"]) == "22.2", "get stringf as string: %v", data["stringf"])
assert.Equal(t, "true", CoerceStringShort(data["boolt"]))
assert.True(t, CoerceIntShort(data["int"]) == 4, "get int as int: %v", data["int"])
assert.True(t, CoerceIntShort(data["float"]) == 45, "get float as int: %v", data["float"])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment