test "5_int_factorial" do
assert parse_file("test_data/5_int_factorial.opt.wasm")
|> Enum.filter(fn {k, _} -> k == :section_type or k == :section_body end) ==
[
{:section_type, :type},
{:section_body, [{[:i32], [:i32]}]},
{:section_type, :function},
{:section_body, [0]},
{:section_type, :memory},
{:section_body, [{2, nil}]},
{:section_type, :global},
{:section_body,
[{{:i32, :const}, ["i32.const": 66560]}, {{:i32, :const}, ["i32.const": 1024]}]},
{:section_type, :export},
{:section_body,
[
{"memory", {:mem, 0}},
{"__heap_base", {:global, 0}},
{"__data_end", {:global, 1}},
{"factorial", {:func, 0}}
]},
{:section_type, :code},
{:section_body,
[
%{
code: %{
expr: [
{:"i32.const", 1},
{:"local.set", 1},
{:"local.get", 0},
{:"i32.const", 1},
:"i32.ge_s",
{:if,
%{
blocktype: :empty,
instr: [
loop: %{
blocktype: :empty,
instr: [
{:"local.get", 2},
{:"i32.const", 1},
:"i32.add",
{:"local.tee", 2},
{:"local.get", 1},
:"i32.mul",
{:"local.set", 1},
{:"local.get", 0},
{:"local.get", 2},
:"i32.ne",
{:br_if, 0}
]
}
]
}},
{:"local.get", 1}
],
locals: [%{num: 2, type: :i32}]
},
size: 40
}
]}
]
end