add Opcode.smallInt()
This commit is contained in:
parent
4fae69807d
commit
7b54a53414
@ -46,6 +46,16 @@ Opcode.prototype.toString = function() {
|
|||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Opcode.smallInt = function(n) {
|
||||||
|
if (!(n >= 0 && n <= 16)) {
|
||||||
|
throw new Error('Invalid Argument: n must be between 0 and 16');
|
||||||
|
}
|
||||||
|
if (n === 0) {
|
||||||
|
return Opcode('OP_0');
|
||||||
|
}
|
||||||
|
return new Opcode(Opcode.map.OP_1 + n - 1);
|
||||||
|
};
|
||||||
|
|
||||||
Opcode.map = {
|
Opcode.map = {
|
||||||
// push value
|
// push value
|
||||||
OP_FALSE: 0,
|
OP_FALSE: 0,
|
||||||
|
|||||||
@ -92,13 +92,22 @@ describe('Opcode', function() {
|
|||||||
Opcode('OP_16')
|
Opcode('OP_16')
|
||||||
];
|
];
|
||||||
|
|
||||||
describe('@isSmallIntOp', function() {
|
describe('@smallInt', function() {
|
||||||
var testSmallInt = function() {
|
var testSmallInt = function(n, op) {
|
||||||
Opcode.isSmallIntOp(this).should.equal(true);
|
Opcode.smallInt(n).toString().should.equal(op.toString());
|
||||||
};
|
};
|
||||||
for (var i = 0; i < smallints.length; i++) {
|
for (var i = 0; i < smallints.length; i++) {
|
||||||
var op = smallints[i];
|
var op = smallints[i];
|
||||||
it('should work for small int ' + op, testSmallInt.bind(op));
|
it('should work for small int ' + op, testSmallInt.bind(null, i, op));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
describe('@isSmallIntOp', function() {
|
||||||
|
var testIsSmallInt = function(op) {
|
||||||
|
Opcode.isSmallIntOp(op).should.equal(true);
|
||||||
|
};
|
||||||
|
for (var i = 0; i < smallints.length; i++) {
|
||||||
|
var op = smallints[i];
|
||||||
|
it('should work for small int ' + op, testIsSmallInt.bind(null, op));
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should work for non-small ints', function() {
|
it('should work for non-small ints', function() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user