1+ var test = require ( './gen/bin/Debug/tests.node' )
2+ const assert = require ( 'assert' ) . strict ;
3+
4+ const eq = assert . strictEqual ;
5+ const floateq = ( actual , expected ) => { assert ( Math . abs ( actual - expected ) < Number . EPSILON ) }
6+
7+ const ascii = v => v . charCodeAt ( 0 )
8+
9+ function builtins ( )
10+ {
11+ eq ( test . ReturnsVoid ( ) , undefined )
12+ eq ( test . ReturnsBool ( ) , true )
13+ eq ( test . PassAndReturnsBool ( false ) , false )
14+ eq ( test . ReturnsNullptr ( ) , null )
15+ //eq(test.PassAndReturnsNullptr(null), null)
16+ eq ( test . ReturnsNullptr ( ) , null )
17+
18+ eq ( test . ReturnsChar ( ) , ascii ( 'a' ) ) ;
19+ eq ( test . ReturnsSChar ( ) , ascii ( 'a' ) ) ;
20+ eq ( test . ReturnsUChar ( ) , ascii ( 'a' ) ) ;
21+
22+ eq ( test . PassAndReturnsChar ( ascii ( 'a' ) ) , ascii ( 'a' ) ) ;
23+ eq ( test . PassAndReturnsSChar ( ascii ( 'b' ) ) , ascii ( 'b' ) ) ;
24+ eq ( test . PassAndReturnsUChar ( ascii ( 'c' ) ) , ascii ( 'c' ) ) ;
25+
26+ eq ( test . ReturnsFloat ( ) , 5.0 ) ;
27+ eq ( test . ReturnsDouble ( ) , - 5.0 ) ;
28+ //eq(test.ReturnsLongDouble(), -5.0);
29+
30+ //floateq(test.PassAndReturnsFloat (1.32), 1.32);
31+ floateq ( test . PassAndReturnsDouble ( 1.32 ) , 1.32 ) ;
32+ //float(test.PassAndReturnsLongDouble(1.32), 1.32);
33+
34+ eq ( test . ReturnsInt8 ( ) , - 5 ) ;
35+ eq ( test . ReturnsUInt8 ( ) , 5 ) ;
36+ eq ( test . ReturnsInt16 ( ) , - 5 ) ;
37+ eq ( test . ReturnsUInt16 ( ) , 5 ) ;
38+ eq ( test . ReturnsInt32 ( ) , - 5 ) ;
39+ eq ( test . ReturnsUInt32 ( ) , 5 ) ;
40+ eq ( test . ReturnsInt64 ( ) , - 5n ) ;
41+ eq ( test . ReturnsUInt64 ( ) , 5n ) ;
42+
43+ const int8 = { min : - ( 2 ** 7 ) , max : ( 2 ** 7 ) - 1 } ;
44+ eq ( test . PassAndReturnsInt8 ( int8 . min ) , int8 . min ) ;
45+ eq ( test . PassAndReturnsInt8 ( int8 . max ) , int8 . max ) ;
46+
47+ const uint8 = { min : 0 , max : ( 2 ** 8 ) - 1 } ;
48+ eq ( test . PassAndReturnsUInt8 ( uint8 . min ) , uint8 . min ) ;
49+ eq ( test . PassAndReturnsUInt8 ( uint8 . max ) , uint8 . max ) ;
50+
51+ const int16 = { min : - ( 2 ** 15 ) , max : ( 2 ** 15 ) - 1 } ;
52+ eq ( test . PassAndReturnsInt16 ( int16 . min ) , int16 . min ) ;
53+ eq ( test . PassAndReturnsInt16 ( int16 . max ) , int16 . max ) ;
54+
55+ const uint16 = { min : 0 , max : ( 2 ** 16 ) - 1 } ;
56+ eq ( test . PassAndReturnsUInt16 ( uint16 . min ) , uint16 . min ) ;
57+ eq ( test . PassAndReturnsUInt16 ( uint16 . max ) , uint16 . max ) ;
58+
59+ const int32 = { min : - ( 2 ** 31 ) , max : ( 2 ** 31 ) - 1 } ;
60+ eq ( test . PassAndReturnsInt32 ( int32 . min ) , int32 . min ) ;
61+ eq ( test . PassAndReturnsInt32 ( int32 . max ) , int32 . max ) ;
62+
63+ const uint32 = { min : 0 , max : ( 2 ** 32 ) - 1 } ;
64+ eq ( test . PassAndReturnsUInt32 ( uint32 . min ) , uint32 . min ) ;
65+ eq ( test . PassAndReturnsUInt32 ( uint32 . max ) , uint32 . max ) ;
66+
67+ const int64 = { min : BigInt ( 2 ** 63 ) * - 1n , max : BigInt ( 2 ** 63 ) - 1n } ;
68+ eq ( test . PassAndReturnsInt64 ( int64 . min ) , int64 . min ) ;
69+ eq ( test . PassAndReturnsInt64 ( int64 . max ) , int64 . max ) ;
70+
71+ const uint64 = { min : BigInt ( 0 ) , max : BigInt ( 2 ** 64 ) - 1n } ;
72+ eq ( test . PassAndReturnsUInt64 ( uint64 . min ) , uint64 . min ) ;
73+ eq ( test . PassAndReturnsUInt64 ( uint64 . max ) , uint64 . max ) ;
74+ }
75+
76+ function enums ( )
77+ {
78+ eq ( test . Enum0 . Item0 , 0 ) ;
79+ eq ( test . Enum0 . Item1 , 1 ) ;
80+ eq ( test . Enum0 . Item2 , 5 ) ;
81+ }
82+
83+ function overloads ( )
84+ {
85+ eq ( test . Overload ( 1 , 2 ) , 1 )
86+ eq ( test . Overload ( 1 , 2.032 ) , 2 ) ;
87+ eq ( test . Overload ( 1.23 , 2 ) , 3 ) ;
88+ }
89+
90+ builtins ( ) ;
91+ enums ( ) ;
92+ overloads ( ) ;
0 commit comments