Skip to content

Commit a0651c0

Browse files
committed
feat: Implement tests for Literal
1 parent c33c9be commit a0651c0

File tree

3 files changed

+118
-3
lines changed

3 files changed

+118
-3
lines changed

test/literal_test.re

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
open Binaryen;
2+
open Frame_work;
3+
4+
suite("Literal", () => {
5+
let create_test_func = (wasm_mod, name, lit) => {
6+
Function.add_function(
7+
wasm_mod,
8+
name,
9+
Type.none,
10+
Type.none,
11+
[||],
12+
Expression.Drop.make(wasm_mod, Expression.Const.make(wasm_mod, lit)),
13+
);
14+
};
15+
test("int32", () => {
16+
let wasm_mod = Module.create();
17+
let _ = create_test_func(wasm_mod, "int32_test", Literal.int32(42l));
18+
Printf.printf("%s", Module.write_text(wasm_mod));
19+
Module.dispose(wasm_mod);
20+
});
21+
test("int64", () => {
22+
let wasm_mod = Module.create();
23+
let _ = create_test_func(wasm_mod, "int64_test", Literal.int64(-35L));
24+
Printf.printf("%s", Module.write_text(wasm_mod));
25+
Module.dispose(wasm_mod);
26+
});
27+
test("float32_bits", () => {
28+
let wasm_mod = Module.create();
29+
let _ =
30+
create_test_func(
31+
wasm_mod,
32+
"float32_bits_test",
33+
Literal.float32_bits(0x40900000l),
34+
); // 4.5
35+
Printf.printf("%s", Module.write_text(wasm_mod));
36+
Module.dispose(wasm_mod);
37+
});
38+
test("float64_bits", () => {
39+
let wasm_mod = Module.create();
40+
let _ =
41+
create_test_func(
42+
wasm_mod,
43+
"float64_bits_test",
44+
Literal.float64_bits(0x4012000000000000L),
45+
); // 4.5
46+
Printf.printf("%s", Module.write_text(wasm_mod));
47+
Module.dispose(wasm_mod);
48+
});
49+
test("float32", () => {
50+
let wasm_mod = Module.create();
51+
let _ = create_test_func(wasm_mod, "float32_test", Literal.float32(3.5));
52+
Printf.printf("%s", Module.write_text(wasm_mod));
53+
Module.dispose(wasm_mod);
54+
});
55+
test("float64", () => {
56+
let wasm_mod = Module.create();
57+
let _ = create_test_func(wasm_mod, "float64_test", Literal.float64(5.5));
58+
Printf.printf("%s", Module.write_text(wasm_mod));
59+
Module.dispose(wasm_mod);
60+
});
61+
});

test/test.expected

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,62 @@ Running suite: Function
4646
)
4747
)
4848
. Running test: set_debug_location
49-
{"version":3,"sources":[],"names":[],"mappings":"uBASoB,C"}Running suite: Module
49+
{"version":3,"sources":[],"names":[],"mappings":"uBASoB,C"}Running suite: Literal
50+
. Running test: int32
51+
(module
52+
(type $0 (func))
53+
(func $int32_test
54+
(drop
55+
(i32.const 42)
56+
)
57+
)
58+
)
59+
. Running test: int64
60+
(module
61+
(type $0 (func))
62+
(func $int64_test
63+
(drop
64+
(i64.const -35)
65+
)
66+
)
67+
)
68+
. Running test: float32_bits
69+
(module
70+
(type $0 (func))
71+
(func $float32_bits_test
72+
(drop
73+
(f32.const 4.5)
74+
)
75+
)
76+
)
77+
. Running test: float64_bits
78+
(module
79+
(type $0 (func))
80+
(func $float64_bits_test
81+
(drop
82+
(f64.const 4.5)
83+
)
84+
)
85+
)
86+
. Running test: float32
87+
(module
88+
(type $0 (func))
89+
(func $float32_test
90+
(drop
91+
(f32.const 3.5)
92+
)
93+
)
94+
)
95+
. Running test: float64
96+
(module
97+
(type $0 (func))
98+
(func $float64_test
99+
(drop
100+
(f64.const 5.5)
101+
)
102+
)
103+
)
104+
Running suite: Module
50105
. Running test: create and dispose
51106
. Running test: add custom section
52107
. Running test: write

test/test.re

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
open Module_test;
2+
open Literal_test;
23
open Function_test;
34
open Settings_test;
45
open Type_test;
5-
// TODO: Type
66
// TODO: Table
77
// TODO: Struct_Type
88
// TODO: Signature_Type
99
// TODO: Passes
1010
// TODO: Packed_Type
1111
// TODO: OP
1212
// TODO: Memory
13-
// TODO: Literal
1413
// TODO: Import
1514
// TODO: Heap_Type
1615
// TODO: Global

0 commit comments

Comments
 (0)