@@ -164,46 +164,73 @@ describe('Long', function () {
164
164
} ) ;
165
165
} ) ;
166
166
167
- describe . only ( 'static fromStringStrict()' , function ( ) {
167
+ describe ( 'static fromStringStrict()' , function ( ) {
168
168
const successInputs = [
169
- [ 'basic no alphabet low radix' , '1236' , 8 ] ,
170
- [ 'radix does allow given alphabet letter' , 'eEe' , 15 ] ,
171
- [ 'hexadecimal letters' , '126073efbcdADEF' , 16 ] ,
172
- [ 'negative hexadecimal letters' , '-126073efbcdADEF' , 16 ]
169
+ [ 'basic no alphabet low radix' , '1236' , true , 8 ] ,
170
+ [ 'negative basic no alphabet low radix' , '-1236' , false , 8 ] ,
171
+ [ 'valid upper and lower case letters in string with radix > 10' , 'eEe' , true , 15 ] ,
172
+ [ 'hexadecimal letters' , '126073efbcdADEF' , true , 16 ] ,
173
+ [ 'negative hexadecimal letters' , '-1267efbcdDEF' , false , 16 ] ,
174
+ [ 'negative leading zeros' , '-00000032' , false , 15 , '-32' ] ,
175
+ [ 'leading zeros' , '00000032' , false , 15 , '32' ] ,
176
+ [ 'explicit positive leading zeros' , '+00000032' , false , 15 , '32' ] ,
177
+ [ 'max unsigned binary input' , Long . MAX_UNSIGNED_VALUE . toString ( 2 ) , true , 2 ] ,
178
+ [ 'max unsigned decimal input' , Long . MAX_UNSIGNED_VALUE . toString ( 10 ) , true , 10 ] ,
179
+ [ 'max unsigned hex input' , Long . MAX_UNSIGNED_VALUE . toString ( 16 ) , true , 16 ] ,
180
+ [ 'max signed binary input' , Long . MAX_VALUE . toString ( 2 ) , false , 2 ] ,
181
+ [ 'max signed decimal input' , Long . MAX_VALUE . toString ( 10 ) , false , 10 ] ,
182
+ [ 'max signed hex input' , Long . MAX_VALUE . toString ( 16 ) , false , 16 ] ,
183
+ [ 'min signed binary input' , Long . MIN_VALUE . toString ( 2 ) , false , 2 ] ,
184
+ [ 'min signed decimal input' , Long . MIN_VALUE . toString ( 10 ) , false , 10 ] ,
185
+ [ 'min signed hex input' , Long . MIN_VALUE . toString ( 16 ) , false , 16 ] ,
186
+ [ 'signed zero' , '0' , false , 10 ] ,
187
+ [ 'unsigned zero' , '0' , true , 10 ]
173
188
] ;
174
189
175
190
const failureInputs = [
176
- [ 'empty string' , '' , 2 ] ,
177
- [ 'non a-z or numeric string' , '~~' , 36 ] ,
178
- [ 'alphabet in radix < 10' , 'a' , 4 ] ,
179
- [ 'radix does not allow all alphabet letters' , 'eee' , 14 ]
191
+ [ 'empty string' , '' , true , 2 ] ,
192
+ [ 'invalid numbers in binary string' , '234' , true , 2 ] ,
193
+ [ 'non a-z or numeric string' , '~~' , true , 36 ] ,
194
+ [ 'alphabet in radix < 10' , 'a' , true , 9 ] ,
195
+ [ 'radix does not allow all alphabet letters' , 'eee' , 14 ] ,
196
+ [ 'over max unsigned binary input' , Long . MAX_UNSIGNED_VALUE . toString ( 2 ) + '1' , true , 2 ] ,
197
+ [ 'over max unsigned decimal input' , Long . MAX_UNSIGNED_VALUE . toString ( 10 ) + '1' , true , 10 ] ,
198
+ [ 'over max unsigned hex input' , Long . MAX_UNSIGNED_VALUE . toString ( 16 ) + '1' , true , 16 ] ,
199
+ [ 'over max signed binary input' , Long . MAX_VALUE . toString ( 2 ) + '1' , false , 2 ] ,
200
+ [ 'over max signed decimal input' , Long . MAX_VALUE . toString ( 10 ) + '1' , false , 10 ] ,
201
+ [ 'over max signed hex input' , Long . MAX_VALUE . toString ( 16 ) + '1' , false , 16 ] ,
202
+ [ 'under min signed binary input' , Long . MIN_VALUE . toString ( 2 ) + '1' , false , 2 ] ,
203
+ [ 'under min signed decimal input' , Long . MIN_VALUE . toString ( 10 ) + '1' , false , 10 ] ,
204
+ [ 'under min signed hex input' , Long . MIN_VALUE . toString ( 16 ) + '1' , false , 16 ]
180
205
] ;
181
206
182
- for ( const [ testName , str , radix ] of successInputs ) {
207
+ for ( const [ testName , str , unsigned , radix , expectedStr ] of successInputs ) {
183
208
context ( `when the input is ${ testName } ` , ( ) => {
184
209
it ( `should return a input string` , ( ) => {
185
- expect ( Long . fromStringStrict ( str , true , radix ) . toString ( radix ) ) . to . equal ( str . toLowerCase ( ) ) ;
210
+ expect ( Long . fromStringStrict ( str , unsigned , radix ) . toString ( radix ) ) . to . equal (
211
+ expectedStr ?? str . toLowerCase ( )
212
+ ) ;
186
213
} ) ;
187
214
} ) ;
188
215
}
189
- for ( const [ testName , str , radix ] of failureInputs ) {
216
+ for ( const [ testName , str , unsigned , radix ] of failureInputs ) {
190
217
context ( `when the input is ${ testName } ` , ( ) => {
191
- it ( `should return false ` , ( ) => {
192
- expect ( ( ) => Long . fromStringStrict ( str , true , radix ) ) . to . throw ( BSONError ) ;
218
+ it ( `should throw BSONError ` , ( ) => {
219
+ expect ( ( ) => Long . fromStringStrict ( str , unsigned , radix ) ) . to . throw ( BSONError ) ;
193
220
} ) ;
194
221
} ) ;
195
222
}
196
223
} ) ;
197
224
198
225
describe ( 'static validateStringCharacters()' , function ( ) {
199
226
const successInputs = [
200
- [ 'multiple decimal points' , '..' , 30 ] ,
201
- [ 'radix does not allow given alphabet letter' , 'eEe' , 15 ] ,
202
- [ 'empty string' , '' , 2 ] ,
227
+ [ 'radix does allows given alphabet letter' , 'eEe' , 15 ] ,
228
+ [ 'empty string' , '' , 2 ] ,
203
229
[ 'all possible hexadecimal characters' , '12efabc689873dADCDEF' , 16 ]
204
230
] ;
205
231
206
232
const failureInputs = [
233
+ [ 'multiple decimal points' , '..' , 30 ] ,
207
234
[ 'non a-z or numeric string' , '~~' , 36 ] ,
208
235
[ 'alphabet in radix < 10' , 'a' , 4 ] ,
209
236
[ 'radix does not allow all alphabet letters' , 'eee' , 14 ]
0 commit comments