-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for isHex and isHexStrict. (#3622)
Co-authored-by: Gregory Markou <16929357+GregTheGreek@users.noreply.github.com>
- Loading branch information
1 parent
6ee7118
commit 6862c59
Showing
2 changed files
with
68 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var chai = require('chai'); | ||
var utils = require('../packages/web3-utils'); | ||
|
||
var BigNumber = require('bignumber.js'); | ||
var BN = require('bn.js'); | ||
|
||
var assert = chai.assert; | ||
|
||
var tests = [ | ||
{ value: 1, expected: true }, | ||
{ value: '1', expected: true }, | ||
{ value: '0xH', expected: false}, | ||
{ value: 'H', expected: false}, | ||
{ value: [1,2,3,{test: 'data'}], expected: false}, | ||
{ value: {test: 'test'}, expected: false}, | ||
{ value: '{"test": "test"}', expected: false}, | ||
{ value: 'myString', expected: false}, | ||
{ value: 'myString 34534!', expected: false}, | ||
{ value: new BN(15), expected: false}, | ||
{ value: new BigNumber(15), expected: false}, | ||
{ value: 'Heeäööä👅D34ɝɣ24Єͽ-.,äü+#/', expected: false}, | ||
{ value: true, expected: false}, | ||
{ value: false, expected: false} | ||
]; | ||
|
||
describe('lib/utils/utils', function () { | ||
describe('isHex', function () { | ||
tests.forEach(function (test) { | ||
it('should return ' + test.expected + ' for input ' + test.value, function () { | ||
assert.strictEqual(utils.isHex(test.value), test.expected); | ||
}); | ||
}); | ||
}); | ||
}); |
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,34 @@ | ||
var chai = require('chai'); | ||
var utils = require('../packages/web3-utils'); | ||
|
||
var BigNumber = require('bignumber.js'); | ||
var BN = require('bn.js'); | ||
|
||
var assert = chai.assert; | ||
|
||
var tests = [ | ||
{ value: 0x1, expected: false }, //0x1 would be tested as 1 | ||
{ value: '0x1', expected: true }, | ||
{ value: '0xH', expected: false}, | ||
{ value: 'H', expected: false}, | ||
{ value: [1,2,3,{test: 'data'}], expected: false}, | ||
{ value: {test: 'test'}, expected: false}, | ||
{ value: '{"test": "test"}', expected: false}, | ||
{ value: 'myString', expected: false}, | ||
{ value: 'myString 34534!', expected: false}, | ||
{ value: new BN(15), expected: false}, | ||
{ value: new BigNumber(15), expected: false}, | ||
{ value: 'Heeäööä👅D34ɝɣ24Єͽ-.,äü+#/', expected: false}, | ||
{ value: true, expected: false}, | ||
{ value: false, expected: false} | ||
]; | ||
|
||
describe('lib/utils/utils', function () { | ||
describe('isHexStrict', function () { | ||
tests.forEach(function (test) { | ||
it('should return ' + test.expected + ' for input ' + test.value, function () { | ||
assert.strictEqual(utils.isHexStrict(test.value), test.expected); | ||
}); | ||
}); | ||
}); | ||
}); |