1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-27 01:51:35 +00:00
8bitworkshop/test/cli/testdecoder.js

29 lines
744 B
JavaScript
Raw Normal View History

2017-01-17 21:50:57 +00:00
var vm = require('vm');
var fs = require('fs');
var emu = require('gen/common/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);
}
describe('Address decoder', function() {
2017-01-17 21:50:57 +00:00
it('Should work empty', function() {
var decoder = new emu.AddressDecoder([]);
2017-01-17 21:50:57 +00:00
assertEquals(0, decoder(0x1234));
assertEquals(0, decoder(0x123456));
});
it('Should work with 1 range', function() {
var decoder = new emu.AddressDecoder([
2017-01-17 21:50:57 +00:00
[0x1000, 0x7fff, 0xff, function(a) { return a+2; }]
]);
assertEquals(0, decoder(0xfff));
assertEquals(2, decoder(0x1000));
assertEquals(1, decoder(0x7fff));
assertEquals(0, decoder(0x8000));
});
});