2018-06-29 23:44:04 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var vm = require('vm');
|
|
|
|
var fs = require('fs');
|
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
var localItems = {};
|
2018-06-30 14:26:41 +00:00
|
|
|
var localMods = 0;
|
2018-06-29 23:44:04 +00:00
|
|
|
|
|
|
|
global.localStorage = {
|
2018-06-30 14:26:41 +00:00
|
|
|
clear: function() {
|
|
|
|
localItems = {};
|
|
|
|
localMods = 0;
|
|
|
|
this.length = 0;
|
|
|
|
},
|
2018-06-29 23:44:04 +00:00
|
|
|
getItem: function(k) {
|
2018-06-30 14:26:41 +00:00
|
|
|
console.log('get',k);
|
2018-06-29 23:44:04 +00:00
|
|
|
return localItems[k];
|
|
|
|
},
|
|
|
|
setItem: function(k,v) {
|
2018-06-30 14:26:41 +00:00
|
|
|
console.log('set',k,v);
|
|
|
|
if (!localItems[k]) this.length++;
|
2018-06-29 23:44:04 +00:00
|
|
|
localItems[k] = v;
|
2018-06-30 14:26:41 +00:00
|
|
|
localMods++;
|
|
|
|
},
|
|
|
|
removeItem: function(k) {
|
|
|
|
if (localItems[k]) {
|
|
|
|
this.length--;
|
|
|
|
delete localItems[k];
|
|
|
|
localMods++;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
length: 0,
|
|
|
|
key: function(i) {
|
|
|
|
var keys = [];
|
|
|
|
for (var k in localItems)
|
|
|
|
keys.push(k);
|
|
|
|
console.log(i,keys[i]);
|
|
|
|
return keys[i];
|
2018-06-29 23:44:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-16 23:19:20 +00:00
|
|
|
global.localforage = require("localForage/dist/localforage.js");
|
|
|
|
var util = require("gen/util.js");
|
|
|
|
var mstore = require("gen/store.js");
|
|
|
|
var prj = require("gen/project.js");
|
2018-06-30 14:26:41 +00:00
|
|
|
|
|
|
|
var test_platform_id = "_TEST";
|
|
|
|
|
2018-06-29 23:44:04 +00:00
|
|
|
describe('Store', function() {
|
2018-06-30 14:26:41 +00:00
|
|
|
it('Should convert from local storage', function(done) {
|
|
|
|
localStorage.clear();
|
|
|
|
localStorage.setItem('_TEST/test', 'a');
|
|
|
|
localStorage.setItem('_TEST/local/test', 'b');
|
|
|
|
assert.equal(2, localMods);
|
2018-08-16 23:19:20 +00:00
|
|
|
var store = mstore.createNewPersistentStore(test_platform_id, function() {
|
2018-06-30 14:26:41 +00:00
|
|
|
assert.equal('true', localItems['__migrated__TEST']);
|
|
|
|
store.getItem('test', function(err, result) {
|
|
|
|
if (err) done(err);
|
2018-08-06 15:20:55 +00:00
|
|
|
// did it convert?
|
2018-06-30 14:26:41 +00:00
|
|
|
assert.equal(result, 'a');
|
|
|
|
assert.equal(7, localMods);
|
2018-08-06 15:20:55 +00:00
|
|
|
// did we not mess with original storage?
|
|
|
|
assert.equal(localStorage.getItem('_TEST/test'), 'a');
|
|
|
|
assert.equal(localStorage.getItem('_TEST/local/test'), 'b');
|
2018-06-30 14:26:41 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should load local project', function(done) {
|
|
|
|
localStorage.clear();
|
2018-08-18 14:21:18 +00:00
|
|
|
localStorage.setItem('_TEST/local/test', 'a');
|
2018-08-16 23:19:20 +00:00
|
|
|
var store = mstore.createNewPersistentStore(test_platform_id, function() {
|
2018-06-30 14:26:41 +00:00
|
|
|
var worker = {};
|
|
|
|
var platform = {};
|
2018-07-06 00:13:07 +00:00
|
|
|
var project = new prj.CodeProject(worker, test_platform_id, platform, store);
|
2018-08-18 14:21:18 +00:00
|
|
|
var remote = [];
|
|
|
|
project.callbackGetRemote = function(path) { remote.push(path); return {fail:function(failfn){failfn({status:404})}} };
|
|
|
|
project.loadFiles(['local/test','test'], function(err, result) {
|
2018-06-30 14:26:41 +00:00
|
|
|
assert.equal(null, err);
|
2018-08-18 14:21:18 +00:00
|
|
|
assert.deepEqual(["presets/_TEST/test"], remote);
|
|
|
|
assert.deepEqual([ { path: 'local/test', filename: 'test', data: 'a', link:true } ], result);
|
2018-06-30 14:26:41 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-08-04 14:21:50 +00:00
|
|
|
it('Should build linked project', function(done) {
|
2018-06-30 14:26:41 +00:00
|
|
|
localStorage.clear();
|
|
|
|
localItems['__migrated__TEST'] = 'true';
|
|
|
|
var msgs = [];
|
|
|
|
var expectmsgs = [
|
|
|
|
true,
|
|
|
|
{ preload: 'dasm', platform: '_TEST' },
|
2018-07-02 13:34:20 +00:00
|
|
|
{
|
|
|
|
buildsteps: [
|
2018-08-04 14:21:50 +00:00
|
|
|
{ path: "test.a", platform: "_TEST", tool: "dasm", mainfile:true, files:["test.a"] },
|
2018-07-02 13:34:20 +00:00
|
|
|
],
|
|
|
|
updates: [
|
|
|
|
{ path: "test.a", data: " lda #0" }
|
|
|
|
]
|
|
|
|
}
|
2018-06-30 14:26:41 +00:00
|
|
|
];
|
2018-08-16 23:19:20 +00:00
|
|
|
var store = mstore.createNewPersistentStore(test_platform_id);
|
2018-06-30 14:26:41 +00:00
|
|
|
var worker = {
|
|
|
|
postMessage: function(m) { msgs.push(m); },
|
|
|
|
};
|
|
|
|
var platform = {
|
|
|
|
getToolForFilename: function(fn) { return 'dasm'; },
|
|
|
|
};
|
2018-07-06 00:13:07 +00:00
|
|
|
var project = new prj.CodeProject(worker, test_platform_id, platform, store);
|
2018-06-30 14:26:41 +00:00
|
|
|
project.callbackBuildStatus = function(b) { msgs.push(b) };
|
|
|
|
project.updateFile('test.a', ' lda #0');
|
2018-08-04 14:21:50 +00:00
|
|
|
project.setMainFile('test.a');
|
2018-06-30 14:26:41 +00:00
|
|
|
project.updateFile('test.a', ' lda #1'); // don't send twice (yet)
|
|
|
|
assert.deepEqual(msgs, expectmsgs);
|
|
|
|
store.getItem('test.a', function(err, result) {
|
|
|
|
assert.equal(null, err);
|
|
|
|
assert.equal(' lda #1', result);
|
|
|
|
done();
|
|
|
|
});
|
2018-06-29 23:44:04 +00:00
|
|
|
});
|
2018-06-30 14:26:41 +00:00
|
|
|
|
|
|
|
// lines: [ { line: 3, offset: 61440, insns: 'a9 00', iscode: true } ] }
|
|
|
|
|
2018-08-04 14:21:50 +00:00
|
|
|
it('Should build asm project', function(done) {
|
2018-06-30 14:26:41 +00:00
|
|
|
localStorage.clear();
|
|
|
|
localItems['__migrated__TEST'] = 'true';
|
|
|
|
var msgs = [];
|
2018-08-16 23:19:20 +00:00
|
|
|
var store = mstore.createNewPersistentStore(test_platform_id);
|
2018-06-30 14:26:41 +00:00
|
|
|
var worker = {
|
|
|
|
};
|
|
|
|
var platform = {
|
|
|
|
};
|
2018-07-06 00:13:07 +00:00
|
|
|
var project = new prj.CodeProject(worker, test_platform_id, platform, store);
|
2018-06-30 14:26:41 +00:00
|
|
|
project.callbackBuildStatus = function(b) { msgs.push(b) };
|
|
|
|
var buildresult = {
|
|
|
|
listings: {
|
|
|
|
test: {
|
|
|
|
lines: [ { line: 3, offset: 61440, insns: 'a9 00', iscode: true } ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
worker.onmessage({data:buildresult});
|
|
|
|
assert.deepEqual([false], msgs);
|
|
|
|
var lst = buildresult.listings.test;
|
|
|
|
console.log(lst);
|
2018-08-19 23:25:42 +00:00
|
|
|
assert.equal(3, lst.sourcefile.findLineForOffset(61440+15, 15));
|
|
|
|
assert.equal(null, lst.sourcefile.findLineForOffset(61440+16, 15));
|
|
|
|
assert.equal(null, lst.sourcefile.findLineForOffset(61440+1, 0));
|
|
|
|
assert.equal(null, lst.sourcefile.findLineForOffset(61440-1, 16));
|
2018-06-30 14:26:41 +00:00
|
|
|
assert.equal(1, lst.sourcefile.lineCount());
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2018-06-29 23:44:04 +00:00
|
|
|
});
|