This commit is contained in:
parent
88ae866b91
commit
10c862de59
3 changed files with 15 additions and 7 deletions
|
|
@ -289,7 +289,7 @@ impl DataValue {
|
|||
pub fn as_number(&self) -> Option<i128> {
|
||||
match self {
|
||||
DataValue::SignedNumber(n) => Some(*n),
|
||||
DataValue::UnsignedNumber(n) => Some(*n as i128),
|
||||
DataValue::UnsignedNumber(n) => i128::try_from(*n).ok(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -1232,6 +1232,18 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsigned_number_conversion_rejects_i128_overflow() {
|
||||
assert_eq!(
|
||||
DataValue::UnsignedNumber(i128::MAX as u128).as_number(),
|
||||
Some(i128::MAX)
|
||||
);
|
||||
assert_eq!(
|
||||
DataValue::UnsignedNumber(i128::MAX as u128 + 1).as_number(),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_container_and_array_have_distinct_framing() {
|
||||
let container = DataValue::Container(vec![])
|
||||
|
|
|
|||
Loading…
Reference in a new issue