2017-01-17 21:50:57 +00:00
|
|
|
|
|
|
|
var vm = require('vm');
|
|
|
|
var fs = require('fs');
|
|
|
|
var includeInThisContext = function(path) {
|
|
|
|
var code = fs.readFileSync(path);
|
|
|
|
vm.runInThisContext(code, path);
|
|
|
|
};
|
|
|
|
|
2018-07-11 00:58:46 +00:00
|
|
|
includeInThisContext("gen/emu.js");
|
2017-01-17 21:50:57 +00:00
|
|
|
|
|
|
|
function assert(b, msg) {
|
|
|
|
if (!b) { throw new Error(msg); }
|
|
|
|
}
|
|
|
|
function assertEquals(a,b) {
|
|
|
|
assert(a==b, a + " != " + b);
|
|
|
|
}
|
|
|
|
|
2017-01-18 17:08:15 +00:00
|
|
|
describe('Address decoder', function() {
|
2017-01-17 21:50:57 +00:00
|
|
|
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));
|
|
|
|
});
|
|
|
|
});
|