Skip to content

Commit 1560682

Browse files
committed
Improved test cases and error detection for automatic tests.
1 parent 44d7c2d commit 1560682

File tree

44 files changed

+243
-595
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+243
-595
lines changed

.eslintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
'i18soy': true,
4242
'i18t': true,
4343
'it': true,
44+
'loadExampleFile': true,
45+
'loadTemplateFile': true,
4446
'soydata': true,
4547
'var_args': true,
4648
'window': true,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"private": true,
88
"dependencies": {
99
"closure-builder": "^2.2.38",
10-
"command-line-usage": "^5.0.2",
10+
"command-line-usage": "^5.0.3",
1111
"jasmine-core": "^2.99.1",
1212
"jsdoc": "^3.5.5",
1313
"karma": "^1.7.1",

src/addon/message/message.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ cwc.addon.Message.prototype.eventsModder = function(e) {
7272
let mode = e.data.mode;
7373
let fileName = e.data.file;
7474
this.log_.info('Change Mode', mode, 'for file', fileName);
75-
let content = this.helper.getInstance('file').getFile().getMetadata('content',
76-
'message');
77-
let help = this.helper.getInstance('file').getFile().getMetadata('help',
78-
'message');
75+
let file = this.helper.getInstance('file').getFile();
76+
if (!file) return;
77+
let content = file.getMetadata('content', 'message');
78+
let help = file.getMetadata('help', 'message');
7979
if (content || help) {
8080
this.log_.info('Adding message pane ...');
8181
let messageInstance = this.helper.getInstance('message');
@@ -95,4 +95,3 @@ cwc.addon.Message.prototype.eventsModder = function(e) {
9595
}
9696
}
9797
};
98-

src/file_format/file_format.js

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -562,59 +562,55 @@ cwc.fileFormat.File.loadJSON = function(file, data) {
562562
}
563563
}
564564

565+
/**
566+
* Handling of additional fields.
567+
*/
565568
if (jsonData['flags']) {
566569
for (let flag in jsonData['flags']) {
567570
if (Object.prototype.hasOwnProperty.call(jsonData['flags'], flag)) {
568571
file.setFlag(flag, jsonData['flags'][flag]);
569572
}
570573
}
571574
}
572-
573575
if (jsonData['mode']) {
574-
file.setMode(decodeURIComponent(jsonData['mode']));
576+
file.setMode(
577+
/** @type {cwc.mode.Type} */ (decodeURIComponent(jsonData['mode'])));
575578
}
576-
577579
if (jsonData['ui']) {
578580
file.setUi(decodeURIComponent(jsonData['ui']));
579581
}
580-
581582
if (jsonData['frameworks']) {
582583
file.setFrameworks(jsonData['frameworks']);
583584
}
584-
585585
if (jsonData['files']) {
586586
file.setFilesData(jsonData['files']);
587587
}
588-
589588
if (jsonData['history']) {
590589
file.setHistory(jsonData['history']);
591590
}
592-
593591
if (jsonData['metadata']) {
594592
file.metadata_ = jsonData['metadata'];
595593
}
596594

597595
/**
598-
* Deprecated fields from file format < 3.0
596+
* Handling of deprecated fields for file format < 3.0
599597
*/
600-
if (jsonData['author']) {
601-
file.setAuthor(decodeURIComponent(jsonData['author']));
602-
}
603-
604-
if (jsonData['description']) {
605-
file.setModel(decodeURIComponent(jsonData['description']));
606-
}
607-
608-
if (jsonData['model']) {
609-
file.setModel(decodeURIComponent(jsonData['model']));
610-
}
611-
612-
if (jsonData['title']) {
613-
file.setTitle(decodeURIComponent(jsonData['title']));
614-
}
615-
616-
if (jsonData['version']) {
617-
file.setVersion(decodeURIComponent(jsonData['version']));
598+
if (fileFormatVersion < 3) {
599+
if (jsonData['author']) {
600+
file.setAuthor(decodeURIComponent(jsonData['author']));
601+
}
602+
if (jsonData['description']) {
603+
file.setModel(decodeURIComponent(jsonData['description']));
604+
}
605+
if (jsonData['model']) {
606+
file.setModel(decodeURIComponent(jsonData['model']));
607+
}
608+
if (jsonData['title']) {
609+
file.setTitle(decodeURIComponent(jsonData['title']));
610+
}
611+
if (jsonData['version']) {
612+
file.setVersion(decodeURIComponent(jsonData['version']));
613+
}
618614
}
619615
};
620616

