forked from aws-amplify/amplify-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BigInteger tests (aws-amplify#4520)
* fix:(amazon-cognito-identity-js): include radix parameter Without this fix, a negative bigint will always end up throwing `new Error('Only radix 2, 4, 8, 16, 32 are supported')` because b is undefined. This fix is present in the original code from which this file was derived: http://www-cs-students.stanford.edu/~tjw/jsbn/jsbn.js * Include radix when calling bnToString() for negatives The bnToString() function throws an exception when called without a radix value or given a radix outside of [2, 4, 8, 16, 32]. When bnToString() is called on a negative big int value, it's negated value is used to call bnToString() which then gets concatenated to a '-'. However, in the bnToString() call for the negated value, no radix value is passed in so it always throws an exception. This change will use the radix value argument from the initial bnToString() call on the negative big integer value when calling bnToString() for it's negated value so that it works as intended. * Add BigInteger.test.js * Update dependencies so that jest runs * Correct negative test name * Update .babelrc to mirror previous one
- Loading branch information
1 parent
8674120
commit 36dfd8f
Showing
4 changed files
with
44 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"es2015", { | ||
"loose": true, | ||
"modules": false | ||
} | ||
] | ||
], | ||
"env": { | ||
"commonjs": { | ||
"plugins": [ | ||
["transform-es2015-modules-commonjs", { "loose": true }] | ||
] | ||
} | ||
} | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"loose": true, | ||
"modules": false | ||
} | ||
] | ||
], | ||
"env": { | ||
"commonjs": { | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"loose": true, | ||
"modules": "commonjs" | ||
} | ||
] | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/amazon-cognito-identity-js/src/BigInteger.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import BigInteger from './BigInteger'; | ||
|
||
describe('BigInteger', () => { | ||
describe('.toString(radix)', () => { | ||
it('should support positive numbers', () => { | ||
expect(new BigInteger('abcd1234', 16).toString(4)).toBe( | ||
'2223303101020310' | ||
); | ||
}); | ||
|
||
it('should support negative numbers', () => { | ||
expect(new BigInteger('-abcd1234', 16).toString(4)).toBe( | ||
'-2223303101020310' | ||
); | ||
}); | ||
}); | ||
}); |