Skip to content

Commit

Permalink
test: module helper methods tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Jul 29, 2020
1 parent 17e499f commit 052149f
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions test/unittests/module_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@
using namespace fizzy;
using namespace fizzy::test;

TEST(module, functions)
{
/* wat2wasm
(func (import "m" "f1") (param i32 i32) (result i32))
(func)
(func (param i64))
(func (result f32) (f32.const 0))
*/
const auto bin = from_hex(
"0061736d0100000001120460027f7f017f60000060017e006000017d020801016d02663100000304030102030a"
"0f0302000b02000b070043000000000b");
const auto module = parse(bin);

ASSERT_EQ(module.get_function_count(), 4);
EXPECT_EQ(
module.get_function_type(0), (FuncType{{ValType::i32, ValType::i32}, {ValType::i32}}));
EXPECT_EQ(module.get_function_type(1), (FuncType{}));
EXPECT_EQ(module.get_function_type(2), (FuncType{{ValType::i64}, {}}));
EXPECT_EQ(module.get_function_type(3), (FuncType{{}, {ValType::f32}}));
}

TEST(module, globals)
{
/* wat2wasm
Expand All @@ -33,3 +54,57 @@ TEST(module, globals)
EXPECT_EQ(module.get_global_type(3).value_type, ValType::f64);
EXPECT_TRUE(module.get_global_type(3).is_mutable);
}

TEST(module, table)
{
/* wat2wasm
(table 1 funcref)
*/
const auto bin1 = from_hex("0061736d01000000040401700001");
const auto module1 = parse(bin1);

EXPECT_TRUE(module1.has_table());

/* wat2wasm
(table (import "m" "t") 1 funcref)
*/
const auto bin2 = from_hex("0061736d01000000020901016d017401700001");
const auto module2 = parse(bin2);

EXPECT_TRUE(module2.has_table());

/* wat2wasm
(module)
*/
const auto bin3 = from_hex("0061736d01000000");
const auto module3 = parse(bin3);

EXPECT_FALSE(module3.has_table());
}

TEST(module, memory)
{
/* wat2wasm
(memory 1)
*/
const auto bin1 = from_hex("0061736d010000000503010001");
const auto module1 = parse(bin1);

EXPECT_TRUE(module1.has_memory());

/* wat2wasm
(memory (import "m" "m") 1)
*/
const auto bin2 = from_hex("0061736d01000000020801016d016d020001");
const auto module2 = parse(bin2);

EXPECT_TRUE(module2.has_memory());

/* wat2wasm
(module)
*/
const auto bin3 = from_hex("0061736d01000000");
const auto module3 = parse(bin3);

EXPECT_FALSE(module3.has_memory());
}

0 comments on commit 052149f

Please sign in to comment.