more zval cast tests

This commit is contained in:
Robin Appelman 2019-04-05 21:27:35 +02:00
commit caf346e4c7
2 changed files with 25 additions and 2 deletions

View file

@ -204,7 +204,7 @@ impl From<u8> for ZValType {
}
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
pub enum ArrayKey {
String(String),
Int(u64),
@ -227,7 +227,7 @@ impl_from_array_key!(u16, Int, u64);
impl_from_array_key!(u8, Int, u64);
impl_from_array_key!(usize, Int, u64);
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum PhpVal {
Undef,
Null,

View file

@ -1,6 +1,7 @@
use maplit::hashmap;
use pretty_assertions::assert_eq;
use ivory::zend::ZVal;
use ivory::{ArrayKey, PhpVal};
#[test]
@ -66,3 +67,25 @@ fn cast_into_php_val() {
.into()
);
}
#[test]
fn cast_into_php_val_round_trip() {
let values: Vec<PhpVal> = vec![
1.into(),
(0.2).into(),
true.into(),
false.into(),
"foo".to_string().into(),
];
for original in values {
let first_cast: ZVal = original.clone().into();
let cast_back: PhpVal = first_cast.as_php_val();
assert_eq!(original, cast_back);
// the first round trip should cast back into the same round trip
let second_cast: ZVal = cast_back.into();
let cast_back: PhpVal = second_cast.as_php_val();
assert_eq!(original, cast_back);
}
}