#![allow(clippy::unwrap_used, clippy::expect_used)]
use blob_decoder::v8_value::{deserialize, V8Value};
#[test]
fn utf8_string_tag_decodes() {
let bytes = [0xFF, 0x0F, 0x53, 0x02, 0x68, 0x69];
assert_eq!(
deserialize(&bytes).unwrap(),
V8Value::String("hi".to_owned())
);
}
#[test]
fn shared_reference_to_map_is_resolved() {
let bytes = [
0xFF, 0x0F, 0x41, 0x02, 0x3B, 0x49, 0x02, 0x49, 0x04, 0x3A, 0x02, 0x5E, 0x01, 0x24, 0x00,
0x02,
];
let map = V8Value::Map(vec![(V8Value::Int(1), V8Value::Int(2))]);
assert_eq!(
deserialize(&bytes).unwrap(),
V8Value::Array(vec![map.clone(), map])
);
}
#[test]
fn summary_ellipsizes_long_strings() {
let short = V8Value::String("hello".to_owned()).summary();
assert!(short.contains("hello"));
assert!(
!short.contains('…'),
"short string must not be truncated: {short}"
);
let long = V8Value::String("a".repeat(40)).summary();
assert!(
long.contains('…'),
"40-char string must be ellipsized: {long}"
);
}