2015-03-08 07:48:45 +00:00
|
|
|
var chai = require('chai');
|
2015-02-27 11:41:07 +00:00
|
|
|
var utils = require('../lib/utils.js');
|
2015-03-08 07:48:45 +00:00
|
|
|
var assert = chai.assert;
|
|
|
|
|
|
|
|
var tests = [
|
|
|
|
{ value: 1, expected: '0x1' },
|
|
|
|
{ value: '1', expected: '0x1' },
|
|
|
|
{ value: '0x1', expected: '0x1'},
|
|
|
|
{ value: '0x01', expected: '0x1'},
|
|
|
|
{ value: 15, expected: '0xf'},
|
|
|
|
{ value: '15', expected: '0xf'},
|
|
|
|
{ value: '0xf', expected: '0xf'},
|
|
|
|
{ value: '0x0f', expected: '0xf'},
|
|
|
|
{ value: -1, expected: '-0x1'},
|
|
|
|
{ value: '-1', expected: '-0x1'},
|
|
|
|
{ value: '-0x1', expected: '-0x1'},
|
|
|
|
{ value: '-0x01', expected: '-0x1'},
|
|
|
|
{ value: -15, expected: '-0xf'},
|
|
|
|
{ value: '-15', expected: '-0xf'},
|
|
|
|
{ value: '-0xf', expected: '-0xf'},
|
|
|
|
{ value: '-0x0f', expected: '-0xf'},
|
|
|
|
{ value: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'},
|
|
|
|
{ value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'},
|
|
|
|
{ value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'},
|
|
|
|
{ value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'},
|
|
|
|
{ value: 0, expected: '0x0'},
|
|
|
|
{ value: '0', expected: '0x0'},
|
|
|
|
{ value: '0x0', expected: '0x0'},
|
|
|
|
{ value: -0, expected: '0x0'},
|
|
|
|
{ value: '-0', expected: '0x0'},
|
|
|
|
{ value: '-0x0', expected: '0x0'}
|
|
|
|
];
|
2015-02-27 11:41:07 +00:00
|
|
|
|
|
|
|
describe('utils', function () {
|
|
|
|
describe('toHex', function () {
|
2015-03-08 07:48:45 +00:00
|
|
|
tests.forEach(function (test) {
|
|
|
|
it('should turn ' + test.value + ' to ' + test.expected, function () {
|
|
|
|
assert.equal(utils.toHex(test.value), test.expected);
|
|
|
|
});
|
2015-02-27 11:41:07 +00:00
|
|
|
});
|
|
|
|
});
|
2015-03-07 18:18:22 +00:00
|
|
|
});
|
2015-03-08 07:48:45 +00:00
|
|
|
|