message: Add parser test for element section
diff: @@ -457,6 +457,42 @@ TEST(parser, start)
  EXPECT_EQ(*module.startfunc, 7);
  }
  +TEST(parser, element_section)
  +{
  + const auto table_contents = bytes{0x01, 0x70, 0x00, 0x7f};
  + const auto element_contents = make_vec({bytes{0x00, 0x41, 0x01, 0x0b, 0x02, 0x7f, 0x7f},
  + bytes{0x00, 0x41, 0x02, 0x0b, 0x02, 0x55, 0x55},
  + bytes{0x00, 0x23, 0x00, 0x0b, 0x02, 0x24, 0x24}});
  + const auto bin =
  + bytes{wasm_prefix} + make_section(4, table_contents) + make_section(9, element_contents);
  +
  + const auto module = parse(bin);
  + ASSERT_EQ(module.elementsec.size(), 3);
  + EXPECT_EQ(module.elementsec[0].offset.kind, ConstantExpression::Kind::Constant);
  + EXPECT_EQ(module.elementsec[0].offset.value.constant, 1);
  + ASSERT_EQ(module.elementsec[0].init.size(), 2);
  + EXPECT_EQ(module.elementsec[0].init[0], 0x7f);
  + EXPECT_EQ(module.elementsec[0].init[1], 0x7f);
  + EXPECT_EQ(module.elementsec[1].offset.kind, ConstantExpression::Kind::Constant);
  + EXPECT_EQ(module.elementsec[1].offset.value.constant, 2);
  + ASSERT_EQ(module.elementsec[1].init.size(), 2);
  + EXPECT_EQ(module.elementsec[1].init[0], 0x55);
  + EXPECT_EQ(module.elementsec[1].init[1], 0x55);
  + EXPECT_EQ(module.elementsec[2].offset.kind, ConstantExpression::Kind::GlobalGet);
  + EXPECT_EQ(module.elementsec[2].offset.value.global_index, 0);
  + ASSERT_EQ(module.elementsec[2].init.size(), 2);
  + EXPECT_EQ(module.elementsec[2].init[0], 0x24);
  + EXPECT_EQ(module.elementsec[2].init[1], 0x24);
  +}
  +
  +TEST(parser, element_section_tableidx_nonzero)
  +{
  + const auto section_contents = bytes{0x01, 0x01, 0x41, 0x01, 0x0b, 0x01, 0x00};
  + const auto bin = bytes{wasm_prefix} + make_section(9, section_contents);
  +
  + EXPECT_THROW_MESSAGE(parse(bin), parser_error, "unexpected tableidx value 1");
  +}
  +
  TEST(parser, code_with_empty_expr_2_locals)
  {
  // Func with 2x i32 locals, only 0x0b "end" instruction.
  @@ -550,7 +586,7 @@ TEST(parser, data_section_memidx_nonzero)
  const auto section_contents = make_vec({"0141010b0100"_bytes});
  const auto bin = bytes{wasm_prefix} + make_section(11, section_contents);
  - EXPECT_THROW(parse({}), parser_error);
  + EXPECT_THROW_MESSAGE(parse(bin), parser_error, "unexpected memidx value 1");
  }
  TEST(parser, milestone1)
  