Skip to content

Commit

Permalink
move roundtrip float to optional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
drmason13 committed Mar 29, 2024
1 parent aeb034e commit 50f0d09
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ test_framework = ["compiler", "dep:prettydiff", "dep:serde_json", "dep:ansi_term
arbitrary = ["dep:quickcheck", "dep:arbitrary"]
lua = ["dep:mlua"]
proptest = ["dep:proptest", "dep:proptest-derive"]
float_roundtrip = ["dep:serde_json", "serde_json/float_roundtrip"]

# Internal testing utilities (used for benches)
test = ["string_path"]
Expand Down Expand Up @@ -157,7 +158,7 @@ rustyline = { version = "14", default-features = false, optional = true }
rust_decimal = { version = "1", optional = true }
seahash = { version = "4", optional = true }
serde = { version = "1", features = ["derive"], optional = true }
serde_json = { version = "1", default-features = false, optional = true, features = ["std", "raw_value", "float_roundtrip"] }
serde_json = { version = "1", default-features = false, optional = true, features = ["std", "raw_value"] }
sha-1 = { version = "0.10", optional = true }
sha-2 = { package = "sha2", version = "0.10", optional = true }
sha-3 = { package = "sha3", version = "0.10", optional = true }
Expand Down
18 changes: 17 additions & 1 deletion src/stdlib/parse_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,24 @@ mod tests {
want: Ok(value!({"num": 9.223_372_036_854_776e18})),
tdef: type_def(),
}
];

#[cfg(not(feature = "float_roundtrip"))]
test_function![
parse_json => ParseJson;

no_roundtrip_float_conversion {
args: func_args![ value: r#"{"num": 1626175065.5934923}"#],
want: Ok(value!({"num": 1_626_175_065.593_492_5})),
tdef: type_def(),
}
];

#[cfg(feature = "float_roundtrip")]
test_function![
parse_json => ParseJson;

lossless_float_conversion {
roundtrip_float_conversion {
args: func_args![ value: r#"{"num": 1626175065.5934923}"#],
want: Ok(value!({"num": 1_626_175_065.593_492_3})),
tdef: type_def(),
Expand Down

0 comments on commit 50f0d09

Please sign in to comment.