Skip to content

Add second test case to binaryenopt #177

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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);
}
}