1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-17 11:05:58 +00:00
8bitworkshop/test/cli/testdecoder.js

34 lines
855 B
JavaScript

var vm = require('vm');
var fs = require('fs');
var includeInThisContext = function(path) {
var code = fs.readFileSync(path);
vm.runInThisContext(code, path);
};
includeInThisContext("src/emu.js");
function assert(b, msg) {
if (!b) { throw new Error(msg); }
}
function assertEquals(a,b) {
assert(a==b, a + " != " + b);
}
describe('Address decoder', function() {
it('Should work empty', function() {
var decoder = new AddressDecoder([]);
assertEquals(0, decoder(0x1234));
assertEquals(0, decoder(0x123456));
});
it('Should work with 1 range', function() {
var decoder = new AddressDecoder([
[0x1000, 0x7fff, 0xff, function(a) { return a+2; }]
]);
assertEquals(0, decoder(0xfff));
assertEquals(2, decoder(0x1000));
assertEquals(1, decoder(0x7fff));
assertEquals(0, decoder(0x8000));
});
});