2018-06-29 23:44:04 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var vm = require('vm');
|
|
|
|
var fs = require('fs');
|
|
|
|
var assert = require('assert');
|
|
|
|
|
2019-05-07 19:37:37 +00:00
|
|
|
var wtu = require('./workertestutils.js'); // loads localStorage
|
2021-08-05 02:20:55 +00:00
|
|
|
var localforage = require("localforage");
|
2019-10-26 01:55:50 +00:00
|
|
|
var util = require("gen/common/util.js");
|
|
|
|
var prj = require("gen/ide/project.js");
|
2018-06-30 14:26:41 +00:00
|
|
|
|
|
|
|
var test_platform_id = "_TEST";
|
|
|
|
|
2021-04-06 16:37:41 +00:00
|
|
|
function newFilesystem(store, platform_id) {
|
2021-04-07 15:22:49 +00:00
|
|
|
return new prj.OverlayFilesystem(
|
|
|
|
new prj.NullFilesystem(),
|
|
|
|
new prj.LocalForageFilesystem(store));
|
2021-04-06 16:37:41 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 16:06:19 +00:00
|
|
|
describe('Store', function () {
|
2018-06-30 14:26:41 +00:00
|
|
|
|
2020-06-29 16:06:19 +00:00
|
|
|
it('Should load local project', function (done) {
|
2021-08-04 17:00:10 +00:00
|
|
|
var store = prj.createNewPersistentStore(test_platform_id);
|
2020-06-29 16:06:19 +00:00
|
|
|
store.setItem('local/test', 'a');
|
2018-06-30 14:26:41 +00:00
|
|
|
var worker = {};
|
|
|
|
var platform = {};
|
2021-04-06 16:37:41 +00:00
|
|
|
var project = new prj.CodeProject(worker, test_platform_id, platform, newFilesystem(store, test_platform_id));
|
2020-06-29 16:06:19 +00:00
|
|
|
project.loadFiles(['local/test', 'test']).then((result) => {
|
2021-04-06 16:37:41 +00:00
|
|
|
assert.deepEqual(["test"], project.filesystem.basefs.gets);
|
2020-06-29 16:06:19 +00:00
|
|
|
assert.deepEqual([{ path: 'local/test', filename: 'local/test', data: 'a', link: true }], result);
|
|
|
|
done();
|
2018-06-30 14:26:41 +00:00
|
|
|
});
|
|
|
|
});
|
2019-03-03 16:32:25 +00:00
|
|
|
|
2020-06-29 16:06:19 +00:00
|
|
|
it('Should build linked project', function (done) {
|
|
|
|
var msgs = [];
|
|
|
|
var expectmsgs = [
|
|
|
|
true,
|
|
|
|
{ preload: 'dasm', platform: '_TEST' },
|
|
|
|
{
|
|
|
|
buildsteps: [
|
|
|
|
{ path: "test.a", platform: "_TEST", tool: "dasm", mainfile: true, files: ["test.a"] },
|
|
|
|
],
|
|
|
|
updates: [
|
|
|
|
{ path: "test.a", data: " lda #0" }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|
2021-08-04 17:00:10 +00:00
|
|
|
var store = prj.createNewPersistentStore(test_platform_id);
|
2019-05-03 22:58:35 +00:00
|
|
|
var worker = {
|
2020-06-29 16:06:19 +00:00
|
|
|
postMessage: function (m) { msgs.push(m); },
|
2019-05-03 22:58:35 +00:00
|
|
|
};
|
|
|
|
var platform = {
|
2020-06-29 16:06:19 +00:00
|
|
|
getToolForFilename: function (fn) { return 'dasm'; },
|
2019-05-03 22:58:35 +00:00
|
|
|
};
|
2021-04-06 16:37:41 +00:00
|
|
|
var project = new prj.CodeProject(worker, test_platform_id, platform, newFilesystem(store, test_platform_id));
|
2020-06-29 16:06:19 +00:00
|
|
|
project.callbackBuildStatus = function (b) { msgs.push(b) };
|
2020-10-16 11:14:40 +00:00
|
|
|
project.callbackBuildResult = function (b) { msgs.push(1) };
|
2019-05-03 22:58:35 +00:00
|
|
|
project.updateFile('test.a', ' lda #0');
|
|
|
|
project.setMainFile('test.a');
|
2019-05-23 12:32:53 +00:00
|
|
|
setTimeout(() => {
|
2020-06-29 16:06:19 +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();
|
|
|
|
});
|
2019-05-23 12:32:53 +00:00
|
|
|
}, 1);
|
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 } ] }
|
|
|
|
|
2020-06-29 16:06:19 +00:00
|
|
|
it('Should build asm project', function (done) {
|
|
|
|
var msgs = [];
|
2021-08-04 17:00:10 +00:00
|
|
|
var store = prj.createNewPersistentStore(test_platform_id);
|
2019-05-03 22:58:35 +00:00
|
|
|
var worker = {
|
|
|
|
};
|
|
|
|
var platform = {
|
|
|
|
};
|
2021-04-06 16:37:41 +00:00
|
|
|
var project = new prj.CodeProject(worker, test_platform_id, platform, newFilesystem(store, test_platform_id));
|
2020-06-29 16:06:19 +00:00
|
|
|
project.callbackBuildStatus = function (b) { msgs.push(b) };
|
2020-10-16 11:14:40 +00:00
|
|
|
project.callbackBuildResult = function (b) { msgs.push(1) };
|
2019-05-03 22:58:35 +00:00
|
|
|
var buildresult = {
|
2020-06-29 16:06:19 +00:00
|
|
|
listings: {
|
|
|
|
test: {
|
|
|
|
lines: [{ line: 3, offset: 61440, insns: 'a9 00', iscode: true }]
|
|
|
|
}
|
2019-05-03 22:58:35 +00:00
|
|
|
}
|
|
|
|
};
|
2020-06-29 16:06:19 +00:00
|
|
|
worker.onmessage({ data: buildresult });
|
2020-10-16 11:14:40 +00:00
|
|
|
assert.deepEqual([false, 1], msgs);
|
2019-05-03 22:58:35 +00:00
|
|
|
var lst = buildresult.listings.test;
|
|
|
|
console.log(lst);
|
2020-08-11 02:35:25 +00:00
|
|
|
assert.deepEqual({ line: 3, offset: 61440, insns: 'a9 00', iscode: true },
|
|
|
|
lst.sourcefile.findLineForOffset(61440 + 15, 15));
|
2020-06-29 16:06:19 +00:00
|
|
|
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));
|
2019-05-03 22:58:35 +00:00
|
|
|
assert.equal(1, lst.sourcefile.lineCount());
|
|
|
|
done();
|
2018-06-30 14:26:41 +00:00
|
|
|
});
|
|
|
|
|
2018-06-29 23:44:04 +00:00
|
|
|
});
|