6
6
#include < stdio.h>
7
7
#include < iostream>
8
8
#include < sstream>
9
- #include < cmath>
10
9
#include < emscripten/bind.h>
11
10
#include < emscripten/emscripten.h>
12
11
#include < emscripten/val.h>
13
12
14
13
using namespace emscripten ;
15
14
using namespace std ;
16
15
17
- void fail ()
18
- {
19
- cout << " fail\n " ;
20
- }
21
-
22
- void pass ()
23
- {
24
- cout << " pass\n " ;
25
- }
26
-
27
- void test (string message)
28
- {
16
+ void test (string message) {
29
17
cout << " test:\n " << message << " \n " ;
30
18
}
31
19
32
- void ensure (bool value)
33
- {
34
- if (value)
35
- pass ();
36
- else
37
- fail ();
38
- }
39
-
40
- void ensure_js (string js_code)
41
- {
20
+ void ensure_js (string js_code) {
42
21
js_code.append (" ;" );
43
22
const char * js_code_pointer = js_code.c_str ();
44
- ensure (EM_ASM_INT ({
23
+ assert (EM_ASM_INT ({
45
24
var js_code = UTF8ToString ($0 );
46
25
return eval (js_code);
47
26
}, js_code_pointer));
@@ -54,8 +33,7 @@ string compare_a_64_js(T value) {
54
33
return ss.str ();
55
34
}
56
35
57
- int main ()
58
- {
36
+ int main () {
59
37
const int64_t max_int64_t = numeric_limits<int64_t >::max ();
60
38
const int64_t min_int64_t = numeric_limits<int64_t >::min ();
61
39
const uint64_t max_uint64_t = numeric_limits<uint64_t >::max ();
@@ -73,24 +51,24 @@ int main()
73
51
74
52
val::global ().set (" a" , val (int64_t (0x12345678aabbccddL )));
75
53
ensure_js (" a === 1311768467732155613n" );
76
- ensure (val::global ()[" a" ].as <int64_t >() == 0x12345678aabbccddL );
54
+ assert (val::global ()[" a" ].as <int64_t >() == 0x12345678aabbccddL );
77
55
78
56
test (" val(uint64_t v)" );
79
57
val::global ().set (" a" , val (uint64_t (1234 )));
80
58
ensure_js (" a === 1234n" );
81
59
82
60
val::global ().set (" a" , val (max_uint64_t ));
83
61
ensure_js (compare_a_64_js (max_uint64_t ));
84
- ensure (val::global ()[" a" ].as <uint64_t >() == max_uint64_t );
62
+ assert (val::global ()[" a" ].as <uint64_t >() == max_uint64_t );
85
63
86
64
test (" val(int64_t v)" );
87
65
val::global ().set (" a" , val (max_int64_t ));
88
66
ensure_js (compare_a_64_js (max_int64_t ));
89
- ensure (val::global ()[" a" ].as <int64_t >() == max_int64_t );
67
+ assert (val::global ()[" a" ].as <int64_t >() == max_int64_t );
90
68
91
69
val::global ().set (" a" , val (min_int64_t ));
92
70
ensure_js (compare_a_64_js (min_int64_t ));
93
- ensure (val::global ()[" a" ].as <int64_t >() == min_int64_t );
71
+ assert (val::global ()[" a" ].as <int64_t >() == min_int64_t );
94
72
95
73
test (" val(typed_memory_view<uint64_t>)" );
96
74
val::global ().set (" a" , val (typed_memory_view (uint64Array.size (), uint64Array.data ())));
0 commit comments