Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avm1: Remove all uses of static strings in tests code #19660

Merged
merged 7 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions core/src/avm1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ mod runtime;
mod scope;
mod value;

#[cfg(test)]
mod tests;

pub use activation::{Activation, ActivationIdentifier};
pub use debug::VariableDumper;
pub use error::Error;
Expand Down
121 changes: 0 additions & 121 deletions core/src/avm1/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,124 +188,3 @@ impl<'a> VariableDumper<'a> {
self.output.push('\n');
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::avm1::error::Error;
use crate::avm1::test_utils::with_avm;
use crate::avm1::ScriptObject;

#[test]
fn dump_undefined() {
with_avm(19, |activation, _root| -> Result<(), Error> {
assert_eq!(
VariableDumper::dump(&Value::Undefined, " ", activation),
"undefined"
);
Ok(())
})
}

#[test]
fn dump_null() {
with_avm(19, |activation, _root| -> Result<(), Error> {
assert_eq!(VariableDumper::dump(&Value::Null, " ", activation), "null");
Ok(())
})
}

#[test]
fn dump_bool() {
with_avm(19, |activation, _root| -> Result<(), Error> {
assert_eq!(VariableDumper::dump(&true.into(), " ", activation), "true");
assert_eq!(
VariableDumper::dump(&false.into(), " ", activation),
"false"
);
Ok(())
})
}

#[test]
fn dump_number() {
with_avm(19, |activation, _root| -> Result<(), Error> {
assert_eq!(VariableDumper::dump(&1000.into(), " ", activation), "1000");
assert_eq!(
VariableDumper::dump(&(-0.05).into(), " ", activation),
"-0.05"
);
Ok(())
})
}

#[test]
fn dump_string() {
with_avm(19, |activation, _root| -> Result<(), Error> {
assert_eq!(VariableDumper::dump(&"".into(), " ", activation), "\"\"");
assert_eq!(
VariableDumper::dump(&"HELLO WORLD".into(), " ", activation),
"\"HELLO WORLD\""
);
assert_eq!(
VariableDumper::dump(
&"Escape \"this\" string\nplease! \u{0008}\u{000C}\n\r\t\"\\".into(),
" ",
activation,
),
"\"Escape \\\"this\\\" string\\nplease! \\b\\f\\n\\r\\t\\\"\\\\\""
);
Ok(())
})
}

#[test]
fn dump_empty_object() {
with_avm(19, |activation, _root| -> Result<(), Error> {
let object = ScriptObject::new(activation.strings(), None);
assert_eq!(
VariableDumper::dump(&object.into(), " ", activation),
"[object #0] {}"
);
Ok(())
})
}

#[test]
fn dump_object() {
with_avm(19, |activation, _root| -> Result<(), Error> {
let object = ScriptObject::new(activation.strings(), None);
let child = ScriptObject::new(activation.strings(), None);
object.set("self", object.into(), activation)?;
object.set("test", "value".into(), activation)?;
object.set("child", child.into(), activation)?;
child.set("parent", object.into(), activation)?;
child.set("age", 6.into(), activation)?;
assert_eq!(
VariableDumper::dump(&object.into(), " ", activation),
"[object #0] {\n child: [object #1] {\n age: 6\n parent: [object #0]\n }\n test: \"value\"\n self: [object #0]\n}",
);
Ok(())
})
}

#[test]
fn dump_variables() {
with_avm(19, |activation, _root| -> Result<(), Error> {
let object = ScriptObject::new(activation.strings(), None);
let child = ScriptObject::new(activation.strings(), None);
object.set("self", object.into(), activation)?;
object.set("test", "value".into(), activation)?;
object.set("child", child.into(), activation)?;
child.set("parent", object.into(), activation)?;
child.set("age", 6.into(), activation)?;
let mut dumper = VariableDumper::new(" ");
dumper.print_variables("Variables:", "object", &object.into(), activation);
assert_eq!(
dumper.output,
"Variables:\nobject.child = [object #0] {\n age: 6\n parent: [object #1] {\n child: [object #0]\n test: \"value\"\n self: [object #1]\n }\n }\nobject.test = \"value\"\nobject.self = [object #1]\n\n"
);
Ok(())
})
}
}
178 changes: 0 additions & 178 deletions core/src/avm1/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,181 +1026,3 @@ pub fn remove_display_object<'gc>(this: DisplayObject<'gc>, activation: &mut Act
}
}
}

