From 4366f72fe1d9f0c3a94f27e5f23bd826f8cf69e0 Mon Sep 17 00:00:00 2001 From: Frankie Date: Wed, 19 Oct 2016 15:22:56 -0700 Subject: Add unit test for isHex and add to CHANGELOG.md --- test/unit/util_test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/unit') diff --git a/test/unit/util_test.js b/test/unit/util_test.js index 45e545e8e..b7d8ba528 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -227,5 +227,22 @@ describe('util', function() { assert.equal(result.toString(10), '1111000000000000000', 'accepts decimals') }) }) + describe('#isHex', function(){ + it('should return true when given a hex string', function() { + var result = util.isHex('c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2') + assert.equal(result, true) + }) + + it('should return false when given a non-hex string', function() { + var result = util.isHex('c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714imnotreal') + assert.equal(result, false) + }) + + it('should return false when given a string containing a non letter/number character', function() { + var result = util.isHex('c3ab8ff13720!8ad9047dd39466b3c%8974e592c2fa383d4a396071imnotreal') + assert.equal(result, false) + }) + + }) }) }) -- cgit v1.2.3 From aa4746f4c723857710d61482a73960d863a8a098 Mon Sep 17 00:00:00 2001 From: Frankie Date: Wed, 19 Oct 2016 19:35:44 -0700 Subject: Add test and ability for isHex to handle hex strings with hex-prefix --- test/unit/util_test.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/unit') diff --git a/test/unit/util_test.js b/test/unit/util_test.js index b7d8ba528..eec3183fe 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -243,6 +243,11 @@ describe('util', function() { assert.equal(result, false) }) + it('should return true when given a hex string with hex-prefix', function() { + var result = util.isHex('0xc3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2') + assert.equal(result, true) + }) + }) }) }) -- cgit v1.2.3 From d4c0a4949bd8331e965ad17c5ac04af7b6fb90ea Mon Sep 17 00:00:00 2001 From: Frankie Date: Thu, 20 Oct 2016 12:26:35 -0700 Subject: Clean up tests --- test/unit/util_test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/unit') diff --git a/test/unit/util_test.js b/test/unit/util_test.js index eec3183fe..00528b905 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -230,22 +230,22 @@ describe('util', function() { describe('#isHex', function(){ it('should return true when given a hex string', function() { var result = util.isHex('c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2') - assert.equal(result, true) + assert(result) }) it('should return false when given a non-hex string', function() { var result = util.isHex('c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714imnotreal') - assert.equal(result, false) + assert(!result) }) it('should return false when given a string containing a non letter/number character', function() { var result = util.isHex('c3ab8ff13720!8ad9047dd39466b3c%8974e592c2fa383d4a396071imnotreal') - assert.equal(result, false) + assert(!result) }) it('should return true when given a hex string with hex-prefix', function() { var result = util.isHex('0xc3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2') - assert.equal(result, true) + assert(result) }) }) -- cgit v1.2.3