avm1: Add a way to specify numeric tolerance `@epsilon` when comparing in `test_method!`
This commit is contained in:
parent
47030b4f5b
commit
056501ee75
|
@ -30,8 +30,9 @@ where
|
|||
}
|
||||
|
||||
macro_rules! test_method {
|
||||
( $test: ident, $name: expr, $object: expr, $($versions: expr => { $([$($arg: expr),*] => $out: expr),* }),* ) => {
|
||||
( $test: ident, $name: expr, $object: expr, $($versions: expr => { $( $(@epsilon($epsilon: expr))? [$($arg: expr),*] => $out: expr),* }),* ) => {
|
||||
#[test]
|
||||
#[allow(unreachable_code)] // the `assert_eq!` at the end, in expansions without `@epsilon`
|
||||
fn $test() {
|
||||
use $crate::avm1::test_utils::*;
|
||||
$(
|
||||
|
@ -43,6 +44,13 @@ macro_rules! test_method {
|
|||
$(
|
||||
let args: Vec<Value> = vec![$($arg.into()),*];
|
||||
let ret = crate::avm1::object::TObject::call_method(&object, name, &args, activation, crate::avm1::function::ExecutionReason::Special)?;
|
||||
|
||||
// Do a numeric comparison with tolerance if `@epsilon` was given:
|
||||
$(
|
||||
assert!(f64::abs($out as f64 - ret.coerce_to_f64(activation)?) < $epsilon as f64, "@epsilon({:?}) {:?} => {:?} in swf {}", $epsilon, args, $out, version);
|
||||
return Ok(());
|
||||
)?
|
||||
// Else, do a generic equality comparison:
|
||||
assert_eq!(ret, $out.into(), "{:?} => {:?} in swf {}", args, $out, version);
|
||||
)*
|
||||
|
||||
|
|
Loading…
Reference in New Issue