Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olalonde committed Mar 5, 2014
1 parent c981ccd commit e73f30c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 3 deletions.
18 changes: 16 additions & 2 deletions lib/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ var helpers = require('./helpers'),
inherits = helpers.inherits,
debug = require('debug')('bitscript:nodes');

/**
* Custom Errors
*/
// bug with mocha when extending error
function CompileError(msg) {
var err = new Error(msg);
err.name = 'CompileError';
return err;
}

/**
* Create a new context everytime compile()
* is called to save some compilation state.
*/
function new_context() {
var o = {
vars: {},
Expand Down Expand Up @@ -37,7 +51,7 @@ function new_context() {
}

/**
* Base
* Base node
*
* Every node inherits from Base
*/
Expand Down Expand Up @@ -198,7 +212,7 @@ inherits(Invocation, Base);
Invocation.prototype.compileNode = function (o) {
var func = o.funcs[this.name];
if (!func) {
throw new Error('Called unknown function ' + this.name);
throw new CompileError('Called unknown function ' + this.name);
}

// Push arguments on stack.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function main() {
actualhash = hash160('data to hash');
assert(actualhash, 'expectedhash');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data to hash
OP_HASH160
expectedhash
OP_VERIFY
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function main() {
somevar = 'abc';
equal(somevar, 'wow');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
abc
wow
OP_EQUAL
1 change: 1 addition & 0 deletions test/compile-results/no-main-params.bitscript
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function main() {}
1 change: 1 addition & 0 deletions test/compile-results/no-main-params.res
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('Parsing', function () {
});
});

describe('Compilation', function () {
describe('Compiling', function () {

function actual (name, type) {
type = type || 'compile-results';
Expand Down

0 comments on commit e73f30c

Please sign in to comment.