Skip to content

Commit

Permalink
Update json conversion subpackage
Browse files Browse the repository at this point in the history
  • Loading branch information
Kripth committed Feb 16, 2018
1 parent 32e4cc4 commit 5592474
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions json/src/toml/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import toml.toml : TOMLDocument, TOMLValue, TOML_TYPE, TOMLException;
*/
JSONValue toJSON(TOMLValue toml) {
final switch(toml.type) with(TOML_TYPE) {
case BOOL: return JSONValue(toml.boolean);
case STRING: return JSONValue(toml.str);
case INTEGER: return JSONValue(toml.integer);
case FLOAT: return JSONValue(toml.floating);
Expand All @@ -42,6 +41,8 @@ JSONValue toJSON(TOMLValue toml) {
ret[key] = toJSON(value);
}
return JSONValue(ret);
case TRUE: return JSONValue(true);
case FALSE: return JSONValue(false);
}
}

Expand All @@ -56,7 +57,6 @@ unittest {
import std.datetime : SysTime, Date;
import toml.datetime : DateTime, TimeOfDay;

assert(toJSON(TOMLValue(true)).type == JSON_TYPE.TRUE);
assert(toJSON(TOMLValue("string")).str == "string");
assert(toJSON(TOMLValue(42)) == JSONValue(42));
assert(toJSON(TOMLValue(.1)) == JSONValue(.1));
Expand All @@ -66,6 +66,9 @@ unittest {
assert(toJSON(TOMLValue(TimeOfDay.fromISOExtString("07:32:00"))).str == "07:32:00");
assert(toJSON(TOMLValue([1, 2, 3])) == JSONValue([1, 2, 3]));
assert(toJSON(TOMLDocument(["a": TOMLValue(0), "b": TOMLValue(1)])) == JSONValue(["a": 0, "b": 1]));
assert(toJSON(TOMLValue(true)).type == JSON_TYPE.TRUE);
assert(toJSON(TOMLValue(false)).type == JSON_TYPE.FALSE);

}

/**
Expand Down Expand Up @@ -107,7 +110,7 @@ unittest {
toTOML(JSONValue.init); assert(0);
} catch(TOMLException) {}

assert(toTOML(JSONValue(true)).type == TOML_TYPE.BOOL);
assert(toTOML(JSONValue(true)).type == TOML_TYPE.TRUE);
assert(toTOML(JSONValue(false)) == false);
assert(toTOML(JSONValue("test")) == "test");
assert(toTOML(JSONValue(42)) == 42);
Expand Down

0 comments on commit 5592474

Please sign in to comment.