#[cfg(test)]
#[allow(clippy::unreadable_literal)]
mod tests {
use super::*;

fn setup<'gc>(activation: &mut Activation<'_, 'gc>) -> Object<'gc> {
create_globals(activation.strings()).1
}

test_method!(boolean_function, "Boolean", setup,
[19] => {
[true] => true,
[false] => false,
[10.0] => true,
[-10.0] => true,
[0.0] => false,
[f64::INFINITY] => true,
[f64::NAN] => false,
[""] => false,
["Hello"] => true,
[" "] => true,
["0"] => true,
["1"] => true,
[Value::Undefined] => false,
[Value::Null] => false,
[] => Value::Undefined
},
[6] => {
[true] => true,
[false] => false,
[10.0] => true,
[-10.0] => true,
[0.0] => false,
[f64::INFINITY] => true,
[f64::NAN] => false,
[""] => false,
["Hello"] => false,
[" "] => false,
["0"] => false,
["1"] => true,
[Value::Undefined] => false,
[Value::Null] => false,
[] => Value::Undefined
}
);

test_method!(is_nan_function, "isNaN", setup,
[19] => {
[true] => false,
[false] => false,
[10.0] => false,
[-10.0] => false,
[0.0] => false,
[f64::INFINITY] => false,
[f64::NAN] => true,
[""] => true,
["Hello"] => true,
[" "] => true,
[" 5 "] => true,
["0"] => false,
["1"] => false,
["Infinity"] => true,
["100a"] => true,
["0x10"] => false,
["0xhello"] => true,
["0x1999999981ffffff"] => false,
["0xUIXUIDFKHJDF012345678"] => true,
["123e-1"] => false,
[] => true
}
);

test_method!(is_finite, "isFinite", setup,
[19] => {
[true] => true,
[false] => true,
[10.0] => true,
[-10.0] => true,
[0.0] => true,
[f64::INFINITY] => false,
[f64::NEG_INFINITY] => false,
[f64::NAN] => false,
[""] => false,
["Hello"] => false,
[" "] => false,
[" 5 "] => false,
["0"] => true,
["1"] => true,
["Infinity"] => false,
["-Infinity"] => false,
["100a"] => false,
["0x10"] => true,
["0xhello"] => false,
["0x1999999981ffffff"] => true,
["0xUIXUIDFKHJDF012345678"] => false,
["123e-1"] => true,
[Value::Undefined] => false,
[Value::Null] => false,
[] => false
}
);

test_method!(number_function, "Number", setup,
[5, 6] => {
[true] => 1.0,
[false] => 0.0,
[10.0] => 10.0,
[-10.0] => -10.0,
["true"] => f64::NAN,
["false"] => f64::NAN,
[1.0] => 1.0,
[0.0] => 0.0,
[0.000] => 0.0,
["0.000"] => 0.0,
["True"] => f64::NAN,
["False"] => f64::NAN,
[f64::NAN] => f64::NAN,
[f64::INFINITY] => f64::INFINITY,
[f64::NEG_INFINITY] => f64::NEG_INFINITY,
[" 12"] => 12.0,
[" \t\r\n12"] => 12.0,
["\u{A0}12"] => f64::NAN,
[" 0x12"] => f64::NAN,
["01.2"] => 1.2,
[""] => f64::NAN,
["Hello"] => f64::NAN,
[" "] => f64::NAN,
[" 5 "] => f64::NAN,
["0"] => 0.0,
["1"] => 1.0,
["Infinity"] => f64::NAN,
["-Infinity"] => f64::NAN,
["inf"] => f64::NAN,
["-inf"] => f64::NAN,
["100a"] => f64::NAN,
["0xhello"] => f64::NAN,
["123e-1"] => 12.3,
["0xUIXUIDFKHJDF012345678"] => f64::NAN,
[] => 0.0
},
[5] => {
["0x12"] => f64::NAN,
["0x10"] => f64::NAN,
["0x1999999981ffffff"] => f64::NAN,
["010"] => 10,
["-010"] => -10,
["+010"] => 10,
[" 010"] => 10,
[" -010"] => -10,
[" +010"] => 10,
["037777777777"] => 37777777777.0,
["-037777777777"] => -37777777777.0
},
[6, 7] => {
["0x12"] => 18.0,
["0x10"] => 16.0,
["-0x10"] => f64::NAN,
["0x1999999981ffffff"] => -2113929217.0,
["010"] => 8,
["-010"] => -8,
["+010"] => 8,
[" 010"] => 10,
[" -010"] => -10,
[" +010"] => 10,
["037777777777"] => -1,
["-037777777777"] => 1
},
[5, 6] => {
[Value::Undefined] => 0.0,
[Value::Null] => 0.0
},
[7] => {
[Value::Undefined] => f64::NAN,
[Value::Null] => f64::NAN
}
);
}
3 changes: 0 additions & 3 deletions core/src/avm1/globals/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ mod tests {
[f64::NAN] => f64::NAN,
[Value::Null] => f64::NAN,
[Value::Undefined] => f64::NAN,
["5"] => f64::NAN,
[1.0, 2.0] => 1.0,
[3.0, 2.0, 1.0] => 9.0
},
Expand Down Expand Up @@ -361,7 +360,6 @@ mod tests {
[f64::NAN] => f64::NAN,
[Value::Null] => f64::NAN,
[Value::Undefined] => f64::NAN,
["5"] => f64::NAN,
[1.0, 2.0] => 2.0,
[3.0, 2.0, 1.0] => 3.0
},
Expand All @@ -382,7 +380,6 @@ mod tests {
[f64::NAN] => f64::NAN,
[Value::Null] => f64::NAN,
[Value::Undefined] => f64::NAN,
["5"] => f64::NAN,
[1.0, 2.0] => 1.0,
[3.0, 2.0, 1.0] => 2.0
},
Expand Down
Loading