Skip to content

Commit fbdef6e

Browse files
committedApr 24, 2014
[BUG] UInt#parse_number should support zero. Add tests.
1 parent 5a04ce9 commit fbdef6e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
 

‎src/js/ripple/uint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ UInt.prototype.parse_number = function (j) {
234234

235235
if ("number" === typeof j &&
236236
j === +j &&
237-
j > 0) {
237+
j >= 0) {
238238
// XXX Better, faster way to get BigInteger from JS int?
239239
this._value = new BigInteger(""+j);
240240
}

‎test/uint-test.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var assert = require('assert');
2+
var utils = require('./testutils');
3+
var UInt128 = utils.load_module('uint128').UInt128;
4+
var config = require('./testutils').get_config();
5+
6+
describe('UInt', function() {
7+
describe('128', function() {
8+
describe('#parse_number', function () {
9+
it('should create 00000000000000000000000000000000 when called with 0', function () {
10+
var val = UInt128.from_number(0);
11+
assert.strictEqual(val.to_hex(), '00000000000000000000000000000000');
12+
});
13+
it('should create 00000000000000000000000000000001 when called with 1', function () {
14+
var val = UInt128.from_number(0);
15+
assert.strictEqual(val.to_hex(), '00000000000000000000000000000000');
16+
});
17+
it('should create 000000000000000000000000FFFFFFFF when called with 0xFFFFFFFF', function () {
18+
var val = UInt128.from_number(0xFFFFFFFF);
19+
assert.strictEqual(val.to_hex(), '000000000000000000000000FFFFFFFF');
20+
});
21+
});
22+
});
23+
});
24+
25+
// vim:sw=2:sts=2:ts=8:et

0 commit comments

Comments
 (0)
Please sign in to comment.