Skip to content

Commit 0812ece

Browse files
authored
Merge pull request #444 from wasmx/module-tests
Unit tests for module helpers
2 parents 17e499f + 052149f commit 0812ece

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

test/unittests/module_test.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,27 @@
1010
using namespace fizzy;
1111
using namespace fizzy::test;
1212

13+
TEST(module, functions)
14+
{
15+
/* wat2wasm
16+
(func (import "m" "f1") (param i32 i32) (result i32))
17+
(func)
18+
(func (param i64))
19+
(func (result f32) (f32.const 0))
20+
*/
21+
const auto bin = from_hex(
22+
"0061736d0100000001120460027f7f017f60000060017e006000017d020801016d02663100000304030102030a"
23+
"0f0302000b02000b070043000000000b");
24+
const auto module = parse(bin);
25+
26+
ASSERT_EQ(module.get_function_count(), 4);
27+
EXPECT_EQ(
28+
module.get_function_type(0), (FuncType{{ValType::i32, ValType::i32}, {ValType::i32}}));
29+
EXPECT_EQ(module.get_function_type(1), (FuncType{}));
30+
EXPECT_EQ(module.get_function_type(2), (FuncType{{ValType::i64}, {}}));
31+
EXPECT_EQ(module.get_function_type(3), (FuncType{{}, {ValType::f32}}));
32+
}
33+
1334
TEST(module, globals)
1435
{
1536
/* wat2wasm
@@ -33,3 +54,57 @@ TEST(module, globals)
3354
EXPECT_EQ(module.get_global_type(3).value_type, ValType::f64);
3455
EXPECT_TRUE(module.get_global_type(3).is_mutable);
3556
}
57+
58+
TEST(module, table)
59+
{
60+
/* wat2wasm
61+
(table 1 funcref)
62+
*/
63+
const auto bin1 = from_hex("0061736d01000000040401700001");
64+
const auto module1 = parse(bin1);
65+
66+
EXPECT_TRUE(module1.has_table());
67+
68+
/* wat2wasm
69+
(table (import "m" "t") 1 funcref)
70+
*/
71+
const auto bin2 = from_hex("0061736d01000000020901016d017401700001");
72+
const auto module2 = parse(bin2);
73+
74+
EXPECT_TRUE(module2.has_table());
75+
76+
/* wat2wasm
77+
(module)
78+
*/
79+
const auto bin3 = from_hex("0061736d01000000");
80+
const auto module3 = parse(bin3);
81+
82+
EXPECT_FALSE(module3.has_table());
83+
}
84+
85+
TEST(module, memory)
86+
{
87+
/* wat2wasm
88+
(memory 1)
89+
*/
90+
const auto bin1 = from_hex("0061736d010000000503010001");
91+
const auto module1 = parse(bin1);
92+
93+
EXPECT_TRUE(module1.has_memory());
94+
95+
/* wat2wasm
96+
(memory (import "m" "m") 1)
97+
*/
98+
const auto bin2 = from_hex("0061736d01000000020801016d016d020001");
99+
const auto module2 = parse(bin2);
100+
101+
EXPECT_TRUE(module2.has_memory());
102+
103+
/* wat2wasm
104+
(module)
105+
*/
106+
const auto bin3 = from_hex("0061736d01000000");
107+
const auto module3 = parse(bin3);
108+
109+
EXPECT_FALSE(module3.has_memory());
110+
}

0 commit comments

Comments
 (0)