Skip to content

Commit

Permalink
avm1: Add a way to specify numeric tolerance @epsilon when comparin…
Browse files Browse the repository at this point in the history
…g in `test_method!`
  • Loading branch information
torokati44 committed Aug 11, 2024
1 parent 47030b4 commit 056501e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion core/src/avm1/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
$(
Expand All @@ -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);
)*

Expand Down

0 comments on commit 056501e

Please sign in to comment.