File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -234,7 +234,10 @@ pub(super) fn toml_to_json_value(toml: TomlValue) -> JsonValue {
234234 _ => JsonValue :: String ( s) ,
235235 } ,
236236 TomlValue :: Integer ( i) => JsonValue :: Number ( i. into ( ) ) ,
237- TomlValue :: Float ( f) => JsonValue :: Number ( serde_json:: Number :: from_f64 ( f) . unwrap ( ) ) ,
237+ TomlValue :: Float ( f) => match serde_json:: Number :: from_f64 ( f) {
238+ Some ( n) => JsonValue :: Number ( n) ,
239+ None => JsonValue :: String ( f. to_string ( ) ) ,
240+ } ,
238241 TomlValue :: Boolean ( b) => JsonValue :: Bool ( b) ,
239242 TomlValue :: Array ( a) => JsonValue :: Array ( a. into_iter ( ) . map ( toml_to_json_value) . collect ( ) ) ,
240243 TomlValue :: Table ( t) => {
Original file line number Diff line number Diff line change @@ -329,6 +329,24 @@ contract ParseTomlTest is DSTest {
329329
330330 assertEq (keccak256 (abi.encode (members)), keccak256 (abi.encode (data.members)));
331331 }
332+
333+ function test_floatNaN () public {
334+ bytes memory data = vm.parseToml (toml, ".nanFloat " );
335+ string memory decodedData = abi.decode (data, (string ));
336+ assertEq ("NaN " , decodedData);
337+ }
338+
339+ function test_floatInf () public {
340+ bytes memory data = vm.parseToml (toml, ".infFloat " );
341+ string memory decodedData = abi.decode (data, (string ));
342+ assertEq ("inf " , decodedData);
343+ }
344+
345+ function test_floatNegInf () public {
346+ bytes memory data = vm.parseToml (toml, ".neginfFloat " );
347+ string memory decodedData = abi.decode (data, (string ));
348+ assertEq ("-inf " , decodedData);
349+ }
332350}
333351
334352contract WriteTomlTest is DSTest {
Original file line number Diff line number Diff line change 1+ nanFloat = nan
2+ infFloat = +inf
3+ neginfFloat = -inf
4+
15basicString = " hai"
26nullString = " null"
37multilineString = """
4852
4953[[advancedTomlPath ]]
5054id = 2
55+
56+
You can’t perform that action at this time.
0 commit comments