@@ -1205,7 +1205,7 @@ describe('Decimal128', function () {
1205
1205
done ( ) ;
1206
1206
} ) ;
1207
1207
1208
- it ( 'accepts strings in the constructor' , function ( done ) {
1208
+ it ( 'accepts strings in the constructor' , ( ) => {
1209
1209
expect ( new Decimal128 ( '0' ) . toString ( ) ) . to . equal ( '0' ) ;
1210
1210
expect ( new Decimal128 ( '00' ) . toString ( ) ) . to . equal ( '0' ) ;
1211
1211
expect ( new Decimal128 ( '0.5' ) . toString ( ) ) . to . equal ( '0.5' ) ;
@@ -1216,6 +1216,30 @@ describe('Decimal128', function () {
1216
1216
expect ( new Decimal128 ( '0.0011' ) . toString ( ) ) . to . equal ( '0.0011' ) ;
1217
1217
expect ( new Decimal128 ( '0.00110' ) . toString ( ) ) . to . equal ( '0.00110' ) ;
1218
1218
expect ( new Decimal128 ( '-1e400' ) . toString ( ) ) . to . equal ( '-1E+400' ) ;
1219
- done ( ) ;
1219
+ } ) ;
1220
+
1221
+ it ( 'throws correct error for invalid constructor argument type' , ( ) => {
1222
+ const constructorArgErrMsg = 'Decimal128 must take a Buffer or string' ;
1223
+
1224
+ expect ( ( ) => new Decimal128 ( - 0 ) ) . to . throw ( constructorArgErrMsg ) ;
1225
+ expect ( ( ) => new Decimal128 ( - 1 ) ) . to . throw ( constructorArgErrMsg ) ;
1226
+ expect ( ( ) => new Decimal128 ( 10 ) ) . to . throw ( constructorArgErrMsg ) ;
1227
+ expect ( ( ) => new Decimal128 ( 1111111111111111 ) ) . to . throw ( constructorArgErrMsg ) ;
1228
+ } ) ;
1229
+
1230
+ it ( 'throws correct error for an invalid Buffer constructor argument' , ( ) => {
1231
+ const byteLengthErrMsg = 'Decimal128 must take a Buffer of 16 bytes' ;
1232
+
1233
+ expect ( ( ) => new Decimal128 ( new Uint8Array ( 0 ) ) ) . to . throw ( byteLengthErrMsg ) ;
1234
+ expect ( ( ) => new Decimal128 ( Buffer . alloc ( 0 ) ) ) . to . throw ( byteLengthErrMsg ) ;
1235
+ expect ( ( ) => new Decimal128 ( new Uint8Array ( 3 ) ) ) . to . throw ( byteLengthErrMsg ) ;
1236
+ expect ( ( ) => new Decimal128 ( Buffer . alloc ( 3 ) ) ) . to . throw ( byteLengthErrMsg ) ;
1237
+ expect ( ( ) => new Decimal128 ( new Uint8Array ( 17 ) ) ) . to . throw ( byteLengthErrMsg ) ;
1238
+ expect ( ( ) => new Decimal128 ( Buffer . alloc ( 17 ) ) ) . to . throw ( byteLengthErrMsg ) ;
1239
+ } ) ;
1240
+
1241
+ it ( 'does not throw error for an empty Buffer of correct length constructor argument' , ( ) => {
1242
+ expect ( ( ) => new Decimal128 ( Buffer . alloc ( 16 ) ) ) . to . not . throw ( ) ;
1243
+ expect ( ( ) => new Decimal128 ( new Uint8Array ( 16 ) ) ) . to . not . throw ( ) ;
1220
1244
} ) ;
1221
1245
} ) ;
0 commit comments