defmodule WaParserTest do
  use ExUnit.Case
  def parse_file(filename) do
    filename
    |> File.read!()
    |> WaParser.stream()
    |> Enum.to_list()
  end
  test "0_return_0" do
    assert parse_file("test_data/0_return_0.opt.wasm") ==
             [
               {:magic, <<0, 97, 115, 109>>},
               {:version, <<1, 0, 0, 0>>},
               {:section_id, 1},
               {:section_type, :type},
               {:section_length, 5},
               {:section_body, [{[], [:i32]}]},
               {:section_id, 3},
               {:section_type, :function},
               {:section_length, 2},
               {:section_body, [0]},
               {:section_id, 5},
               {:section_type, :memory},
               {:section_length, 3},
               {:section_body, [{2, nil}]},
               {:section_id, 6},
               {:section_type, :global},
               {:section_length, 14},
               {:section_body,
                [{{:i32, :const}, ["i32.const": 66560]}, {{:i32, :const}, ["i32.const": 1024]}]},
               {:section_id, 7},
               {:section_type, :export},
               {:section_length, 48},
               {:section_body,
                [
                  {"memory", {:mem, 0}},
                  {"__heap_base", {:global, 0}},
                  {"__data_end", {:global, 1}},
                  {"return_0", {:func, 0}}
                ]},
               {:section_id, 10},
               {:section_type, :code},
               {:section_length, 6},
               {:section_body, [%{code: %{expr: ["i32.const": 0], locals: []}, size: 4}]}
             ]
  end
end