Skip to content
Open
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
23 changes: 23 additions & 0 deletions libchisel/src/binaryenopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ fn binaryen_optimiser(
#[cfg(test)]
mod tests {
use super::*;
use rustc_hex::FromHex;

#[test]
fn smoke_test_o0() {
Expand All @@ -137,4 +138,26 @@ mod tests {
let serialized = result.to_bytes().unwrap();
assert_eq!(expected, serialized);
}

#[test]
fn test_keep_names_section() {
let input = FromHex::from_hex(
"0061736d010000000104016000000303020000070801046d61696e00010a
0a020300010b040010000b0014046e616d65010d0200047465737401046d
61696e",
)
.unwrap();
let module = Module::from_bytes(&input)
.unwrap()
.parse_names()
.expect("parsing the names section failed");
assert_eq!(module.has_names_section(), true);

let translator = BinaryenOptimiser::with_preset("O0").unwrap();
let result = translator.translate(&module).unwrap().unwrap();
assert_eq!(result.has_names_section(), true);

let output = result.to_bytes().unwrap();
assert_eq!(input, output);
}
}