diff --git a/Cargo.toml b/Cargo.toml index 46dd70f..0df8b9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ debug = true [workspace.dependencies] jiter = { path = "crates/jiter", version = "0.5.0" } +batson = { path = "crates/batson", version = "0.5.0" } pyo3 = { version = "0.22.0" } pyo3-build-config = { version = "0.22.0" } bencher = "0.1.5" diff --git a/crates/fuzz/Cargo.toml b/crates/fuzz/Cargo.toml index cde9a3b..da0d33e 100644 --- a/crates/fuzz/Cargo.toml +++ b/crates/fuzz/Cargo.toml @@ -15,7 +15,8 @@ serde = "1.0.190" indexmap = "2.0.0" num-bigint = "0.4.4" num-traits = "0.2.17" -jiter = {path = "../jiter"} +jiter = {workspace = true} +batson = {workspace = true} [[bin]] name = "compare_to_serde" @@ -28,3 +29,9 @@ name = "compare_skip" path = "fuzz_targets/compare_skip.rs" test = false doc = false + +[[bin]] +name = "batson_round_trip" +path = "fuzz_targets/batson_round_trip.rs" +test = false +doc = false diff --git a/crates/fuzz/fuzz_targets/batson_round_trip.rs b/crates/fuzz/fuzz_targets/batson_round_trip.rs new file mode 100644 index 0000000..4dcce95 --- /dev/null +++ b/crates/fuzz/fuzz_targets/batson_round_trip.rs @@ -0,0 +1,24 @@ +#![no_main] + +use batson::{batson_to_json_string, encode_from_json}; +use jiter::JsonValue; + +use libfuzzer_sys::fuzz_target; + +fn round_trip(json: String) { + let Ok(jiter_value1) = JsonValue::parse(json.as_bytes(), false) else { + return; + }; + let bytes1 = encode_from_json(&jiter_value1).unwrap(); + let json1 = batson_to_json_string(&bytes1).unwrap(); + + let jiter_value2 = JsonValue::parse(json1.as_bytes(), false).unwrap(); + let bytes2 = encode_from_json(&jiter_value2).unwrap(); + let json2 = batson_to_json_string(&bytes2).unwrap(); + + assert_eq!(json1, json2); +} + +fuzz_target!(|json: String| { + round_trip(json); +});