src/file_handler/file_loader.js

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,20 @@ cwc.fileHandler.FileLoader.prototype.loadFileData = function(file,
9797

9898

9999
/**
100-
* @param {!string} filename
100+
* @param {!string} file
101101
* @return {Promise}
102102
* @export
103103
*/
104-
cwc.fileHandler.FileLoader.prototype.loadLocalFile = function(filename) {
104+
cwc.fileHandler.FileLoader.prototype.loadLocalFile = function(file) {
105+
this.log_.info('Loading file', file, '...');
105106
return new Promise((resolve, reject) => {
106-
this.getResourceFile(filename, (filename, data) => {
107-
this.handleFileData(data, filename, null, undefined).then(
108-
resolve
109-
).catch((e) => {
110-
this.log_.error('Loading error:', e);
111-
reject();
112-
});
107+
let filename = file.replace(/^.*(\\|\/|:)/, '');
108+
return cwc.utils.Resources.getUriAsText(file).then((content) => {
109+
return this.handleFileData(content, filename, null, undefined)
110+
.then(resolve).catch(reject);
111+
}).catch((e) => {
112+
this.helper.showError(String(e));
113+
reject(e);
113114
});
114115
});
115116
};
@@ -289,21 +290,3 @@ cwc.fileHandler.FileLoader.prototype.openFile = function(file, file_entry,
289290
this.helper.showError('Unable to open file ' + file + '!');
290291
}
291292
};
292-
293-
294-
/**
295-
* @param {string} file
296-
* @param {function(string, string)=} callback
297-
*/
298-
cwc.fileHandler.FileLoader.prototype.getResourceFile = function(file,
299-
callback) {
300-
if (file) {
301-
this.log_.info('Loading file', file, '...');
302-
let filename = file.replace(/^.*(\\|\/|:)/, '');
303-
cwc.utils.Resources.getUriAsText(file).then((content) => {
304-
callback(filename, content);
305-
}).catch((error) => {
306-
this.helper.showError(String(error));
307-
});
308-
}
309-
};

src/mode/default/mod.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ cwc.mode.default.RunnerTypes;
6565
/**
6666
* @typedef {cwc.mode.ev3.Monitor|
6767
* cwc.mode.sphero.Monitor|
68-
* cwc.mode.makeblock.mbot.Monitor}
68+
* cwc.mode.makeblock.mbot.Monitor|
69+
* cwc.mode.makeblock.mbotRanger.Monitor}
6970
*/
7071
cwc.mode.default.MonitorTypes;
7172

src/mode/mode_config_data.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ goog.require('cwc.mode.phaser.advanced.Mod');
3838
goog.require('cwc.mode.phaser.blockly.Mod');
3939
goog.require('cwc.mode.python.Mod');
4040
goog.require('cwc.mode.raspberryPi.advanced.Mod');
41-
goog.require('cwc.mode.sphero.advanced.Mod');
41+
goog.require('cwc.mode.sphero.classic.advanced.Mod');
4242
goog.require('cwc.mode.sphero.bb8.blockly.Mod');
43-
goog.require('cwc.mode.sphero.blockly.Mod');
43+
goog.require('cwc.mode.sphero.classic.blockly.Mod');
4444
goog.require('cwc.mode.sphero.ollie.blockly.Mod');
4545
goog.require('cwc.mode.sphero.sprkPlus.advanced.Mod');
4646
goog.require('cwc.mode.sphero.sprkPlus.blockly.Mod');
@@ -346,7 +346,7 @@ cwc.mode.ConfigData[cwc.mode.Type.SPHERO] = new cwc.mode.Mod({
346346
authors: ['Markus Bordihn'],
347347
icon: 'adjust',
348348
mime_types: [cwc.file.MimeType.CWC.type],
349-
mod: cwc.mode.sphero.advanced.Mod,
349+
mod: cwc.mode.sphero.classic.advanced.Mod,
350350
name: 'Sphero 2.0',
351351
template: 'sphero/classic/blank.cwc',
352352
});
@@ -359,7 +359,7 @@ cwc.mode.ConfigData[cwc.mode.Type.SPHERO_BLOCKLY] = new cwc.mode.Mod({
359359
authors: ['Markus Bordihn'],
360360
icon: 'adjust',
361361
mime_types: [cwc.file.MimeType.CWC.type],
362-
mod: cwc.mode.sphero.blockly.Mod,
362+
mod: cwc.mode.sphero.classic.blockly.Mod,
363363
name: 'Sphero 2.0 blockly',
364364
template: 'sphero/classic/blank-blocks.cwc',
365365
});

src/mode/sphero/advanced/mod.js renamed to src/mode/sphero/classic/advanced/mod.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @author [email protected] (Markus Bordihn)
1919
*/
20-
goog.provide('cwc.mode.sphero.advanced.Mod');
20+
goog.provide('cwc.mode.sphero.classic.advanced.Mod');
2121

2222
goog.require('cwc.mode.default.Mod');
2323
goog.require('cwc.mode.sphero.Connection');
@@ -31,7 +31,7 @@ goog.require('cwc.renderer.external.Sphero');
3131
* @constructor
3232
* @param {!cwc.utils.Helper} helper
3333
*/
34-
cwc.mode.sphero.advanced.Mod = function(helper) {
34+
cwc.mode.sphero.classic.advanced.Mod = function(helper) {
3535
/** @type {!cwc.mode.default.Mod} */
3636
this.mod = new cwc.mode.default.Mod(helper);
3737

@@ -52,7 +52,7 @@ cwc.mode.sphero.advanced.Mod = function(helper) {
5252
/**
5353
* Decorates the different parts of the modification.
5454
*/
55-
cwc.mode.sphero.advanced.Mod.prototype.decorate = function() {
55+
cwc.mode.sphero.classic.advanced.Mod.prototype.decorate = function() {
5656
this.mod.setConnection(this.connection);
5757
this.mod.setMonitor(this.monitor);
5858
this.mod.setRenderer(this.renderer);

src/mode/sphero/blockly/mod.js renamed to src/mode/sphero/classic/blockly/mod.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @author [email protected] (Markus Bordihn)
1919
*/
20-
goog.provide('cwc.mode.sphero.blockly.Mod');
20+
goog.provide('cwc.mode.sphero.classic.blockly.Mod');
2121

2222
goog.require('cwc.mode.default.Mod');
2323
goog.require('cwc.mode.sphero.Connection');
@@ -31,7 +31,7 @@ goog.require('cwc.soy.sphero.Blocks');
3131
* @constructor
3232
* @param {!cwc.utils.Helper} helper
3333
*/
34-
cwc.mode.sphero.blockly.Mod = function(helper) {
34+
cwc.mode.sphero.classic.blockly.Mod = function(helper) {
3535
/** @type {!cwc.mode.default.Mod} */
3636
this.mod = new cwc.mode.default.Mod(helper);
3737

@@ -52,7 +52,7 @@ cwc.mode.sphero.blockly.Mod = function(helper) {
5252
/**
5353
* Decorates the different parts of the modification.
5454
*/
55-
cwc.mode.sphero.blockly.Mod.prototype.decorate = function() {
55+
cwc.mode.sphero.classic.blockly.Mod.prototype.decorate = function() {
5656
this.mod.enableBlockly(cwc.soy.sphero.Blocks.toolbox);
5757
this.mod.setConnection(this.connection);
5858
this.mod.setMonitor(this.monitor);

src/mode/sphero/monitor.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ cwc.mode.sphero.Monitor = function(helper, connection) {
4747
/** @type {!string} */
4848
this.prefix = this.helper.getPrefix('sphero-monitor');
4949

50-
/** @type {!cwc.mode.sphero.Connection} */
50+
/**
51+
* @type {!cwc.mode.sphero.Connection|
52+
* cwc.mode.sphero.bb8.Connection|
53+
* cwc.mode.sphero.sprkPlus.Connection|
54+
* cwc.mode.sphero.ollie.Connection}
55+
*/
5156
this.connection = connection;
5257

5358
/** @type {!cwc.protocol.sphero.classic.Api} */

0 commit comments

Comments
 (0)