use super::super::*;
#[test]
fn high_level_lifts_local_slots() {
let script = [0x57, 0x01, 0x00, 0x11, 0x70, 0x68, 0x40];
let nef_bytes = build_nef(&script);
let decompilation = Decompiler::new()
.decompile_bytes(&nef_bytes)
.expect("decompile succeeds");
let high_level = decompilation
.high_level
.as_deref()
.expect("high-level output");
assert!(high_level.contains("// declare 1 locals, 0 arguments"));
assert!(
high_level.contains("let loc0 = 1;"),
"expected collapsed store: {high_level}"
);
assert!(high_level.contains("return loc0;"));
}
#[test]
fn high_level_lifts_all_local_slot_variants() {
let script = [
0x57, 0x07, 0x00, 0x10, 0x70, 0x11, 0x71, 0x12, 0x72, 0x13, 0x73, 0x14, 0x74, 0x15, 0x75, 0x16, 0x76, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x40, ];
let nef_bytes = build_nef(&script);
let decompilation = Decompiler::new()
.decompile_bytes(&nef_bytes)
.expect("decompile succeeds");
let high_level = decompilation
.high_level
.as_deref()
.expect("high-level output");
assert!(
high_level.contains("// declare 7 locals, 0 arguments"),
"should declare 7 locals: {high_level}"
);
for i in 0..7 {
assert!(
high_level.contains(&format!("loc{i}")),
"local slot {i} should appear in output: {high_level}"
);
}
}
#[test]
fn high_level_lifts_all_argument_slot_variants() {
let script = [
0x57, 0x00, 0x07, 0x78, 0x80, 0x79, 0x81, 0x7A, 0x82, 0x7B, 0x83, 0x7C, 0x84, 0x7D, 0x85, 0x7E, 0x86, 0x40, ];
let nef_bytes = build_nef(&script);
let decompilation = Decompiler::new()
.decompile_bytes(&nef_bytes)
.expect("decompile succeeds");
let high_level = decompilation
.high_level
.as_deref()
.expect("high-level output");
assert!(
high_level.contains("// declare 0 locals, 7 arguments"),
"should declare 7 arguments: {high_level}"
);
for i in 0..7 {
assert!(
high_level.contains(&format!("arg{i}")),
"argument slot {i} should appear in output: {high_level}"
);
}
}
#[test]
fn high_level_lifts_indexed_local_slot() {
let script = [
0x57, 0x08, 0x00, 0x11, 0x77, 0x07, 0x6F, 0x07, 0x40, ];
let nef_bytes = build_nef(&script);
let decompilation = Decompiler::new()
.decompile_bytes(&nef_bytes)
.expect("decompile succeeds");
let high_level = decompilation
.high_level
.as_deref()
.expect("high-level output");
assert!(
high_level.contains("loc7"),
"indexed LDLOC/STLOC should reference loc7: {high_level}"
);
}
#[test]
fn high_level_lifts_indexed_argument_slot() {
let script = [
0x57, 0x00, 0x08, 0x7F, 0x07, 0x11, 0x87, 0x07, 0x40, ];
let nef_bytes = build_nef(&script);
let decompilation = Decompiler::new()
.decompile_bytes(&nef_bytes)
.expect("decompile succeeds");
let high_level = decompilation
.high_level
.as_deref()
.expect("high-level output");
assert!(
high_level.contains("arg7"),
"indexed LDARG/STARG should reference arg7: {high_level}"
);
}