Skip to content

Commit 5d210b2

Browse files
committed
Add second test case to binaryenopt
1 parent b56815a commit 5d210b2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

libchisel/src/binaryenopt.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ fn binaryen_optimiser(
116116
#[cfg(test)]
117117
mod tests {
118118
use super::*;
119+
use rustc_hex::FromHex;
119120

120121
#[test]
121122
fn smoke_test_o0() {
@@ -137,4 +138,26 @@ mod tests {
137138
let serialized = result.to_bytes().unwrap();
138139
assert_eq!(expected, serialized);
139140
}
141+
142+
#[test]
143+
fn test_keep_names_section() {
144+
let input = FromHex::from_hex(
145+
"0061736d010000000104016000000303020000070801046d61696e00010a
146+
0a020300010b040010000b0014046e616d65010d0200047465737401046d
147+
61696e",
148+
)
149+
.unwrap();
150+
let module = Module::from_bytes(&input)
151+
.unwrap()
152+
.parse_names()
153+
.expect("parsing the names section failed");
154+
assert_eq!(module.has_names_section(), true);
155+
156+
let translator = BinaryenOptimiser::with_preset("O0").unwrap();
157+
let result = translator.translate(&module).unwrap().unwrap();
158+
assert_eq!(result.has_names_section(), true);
159+
160+
let output = result.to_bytes().unwrap();
161+
assert_eq!(input, output);
162+
}
140163
}

0 commit comments

Comments
 (0)