Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed May 30, 2020
1 parent 46d5ddf commit 2320ef5
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions test/unittests/parser_expr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ namespace
const Module ModuleWithSingleFunction = {
{FuncType{{}, {}}}, {}, {0}, {}, {}, {}, {}, std::nullopt, {}, {}, {}, {}, {}, {}, {}};

inline auto parse_expr(
const bytes& input, FuncIdx func_idx = 0, const Module& module = ModuleWithSingleFunction)
inline auto parse_expr(const bytes& input, uint32_t locals_count = 0, FuncIdx func_idx = 0,
const Module& module = ModuleWithSingleFunction)
{
return fizzy::parse_expr(input.data(), input.data() + input.size(), func_idx, module);
return fizzy::parse_expr(
input.data(), input.data() + input.size(), locals_count, func_idx, module);
}
} // namespace

Expand Down Expand Up @@ -184,7 +185,7 @@ TEST(parser_expr, block_br)
// end

const auto code_bin = "010240410a21010c00410b21010b20011a0b"_bytes;
const auto [code, pos] = parse_expr(code_bin);
const auto [code, pos] = parse_expr(code_bin, 2);
EXPECT_EQ(
code.instructions, (std::vector{Instr::nop, Instr::block, Instr::i32_const,
Instr::local_set, Instr::br, Instr::i32_const, Instr::local_set,
Expand Down Expand Up @@ -467,11 +468,11 @@ TEST(parser_expr, call_indirect_table_index)
module.tablesec.emplace_back(Table{{1, 1}});

const auto code1_bin = i32_const(0) + "1100000b"_bytes;
const auto [code, pos] = parse_expr(code1_bin, 0, module);
const auto [code, pos] = parse_expr(code1_bin, 0, 0, module);
EXPECT_EQ(code.instructions, (std::vector{Instr::i32_const, Instr::call_indirect, Instr::end}));

const auto code2_bin = i32_const(0) + "1100010b"_bytes;
EXPECT_THROW_MESSAGE(parse_expr(code2_bin, 0, module), parser_error,
EXPECT_THROW_MESSAGE(parse_expr(code2_bin, 0, 0, module), parser_error,
"invalid tableidx encountered with call_indirect");
}

Expand All @@ -494,7 +495,7 @@ TEST(parser_expr, immediate_leb128_out_of_bounds)
Instr::call_indirect, Instr::i32_const, Instr::i64_const})
{
const auto code = i32_const(0) + i32_const(0) + bytes{uint8_t(instr), 0x99};
EXPECT_THROW_MESSAGE(parse_expr(code, 0, module), parser_error, "unexpected EOF");
EXPECT_THROW_MESSAGE(parse_expr(code, 0, 0, module), parser_error, "unexpected EOF");
}
}

Expand Down Expand Up @@ -539,7 +540,7 @@ TEST(parser_expr, call_indirect_out_of_bounds)
module.tablesec.emplace_back(Table{{1, 1}});

EXPECT_THROW_MESSAGE(
parse_expr(i32_const(0) + "1100"_bytes, 0, module), parser_error, "unexpected EOF");
parse_expr(i32_const(0) + "1100"_bytes, 0, 0, module), parser_error, "unexpected EOF");
}

TEST(parser_expr, memory_grow_out_of_bounds)
Expand Down

0 comments on commit 2320ef5

Please sign in to comment.