#![deny(warnings)]
#![cfg_attr(target_feature = "neon", feature(stdsimd,))]
#![cfg_attr(feature = "hints", feature(core_intrinsics))]
#![forbid(warnings)]
#![warn(unused_extern_crates)]
#![deny(
clippy::all,
clippy::result_unwrap_used,
clippy::unnecessary_unwrap,
clippy::pedantic
)]
#![allow(clippy::module_name_repetitions, clippy::inline_always)]
#![deny(missing_docs)]
#[cfg(feature = "serde_impl")]
extern crate serde as serde_ext;
#[cfg(feature = "serde_impl")]
pub mod serde;
#[cfg(feature = "serde_impl")]
pub use crate::serde::{
from_reader, from_slice, from_str, to_string, to_string_pretty, to_vec, to_vec_pretty,
to_writer, to_writer_pretty,
};
pub mod prelude;
mod charutils;
#[macro_use]
mod macros;
mod error;
mod numberparse;
mod stringparse;
mod utf8check;
pub mod cow;
#[cfg(target_feature = "avx2")]
mod avx2;
#[cfg(target_feature = "avx2")]
pub use crate::avx2::deser::*;
#[cfg(target_feature = "avx2")]
use crate::avx2::stage1::{SimdInput, SIMDINPUT_LENGTH, SIMDJSON_PADDING};
#[cfg(all(target_feature = "sse4.2", not(target_feature = "avx2")))]
mod sse42;
#[cfg(all(target_feature = "sse4.2", not(target_feature = "avx2")))]
pub use crate::sse42::deser::*;
#[cfg(all(target_feature = "sse4.2", not(target_feature = "avx2")))]
use crate::sse42::stage1::{SimdInput, SIMDINPUT_LENGTH, SIMDJSON_PADDING};
#[cfg(all(target_feature = "neon", feature = "neon"))]
mod neon;
#[cfg(all(target_feature = "neon", feature = "neon"))]
pub use crate::neon::deser::*;
#[cfg(all(target_feature = "neon", feature = "neon"))]
use crate::neon::stage1::{SimdInput, SIMDINPUT_LENGTH, SIMDJSON_PADDING};
#[cfg(all(not(any(
target_feature = "sse4.2",
target_feature = "avx2",
target_feature = "neon"
))))]
mod sse42;
#[cfg(all(not(any(
target_feature = "sse4.2",
target_feature = "avx2",
target_feature = "neon"
))))]
#[cfg(all(not(any(
target_feature = "sse4.2",
target_feature = "avx2",
target_feature = "neon"
))))]
pub use crate::sse42::deser::*;
#[cfg(all(not(any(
target_feature = "sse4.2",
target_feature = "avx2",
target_feature = "neon"
))))]
use crate::sse42::stage1::{SimdInput, SIMDINPUT_LENGTH, SIMDJSON_PADDING};
#[cfg(all(
not(feature = "allow-non-simd"),
not(any(
target_feature = "sse4.2",
target_feature = "avx2",
target_feature = "neon"
))
))]
fn please_compile_with_a_simd_compatible_cpu_setting_read_the_simdjonsrs_readme() -> ! {}
use crate::utf8check::ProcessedUtfBytes;
mod stage2;
pub mod value;
use std::mem;
use std::str;
pub use value_trait::StaticNode;
pub use crate::error::{Error, ErrorType};
pub use crate::value::*;
pub use value_trait::ValueType;
pub type Result<T> = std::result::Result<T, Error>;
#[cfg(feature = "known-key")]
mod known_key;
#[cfg(feature = "known-key")]
pub use known_key::{Error as KnownKeyError, KnownKey};
pub use crate::tape::{Node, Tape};
pub fn to_tape<'input>(s: &'input mut [u8]) -> Result<Vec<Node<'input>>> {
Deserializer::from_slice(s).map(|de| de.tape)
}
pub(crate) struct Utf8CheckingState<T> {
has_error: T,
previous: ProcessedUtfBytes<T>,
}
pub(crate) trait Stage1Parse<T> {
fn new_utf8_checking_state() -> Utf8CheckingState<T>;
fn compute_quote_mask(quote_bits: u64) -> u64;
fn cmp_mask_against_input(&self, m: u8) -> u64;
fn check_utf8(&self, state: &mut Utf8CheckingState<T>);
fn check_utf8_errors(state: &Utf8CheckingState<T>) -> bool;
fn unsigned_lteq_against_input(&self, maxval: T) -> u64;
fn find_whitespace_and_structurals(&self, whitespace: &mut u64, structurals: &mut u64);
fn flatten_bits(base: &mut Vec<u32>, idx: u32, bits: u64);
#[cfg_attr(not(feature = "no-inline"), inline(always))]
#[allow(overflowing_literals, clippy::cast_sign_loss)]
fn find_quote_mask_and_bits(
&self,
odd_ends: u64,
prev_iter_inside_quote: &mut u64,
quote_bits: &mut u64,
error_mask: &mut u64,
) -> u64 {
unsafe {
*quote_bits = self.cmp_mask_against_input(b'"');
*quote_bits &= !odd_ends;
let mut quote_mask: u64 = Self::compute_quote_mask(*quote_bits);
quote_mask ^= *prev_iter_inside_quote;
let unescaped: u64 = self.unsigned_lteq_against_input(Self::fill_s8(0x1F));
*error_mask |= quote_mask & unescaped;
*prev_iter_inside_quote = static_cast_u64!(static_cast_i64!(quote_mask) >> 63);
quote_mask
}
}
#[cfg_attr(not(feature = "no-inline"), inline(always))]
fn find_odd_backslash_sequences(&self, prev_iter_ends_odd_backslash: &mut u64) -> u64 {
const EVEN_BITS: u64 = 0x5555_5555_5555_5555;
const ODD_BITS: u64 = !EVEN_BITS;
let bs_bits: u64 = self.cmp_mask_against_input(b'\\');
let start_edges: u64 = bs_bits & !(bs_bits << 1);
let even_start_mask: u64 = EVEN_BITS ^ *prev_iter_ends_odd_backslash;
let even_starts: u64 = start_edges & even_start_mask;
let odd_starts: u64 = start_edges & !even_start_mask;
let even_carries: u64 = bs_bits.wrapping_add(even_starts);
let (mut odd_carries, iter_ends_odd_backslash) = bs_bits.overflowing_add(odd_starts);
odd_carries |= *prev_iter_ends_odd_backslash;
*prev_iter_ends_odd_backslash = if iter_ends_odd_backslash { 0x1 } else { 0x0 };
let even_carry_ends: u64 = even_carries & !bs_bits;
let odd_carry_ends: u64 = odd_carries & !bs_bits;
let even_start_odd_end: u64 = even_carry_ends & ODD_BITS;
let odd_start_even_end: u64 = odd_carry_ends & EVEN_BITS;
let odd_ends: u64 = even_start_odd_end | odd_start_even_end;
odd_ends
}
#[cfg_attr(not(feature = "no-inline"), inline(always))]
fn finalize_structurals(
mut structurals: u64,
whitespace: u64,
quote_mask: u64,
quote_bits: u64,
prev_iter_ends_pseudo_pred: &mut u64,
) -> u64 {
structurals &= !quote_mask;
structurals |= quote_bits;
let pseudo_pred: u64 = structurals | whitespace;
let shifted_pseudo_pred: u64 = (pseudo_pred << 1) | *prev_iter_ends_pseudo_pred;
*prev_iter_ends_pseudo_pred = pseudo_pred >> 63;
let pseudo_structurals: u64 = shifted_pseudo_pred & (!whitespace) & (!quote_mask);
structurals |= pseudo_structurals;
structurals &= !(quote_bits & !quote_mask);
structurals
}
fn fill_s8(n: i8) -> T;
fn zero() -> T;
}
pub struct Deserializer<'de> {
pub(crate) tape: Vec<Node<'de>>,
idx: usize,
}
impl<'de> Deserializer<'de> {
#[cfg(feature = "serde_impl")]
#[cfg_attr(not(feature = "no-inline"), inline(always))]
fn error(error: ErrorType) -> Error {
Deserializer::raw_error(0, '?', error)
}
fn raw_error(idx: usize, c: char, error: ErrorType) -> Error {
Error::new(idx, c, error)
}
pub fn from_slice(input: &'de mut [u8]) -> Result<Self> {
let len = input.len();
let mut string_buffer: Vec<u8> = Vec::with_capacity(len + SIMDJSON_PADDING);
unsafe {
string_buffer.set_len(len + SIMDJSON_PADDING);
};
Deserializer::from_slice_with_buffer(input, &mut string_buffer)
}
pub fn from_slice_with_buffer(input: &'de mut [u8], string_buffer: &mut [u8]) -> Result<Self> {
let len = input.len();
let mut buffer: Vec<u8> = Vec::with_capacity(len + SIMDJSON_PADDING * 2);
let align = buffer
.as_slice()
.as_ptr()
.align_offset(SIMDJSON_PADDING / 2);
unsafe {
buffer
.as_mut_slice()
.get_unchecked_mut(align..align + len)
.clone_from_slice(input);
*(buffer.get_unchecked_mut(len + align)) = 0;
buffer.set_len(len + align);
};
let s1_result: std::result::Result<Vec<u32>, ErrorType> =
unsafe { Deserializer::find_structural_bits(&buffer[align..]) };
let structural_indexes = match s1_result {
Ok(i) => i,
Err(t) => {
return Err(Error::generic(t));
}
};
let tape =
Deserializer::build_tape(input, &buffer[align..], string_buffer, &structural_indexes)?;
Ok(Deserializer { tape, idx: 0 })
}
#[cfg(feature = "serde_impl")]
#[cfg_attr(not(feature = "no-inline"), inline(always))]
fn skip(&mut self) {
self.idx += 1;
}
#[cfg_attr(not(feature = "no-inline"), inline(always))]
fn next_(&mut self) -> Node<'de> {
unsafe {
self.idx += 1;
*self.tape.get_unchecked(self.idx)
}
}
#[allow(clippy::cast_possible_truncation)]
pub(crate) unsafe fn find_structural_bits(
input: &[u8],
) -> std::result::Result<Vec<u32>, ErrorType> {
let len = input.len();
let mut structural_indexes = Vec::with_capacity(len / 6);
structural_indexes.push(0);
let mut state = SimdInput::new_utf8_checking_state();
let mut prev_iter_ends_odd_backslash: u64 = 0;
let mut prev_iter_inside_quote: u64 = 0;
let mut prev_iter_ends_pseudo_pred: u64 = 1;
let mut structurals: u64 = 0;
let lenminus64: usize = if len < 64 { 0 } else { len as usize - 64 };
let mut idx: usize = 0;
let mut error_mask: u64 = 0;
while idx < lenminus64 {
let input = SimdInput::new(input.get_unchecked(idx as usize..));
input.check_utf8(&mut state);
let odd_ends: u64 =
input.find_odd_backslash_sequences(&mut prev_iter_ends_odd_backslash);
let mut quote_bits: u64 = 0;
let quote_mask: u64 = input.find_quote_mask_and_bits(
odd_ends,
&mut prev_iter_inside_quote,
&mut quote_bits,
&mut error_mask,
);
#[allow(clippy::cast_possible_truncation)]
SimdInput::flatten_bits(&mut structural_indexes, idx as u32, structurals);
let mut whitespace: u64 = 0;
input.find_whitespace_and_structurals(&mut whitespace, &mut structurals);
structurals = SimdInput::finalize_structurals(
structurals,
whitespace,
quote_mask,
quote_bits,
&mut prev_iter_ends_pseudo_pred,
);
idx += SIMDINPUT_LENGTH;
}
if idx < len {
let mut tmpbuf: [u8; SIMDINPUT_LENGTH] = [0x20; SIMDINPUT_LENGTH];
tmpbuf
.as_mut_ptr()
.copy_from(input.as_ptr().add(idx), len as usize - idx);
let input = SimdInput::new(&tmpbuf);
input.check_utf8(&mut state);
let odd_ends: u64 =
input.find_odd_backslash_sequences(&mut prev_iter_ends_odd_backslash);
let mut quote_bits: u64 = 0;
let quote_mask: u64 = input.find_quote_mask_and_bits(
odd_ends,
&mut prev_iter_inside_quote,
&mut quote_bits,
&mut error_mask,
);
SimdInput::flatten_bits(&mut structural_indexes, idx as u32, structurals);
let mut whitespace: u64 = 0;
input.find_whitespace_and_structurals(&mut whitespace, &mut structurals);
structurals = SimdInput::finalize_structurals(
structurals,
whitespace,
quote_mask,
quote_bits,
&mut prev_iter_ends_pseudo_pred,
);
idx += SIMDINPUT_LENGTH;
}
if prev_iter_inside_quote != 0 {
return Err(ErrorType::Syntax);
}
SimdInput::flatten_bits(&mut structural_indexes, idx as u32, structurals);
if structural_indexes.len() == 1 {
return Err(ErrorType::EOF);
}
if structural_indexes.last() > Some(&(len as u32)) {
return Err(ErrorType::InternalError);
}
if error_mask != 0 {
return Err(ErrorType::Syntax);
}
if SimdInput::check_utf8_errors(&state) {
Err(ErrorType::InvalidUTF8)
} else {
Ok(structural_indexes)
}
}
}
#[cfg(test)]
mod tests {
#![allow(clippy::unnecessary_operation, clippy::non_ascii_literal)]
use super::{owned::Value, to_borrowed_value, to_owned_value, Deserializer};
use crate::tape::*;
use proptest::prelude::*;
use value_trait::{StaticNode, Writable};
#[test]
fn count1() {
let mut d = String::from("[]");
let mut d = unsafe { d.as_bytes_mut() };
let simd = Deserializer::from_slice(&mut d).expect("");
assert_eq!(simd.tape[1], Node::Array(0, 2));
}
#[test]
fn count2() {
let mut d = String::from("[1]");
let mut d = unsafe { d.as_bytes_mut() };
let simd = Deserializer::from_slice(&mut d).expect("");
assert_eq!(simd.tape[1], Node::Array(1, 3));
}
#[test]
fn count3() {
let mut d = String::from("[1,2]");
let mut d = unsafe { d.as_bytes_mut() };
let simd = Deserializer::from_slice(&mut d).expect("");
assert_eq!(simd.tape[1], Node::Array(2, 4));
}
#[test]
fn count4() {
let mut d = String::from(" [ 1 , [ 3 ] , 2 ]");
let mut d = unsafe { d.as_bytes_mut() };
let simd = Deserializer::from_slice(&mut d).expect("");
assert_eq!(simd.tape[1], Node::Array(3, 6));
assert_eq!(simd.tape[3], Node::Array(1, 5));
}
#[test]
fn count5() {
let mut d = String::from("[[],null,null]");
let mut d = unsafe { d.as_bytes_mut() };
let simd = Deserializer::from_slice(&mut d).expect("");
assert_eq!(simd.tape[1], Node::Array(3, 5));
assert_eq!(simd.tape[2], Node::Array(0, 3));
}
#[cfg(feature = "128bit")]
#[test]
fn odd_nuber() {
use super::value::owned::to_value;
use super::value::{Builder, Mutable};
let mut d = String::from(
r#"{"name": "max_unsafe_auto_id_timestamp", "value": -9223372036854776000}"#,
);
let mut d = unsafe { d.as_bytes_mut() };
let mut o = Value::object();
o.insert("name", "max_unsafe_auto_id_timestamp")
.expect("failed to set key");
o.insert("value", -9_223_372_036_854_776_000_i128)
.expect("failed to set key");
assert_eq!(to_value(&mut d), Ok(o));
}
#[cfg(feature = "128bit")]
#[test]
fn odd_nuber2() {
use super::value::owned::to_value;
use super::value::{Builder, Mutable};
let mut d = String::from(
r#"{"name": "max_unsafe_auto_id_timestamp", "value": 9223372036854776000}"#,
);
let mut d = unsafe { d.as_bytes_mut() };
let mut o = Value::object();
o.insert("name", "max_unsafe_auto_id_timestamp")
.expect("failed to set key");
o.insert("value", 9_223_372_036_854_776_000_u128)
.expect("failed to set key");
assert_eq!(to_value(&mut d), Ok(o));
}
#[test]
fn silly_float1() {
let v = Value::from(3.090_144_804_232_201_7e305);
let s = v.encode();
dbg!(&s);
let mut bytes = s.as_bytes().to_vec();
let parsed = to_owned_value(&mut bytes).expect("failed to parse gernated float");
assert_eq!(v, parsed);
}
#[test]
#[ignore]
fn silly_float2() {
let v = Value::from(-6.990_585_694_841_803e305);
let s = v.encode();
dbg!(&s);
let mut bytes = s.as_bytes().to_vec();
let parsed = to_owned_value(&mut bytes).expect("failed to parse gernated float");
assert_eq!(v, parsed);
}
#[cfg(not(feature = "128bit"))]
fn arb_json_value() -> BoxedStrategy<Value> {
let leaf = prop_oneof![
Just(Value::Static(StaticNode::Null)),
any::<bool>().prop_map(Value::from),
any::<i64>().prop_map(Value::from),
any::<u64>().prop_map(Value::from),
".*".prop_map(Value::from),
];
leaf.prop_recursive(
8,
256,
10,
|inner| {
prop_oneof![
prop::collection::vec(inner.clone(), 0..10).prop_map(Value::from),
prop::collection::hash_map(".*", inner, 0..10).prop_map(Value::from),
]
},
)
.boxed()
}
#[cfg(feature = "128bit")]
fn arb_json_value() -> BoxedStrategy<Value> {
let leaf = prop_oneof![
Just(Value::Static(StaticNode::Null)),
any::<bool>().prop_map(Value::from),
any::<i64>().prop_map(Value::from),
any::<u64>().prop_map(Value::from),
any::<i128>().prop_map(Value::from),
any::<u128>().prop_map(Value::from),
".*".prop_map(Value::from),
];
leaf.prop_recursive(
8,
256,
10,
|inner| {
prop_oneof![
prop::collection::vec(inner.clone(), 0..10).prop_map(Value::from),
prop::collection::hash_map(".*", inner, 0..10).prop_map(Value::from),
]
},
)
.boxed()
}
proptest! {
#![proptest_config(ProptestConfig {
.. ProptestConfig::default()
})]
#[test]
fn prop_json_encode_decode(val in arb_json_value()) {
let mut encoded: Vec<u8> = Vec::new();
let _ = val.write(&mut encoded);
println!("{}", String::from_utf8_lossy(&encoded.clone()));
let mut e = encoded.clone();
let res = to_owned_value(&mut e).expect("can't convert");
assert_eq!(val, res);
let mut e = encoded.clone();
let res = to_borrowed_value(&mut e).expect("can't convert");
assert_eq!(val, res);
#[cfg(not(feature = "128bit"))]
{
use crate::{deserialize, BorrowedValue, OwnedValue};
let mut e = encoded.clone();
let res: OwnedValue = deserialize(&mut e).expect("can't convert");
assert_eq!(val, res);
let mut e = encoded.clone();
let res: BorrowedValue = deserialize(&mut e).expect("can't convert");
assert_eq!(val, res);
}
}
}
}
#[cfg(feature = "serde_impl")]
#[cfg(test)]
mod tests_serde {
#![allow(clippy::unnecessary_operation, clippy::non_ascii_literal)]
use super::serde::from_slice;
use super::{owned::to_value, owned::Object, owned::Value, to_borrowed_value, to_owned_value};
use halfbrown::HashMap;
use proptest::prelude::*;
use serde::Deserialize;
use serde_json;
use value_trait::{Builder, Mutable, StaticNode};
#[test]
fn empty() {
let mut d = String::from("");
let mut d = unsafe { d.as_bytes_mut() };
let v_simd = from_slice::<Value>(&mut d);
let v_serde = serde_json::from_slice::<Value>(d);
assert!(v_simd.is_err());
assert!(v_serde.is_err());
}
#[test]
fn bool_true() {
let mut d = String::from("true");
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
assert_eq!(to_value(&mut d1), Ok(Value::from(true)));
}
#[test]
fn bool_false() {
let mut d = String::from("false");
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
assert_eq!(to_value(&mut d1), Ok(Value::from(false)));
}
#[test]
fn union() {
let mut d = String::from("null");
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
assert_eq!(to_value(&mut d1), Ok(Value::Static(StaticNode::Null)));
}
#[test]
fn int() {
let mut d = String::from("42");
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
assert_eq!(to_value(&mut d1), Ok(Value::from(42)));
}
#[test]
fn zero() {
let mut d = String::from("0");
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
assert_eq!(to_value(&mut d1), Ok(Value::from(0)));
}
#[test]
fn one() {
let mut d = String::from("1");
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
assert_eq!(to_value(&mut d1), Ok(Value::from(1)));
}
#[test]
fn minus_one() {
let mut d = String::from("-1");
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
assert_eq!(to_value(&mut d1), Ok(Value::from(-1)));
}
#[test]
fn float() {
let mut d = String::from("23.0");
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
assert_eq!(to_value(&mut d1), Ok(Value::from(23.0)));
}
#[test]
fn string() {
let mut d = String::from(r#""snot""#);
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(to_value(&mut d1), Ok(Value::from("snot")));
assert_eq!(v_simd, v_serde);
}
#[test]
fn lonely_quote() {
let mut d = String::from(r#"""#);
let mut d = unsafe { d.as_bytes_mut() };
let v_serde = serde_json::from_slice::<serde_json::Value>(d).is_err();
let v_simd = from_slice::<serde_json::Value>(&mut d).is_err();
assert!(v_simd);
assert!(v_serde);
}
#[test]
fn lonely_quote1() {
let mut d = String::from(r#"["]"#);
let mut d = unsafe { d.as_bytes_mut() };
let v_serde = serde_json::from_slice::<serde_json::Value>(d).is_err();
let v_simd = from_slice::<serde_json::Value>(&mut d).is_err();
assert!(v_simd);
assert!(v_serde);
}
#[test]
fn lonely_quote2() {
let mut d = String::from(r#"[1, "]"#);
let mut d = unsafe { d.as_bytes_mut() };
let v_serde = serde_json::from_slice::<serde_json::Value>(d).is_err();
let v_simd = from_slice::<serde_json::Value>(&mut d).is_err();
assert!(v_simd);
assert!(v_serde);
}
#[test]
fn lonely_quote3() {
let mut d = String::from(r#"{": 1}"#);
let mut d = unsafe { d.as_bytes_mut() };
let v_serde = serde_json::from_slice::<serde_json::Value>(d).is_err();
let v_simd = from_slice::<serde_json::Value>(&mut d).is_err();
assert!(v_simd);
assert!(v_serde);
}
#[test]
fn empty_string() {
let mut d = String::from(r#""""#);
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(to_value(&mut d1), Ok(Value::from("")));
assert_eq!(v_simd, v_serde);
}
#[test]
fn empty_array() {
let mut d = String::from(r#"[]"#);
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("parse_serde");
let v_simd: serde_json::Value = from_slice(&mut d).expect("parse_simd");
assert_eq!(to_value(&mut d1), Ok(Value::Array(vec![])));
assert_eq!(v_simd, v_serde);
}
#[test]
fn malformed_array() {
let mut d = String::from(r#"[["#);
let mut d1 = d.clone();
let mut d2 = d.clone();
let mut d = unsafe { d.as_bytes_mut() };
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d2 = unsafe { d2.as_bytes_mut() };
let v_serde: Result<serde_json::Value, _> = serde_json::from_slice(d);
let v_simd_ov = to_owned_value(&mut d);
let v_simd_bv = to_borrowed_value(&mut d1);
let v_simd: Result<serde_json::Value, _> = from_slice(&mut d2);
assert!(v_simd_ov.is_err());
assert!(v_simd_bv.is_err());
assert!(v_simd.is_err());
assert!(v_serde.is_err());
}
#[test]
fn double_array() {
let mut d = String::from(r#"[[]]"#);
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("parse_serde");
let v_simd: serde_json::Value = from_slice(&mut d).expect("parse_simd");
assert_eq!(
to_value(&mut d1),
Ok(Value::Array(vec![Value::Array(vec![])]))
);
assert_eq!(v_simd, v_serde);
}
#[test]
fn null_null_array() {
let mut d = String::from(r#"[[],null,null]"#);
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("parse_serde");
let v_simd: serde_json::Value = from_slice(&mut d).expect("parse_simd");
assert_eq!(
to_value(&mut d1),
Ok(Value::Array(vec![
Value::Array(vec![]),
Value::Static(StaticNode::Null),
Value::Static(StaticNode::Null),
]))
);
assert_eq!(v_simd, v_serde);
}
#[test]
fn one_element_array() {
let mut d = String::from(r#"["snot"]"#);
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
assert_eq!(
to_value(&mut d1),
Ok(Value::Array(vec![Value::from("snot")]))
);
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
}
#[test]
fn two_element_array() {
let mut d = String::from(r#"["snot", "badger"]"#);
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
assert_eq!(
to_value(&mut d1),
Ok(Value::Array(vec![
Value::from("snot"),
Value::from("badger")
]))
);
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
}
#[test]
fn list() {
let mut d = String::from(r#"[42, 23.0, "snot badger"]"#);
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
assert_eq!(
to_value(&mut d1),
Ok(Value::Array(vec![
Value::from(42),
Value::from(23.0),
Value::from("snot badger")
]))
);
}
#[test]
fn nested_list1() {
let mut d = String::from(r#"[42, [23.0, "snot"], "bad", "ger"]"#);
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
assert_eq!(
to_value(&mut d1),
Ok(Value::Array(vec![
Value::from(42),
Value::Array(vec![Value::from(23.0), Value::from("snot")]),
Value::from("bad"),
Value::from("ger")
]))
);
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
}
#[test]
fn nested_list2() {
let mut d = String::from(r#"[42, [23.0, "snot"], {"bad": "ger"}]"#);
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde)
}
#[test]
fn utf8() {
let mut d = String::from(r#""\u000e""#);
let mut d = unsafe { d.as_bytes_mut() };
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, "\u{e}");
}
#[test]
fn unicode() {
let mut d = String::from(r#""¡\"""#);
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
}
#[test]
fn odd_array() {
let mut d = String::from("[{},null]");
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
assert_eq!(
to_value(&mut d1),
Ok(Value::Array(vec![
Value::from(Object::new()),
Value::Static(StaticNode::Null)
]))
);
}
#[test]
fn min_i64() {
let mut d = String::from(
r#"{"name": "max_unsafe_auto_id_timestamp", "value": -9223372036854775808}"#,
);
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
let mut o = Value::object();
o.insert("name", "max_unsafe_auto_id_timestamp")
.expect("failed to set key");
o.insert("value", -9_223_372_036_854_775_808_i64)
.expect("failed to set key");
assert_eq!(to_value(&mut d1), Ok(o));
}
#[test]
fn map2() {
let mut d = String::from(r#"[{"\u0000":null}]"#);
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde)
}
#[test]
fn null() {
let mut d = String::from(r#"null"#);
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
assert_eq!(to_value(&mut d1), Ok(Value::Static(StaticNode::Null)));
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
}
#[test]
fn null_null() {
let mut d = String::from(r#"[null, null]"#);
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
assert_eq!(
to_value(&mut d1),
Ok(Value::Array(vec![
Value::Static(StaticNode::Null),
Value::Static(StaticNode::Null),
]))
);
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
}
#[test]
fn nested_null() {
let mut d = String::from(r#"[[null, null]]"#);
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
assert_eq!(
to_value(&mut d1),
Ok(Value::Array(vec![Value::Array(vec![
Value::Static(StaticNode::Null),
Value::Static(StaticNode::Null),
])]))
);
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
}
#[test]
fn nestednested_null() {
let mut d = String::from(r#"[[[null, null]]]"#);
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
assert_eq!(
to_value(&mut d1),
Ok(Value::Array(vec![Value::Array(vec![Value::Array(vec![
Value::Static(StaticNode::Null),
Value::Static(StaticNode::Null),
])])]))
);
}
#[test]
fn odd_array2() {
let mut d = String::from("[[\"\\u0000\\\"\"]]");
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde)
}
#[test]
fn odd_array3() {
let mut d = String::from("[{\"\\u0000\\u0000\":null}]");
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde)
}
#[test]
fn odd_array4() {
let mut d = String::from("[{\"\\u0000𐀀a\":null}]");
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde)
}
#[test]
fn float1() {
let mut d = String::from("2.3250706903316115e307");
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("serde_json");
let v_simd: serde_json::Value = from_slice(&mut d).expect("simd_json");
assert_eq!(v_simd, v_serde)
}
#[ignore]
#[test]
fn float2() {
let mut d = String::from("-4.5512678569607477e306");
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("serde_json");
let v_simd: serde_json::Value = from_slice(&mut d).expect("simd_json");
assert_eq!(v_simd, v_serde)
}
#[test]
fn map0() {
let mut d = String::from(r#"{"snot": "badger"}"#);
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
let mut h = Object::new();
h.insert("snot".into(), Value::from("badger"));
assert_eq!(dbg!(to_value(&mut d1)), Ok(Value::from(h)));
}
#[test]
fn map1() {
let mut d = String::from(r#"{"snot": "badger", "badger": "snot"}"#);
let mut d1 = d.clone();
let mut d1 = unsafe { d1.as_bytes_mut() };
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
let mut h = Object::new();
h.insert("snot".into(), Value::from("badger"));
h.insert("badger".into(), Value::from("snot"));
assert_eq!(to_value(&mut d1), Ok(Value::from(h)));
}
#[cfg(feature = "serde_impl")]
#[test]
fn tpl1() {
let mut d = String::from("[-65.613616999999977, 43.420273000000009]");
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: (f32, f32) = serde_json::from_slice(d).expect("serde_json");
let v_simd: (f32, f32) = from_slice(&mut d).expect("simd_json");
assert_eq!(v_simd, v_serde)
}
#[test]
fn tpl2() {
let mut d = String::from("[[-65.613616999999977, 43.420273000000009]]");
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: Vec<(f32, f32)> = serde_json::from_slice(d).expect("serde_json");
let v_simd: Vec<(f32, f32)> = from_slice(&mut d).expect("simd_json");
assert_eq!(v_simd, v_serde)
}
#[test]
fn tpl3() {
let mut d = String::from(
"[[-65.613616999999977,43.420273000000009], [-65.613616999999977,43.420273000000009]]",
);
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: Vec<(f32, f32)> = serde_json::from_slice(d).expect("serde_json");
let v_simd: Vec<(f32, f32)> = from_slice(&mut d).expect("simd_json");
assert_eq!(v_simd, v_serde)
}
#[test]
fn tpl4() {
let mut d = String::from("[[[-65.613616999999977,43.420273000000009]]]");
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: Vec<Vec<(f32, f32)>> = serde_json::from_slice(d).expect("serde_json");
let v_simd: Vec<Vec<(f32, f32)>> = from_slice(&mut d).expect("simd_json");
assert_eq!(v_simd, v_serde)
}
#[test]
fn tpl5() {
let mut d = String::from("[[[-65.613616999999977,43.420273000000009], [-65.613616999999977,43.420273000000009]]]");
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: Vec<Vec<(f32, f32)>> = serde_json::from_slice(d).expect("serde_json");
let v_simd: Vec<Vec<(f32, f32)>> = from_slice(&mut d).expect("simd_json");
assert_eq!(v_simd, v_serde)
}
#[test]
fn tpl6() {
let mut d = String::from("[[[[-65.613616999999977,43.420273000000009], [-65.613616999999977,43.420273000000009]]]]");
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: Vec<Vec<Vec<(f32, f32)>>> = serde_json::from_slice(d).expect("serde_json");
let v_simd: Vec<Vec<Vec<(f32, f32)>>> = from_slice(&mut d).expect("simd_json");
assert_eq!(v_simd, v_serde)
}
#[test]
fn tpl7() {
let mut d = String::from("[[[[-65.613616999999977,43.420273000000009], [-65.613616999999977,43.420273000000009]]]]");
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: Vec<Vec<Vec<[f32; 2]>>> = serde_json::from_slice(d).expect("serde_json");
let v_simd: Vec<Vec<Vec<[f32; 2]>>> = from_slice(&mut d).expect("simd_json");
assert_eq!(v_simd, v_serde)
}
#[derive(Deserialize, PartialEq, Debug)]
struct Obj {
a: u64,
b: u64,
}
#[derive(Deserialize, PartialEq, Debug)]
struct Obj1 {
a: Obj,
}
#[test]
fn obj1() {
let mut d = String::from(r#"{"a": 1, "b":1}"#);
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: Obj = serde_json::from_slice(d).expect("serde_json");
let v_simd: Obj = from_slice(&mut d).expect("simd_json");
assert_eq!(v_simd, v_serde)
}
#[test]
fn obj2() {
let mut d =
String::from(r#"{"a": {"a": 1, "b":1}, "b": {"a": 1, "b":1}, "c": {"a": 1, "b": 1}}"#);
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: HashMap<String, Obj> = serde_json::from_slice(d).expect("serde_json");
let v_simd: HashMap<String, Obj> = from_slice(&mut d).expect("simd_json");
assert_eq!(v_simd, v_serde)
}
#[test]
fn obj3() {
let mut d = String::from(
r#"{"c": {"a": {"a": 1, "b":1}, "b": {"a": 1, "b":1}, "c": {"a": 1, "b": 1}}}"#,
);
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: HashMap<String, HashMap<String, Obj>> =
serde_json::from_slice(d).expect("serde_json");
let v_simd: HashMap<String, HashMap<String, Obj>> = from_slice(&mut d).expect("simd_json");
assert_eq!(v_simd, v_serde)
}
#[test]
fn obj4() {
let mut d = String::from(r#"{"c": {"a": {"a": 1, "b":1}}}"#);
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: HashMap<String, Obj1> = serde_json::from_slice(d).expect("serde_json");
let v_simd: HashMap<String, Obj1> = from_slice(&mut d).expect("simd_json");
assert_eq!(v_simd, v_serde)
}
#[test]
fn vecvec() {
let mut d = String::from("[[[-65.613616999999977,43.420273000000009], [-65.613616999999977,43.420273000000009]], [[-65.613616999999977,43.420273000000009], [-65.613616999999977,43.420273000000009]]]");
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: Vec<Vec<(f32, f32)>> = serde_json::from_slice(d).expect("serde_json");
let v_simd: Vec<Vec<(f32, f32)>> = from_slice(&mut d).expect("simd_json");
assert_eq!(v_simd, v_serde)
}
#[test]
fn crazy_string() {
let d = "\"𐀀𐀀 𐀀𐀀0 𐀀A\\u00000A0 A \\u000b\"";
let mut d = String::from(d);
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("serde_json");
let v_simd: serde_json::Value = from_slice(&mut d).expect("simd_json");
assert_eq!(v_simd, v_serde)
}
#[cfg(feature = "serde_impl")]
#[test]
fn event() {
#[derive(Deserialize, Debug, PartialEq)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct CitmCatalog {
pub area_names: HashMap<String, String>,
pub audience_sub_category_names: HashMap<String, String>,
pub block_names: HashMap<String, String>,
pub events: HashMap<String, Event>,
}
pub type Id = u32;
#[derive(Deserialize, Debug, PartialEq)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct Event {
pub description: (),
pub id: Id,
pub logo: Option<String>,
pub name: String,
pub sub_topic_ids: Vec<Id>,
pub subject_code: (),
pub subtitle: (),
pub topic_ids: Vec<Id>,
}
let mut d = String::from(
r#"
{
"areaNames": {
"205705993": "Arrière-scène central",
"205705994": "1er balcon central",
"205705995": "2ème balcon bergerie cour",
"205705996": "2ème balcon bergerie jardin",
"205705998": "1er balcon bergerie jardin",
"205705999": "1er balcon bergerie cour",
"205706000": "Arrière-scène jardin",
"205706001": "Arrière-scène cour",
"205706002": "2ème balcon jardin",
"205706003": "2ème balcon cour",
"205706004": "2ème Balcon central",
"205706005": "1er balcon jardin",
"205706006": "1er balcon cour",
"205706007": "Orchestre central",
"205706008": "Orchestre jardin",
"205706009": "Orchestre cour",
"342752287": "Zone physique secrète"
},
"audienceSubCategoryNames": {
"337100890": "Abonné"
},
"blockNames": {},
"events": {
"138586341": {
"description": null,
"id": 138586341,
"logo": null,
"name": "30th Anniversary Tour",
"subTopicIds": [
337184269,
337184283
],
"subjectCode": null,
"subtitle": null,
"topicIds": [
324846099,
107888604
]
},
"138586345": {
"description": null,
"id": 138586345,
"logo": "/images/UE0AAAAACEKo6QAAAAZDSVRN",
"name": "Berliner Philharmoniker",
"subTopicIds": [
337184268,
337184283,
337184275
],
"subjectCode": null,
"subtitle": null,
"topicIds": [
324846099,
107888604,
324846100
]
}
}
}
"#,
);
let mut d = unsafe { d.as_bytes_mut() };
let v_serde: CitmCatalog = serde_json::from_slice(d).expect("serde_json");
let v_simd: CitmCatalog = from_slice(&mut d).expect("simd_json");
assert_eq!(v_simd, v_serde)
}
fn arb_json() -> BoxedStrategy<String> {
let leaf = prop_oneof![
Just(Value::Static(StaticNode::Null)),
any::<bool>()
.prop_map(StaticNode::Bool)
.prop_map(Value::Static),
any::<i64>().prop_map(Value::from),
".*".prop_map(Value::from),
];
leaf.prop_recursive(
8,
256,
10,
|inner| {
prop_oneof![
prop::collection::vec(inner.clone(), 0..10).prop_map(Value::from),
prop::collection::hash_map(".*", inner, 0..10).prop_map(Value::from),
]
},
)
.prop_map(|v| serde_json::to_string(&v).expect("").to_string())
.boxed()
}
proptest! {
#![proptest_config(ProptestConfig {
.. ProptestConfig::default()
})]
#[test]
fn prop_json(d in arb_json()) {
use super::{OwnedValue, deserialize};
if let Ok(v_serde) = serde_json::from_slice::<serde_json::Value>(&d.as_bytes()) {
let mut d1 = d.clone();
let d1 = unsafe{ d1.as_bytes_mut()};
let v_simd_serde: serde_json::Value = from_slice(d1).expect("");
let mut d2 = v_simd_serde.to_string();
let d2 = unsafe{ d2.as_bytes_mut()};
let mut d3 = d.clone();
let d3 = unsafe{ d3.as_bytes_mut()};
let mut d4 = d.clone();
let d4 = unsafe{ d4.as_bytes_mut()};
assert_eq!(v_simd_serde, v_serde);
let v_simd_owned = to_owned_value(d2).expect("to_owned_value failed");
let v_simd_borrowed = to_borrowed_value(d3).expect("to_borrowed_value failed");
assert_eq!(v_simd_borrowed, v_simd_owned);
let v_deserialize: OwnedValue = deserialize(d4).expect("deserialize failed");
assert_eq!(v_deserialize, v_simd_owned);
}
}
}
fn arb_junk() -> BoxedStrategy<Vec<u8>> {
prop::collection::vec(any::<u8>(), 0..(1024 * 8)).boxed()
}
proptest! {
#![proptest_config(ProptestConfig {
.. ProptestConfig::default()
})]
#[test]
fn prop_junk(d in arb_junk()) {
let mut d1 = d.clone();
let mut d2 = d.clone();
let mut d3 = d.clone();
let _ = from_slice::<serde_json::Value>(&mut d1);
let _ = to_borrowed_value(&mut d2);
let _ = to_owned_value(&mut d3);
}
}
proptest! {
#![proptest_config(ProptestConfig {
.. ProptestConfig::default()
})]
#[test]
fn prop_string(d in "\\PC*") {
let mut d1 = d.clone();
let mut d1 = unsafe{ d1.as_bytes_mut()};
let mut d2 = d.clone();
let mut d2 = unsafe{ d2.as_bytes_mut()};
let mut d3 = d.clone();
let mut d3 = unsafe{ d3.as_bytes_mut()};
let _ = from_slice::<serde_json::Value>(&mut d1);
let _ = to_borrowed_value(&mut d2);
let _ = to_owned_value(&mut d3);
}
}
}