Skip to content

Commit

Permalink
Add unittests for inf and nan
Browse files Browse the repository at this point in the history
  • Loading branch information
Kripth committed Dec 16, 2017
1 parent 9f8e5d1 commit b65747b
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/toml/toml.d
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ struct TOMLValue {
this.store.integer = value;
this._type = TOML_TYPE.INTEGER;
} else static if(isFloatingPoint!T) {
enforce!TOMLException(!value.isNaN && value.isFinite, "Floating point value must be a finite number");
this.store.floating = cast(double)value;
this.store.floating = value.to!double;
this._type = TOML_TYPE.FLOAT;
} else static if(is(T == SysTime)) {
this.store.offsetDatetime = value;
Expand Down Expand Up @@ -978,6 +977,24 @@ trimmed in raw strings.
doc = parseTOML(`flt8 = 9_224_617.445_991_228_313`);
assert(doc["flt8"] == 9_224_617.445_991_228_313);

doc = parseTOML(`
# infinity
sf1 = inf # positive infinity
sf2 = +inf # positive infinity
sf3 = -inf # negative infinity
# not a number
sf4 = nan # actual sNaN/qNaN encoding is implementation specific
sf5 = +nan # same as nan
sf6 = -nan # valid, actual encoding is implementation specific
`);
assert(doc["sf1"] == double.infinity);
assert(doc["sf2"] == double.infinity);
assert(doc["sf3"] == -double.infinity);
assert(doc["sf4"].floating.isNaN());
assert(doc["sf5"].floating.isNaN());
assert(doc["sf6"].floating.isNaN());

doc = parseTOML(`
bool1 = true
bool2 = false
Expand Down

0 comments on commit b65747b

Please sign in to comment.