Pass with eslint --fix

Resolved whitespace issues, e.g., space-before-function-paren and key-spacing
This commit is contained in:
Ray Schamp 2016-10-23 12:41:45 -04:00
parent 36e4683aa8
commit 68ed110b49
21 changed files with 975 additions and 975 deletions

View file

@ -1,7 +1,7 @@
var Cast = require('../util/cast');
var Timer = require('../util/timer');
function Scratch3ControlBlocks(runtime) {
function Scratch3ControlBlocks (runtime) {
/**
* The runtime instantiating this block package.
* @type {Runtime}
@ -13,7 +13,7 @@ function Scratch3ControlBlocks(runtime) {
* Retrieve the block primitives implemented by this package.
* @return {Object.<string, Function>} Mapping of opcode to Function.
*/
Scratch3ControlBlocks.prototype.getPrimitives = function() {
Scratch3ControlBlocks.prototype.getPrimitives = function () {
return {
'control_repeat': this.repeat,
'control_repeat_until': this.repeatUntil,
@ -36,7 +36,7 @@ Scratch3ControlBlocks.prototype.getHats = function () {
};
};
Scratch3ControlBlocks.prototype.repeat = function(args, util) {
Scratch3ControlBlocks.prototype.repeat = function (args, util) {
var times = Math.floor(Cast.toNumber(args.TIMES));
// Initialize loop
if (util.stackFrame.loopCounter === undefined) {
@ -53,7 +53,7 @@ Scratch3ControlBlocks.prototype.repeat = function(args, util) {
}
};
Scratch3ControlBlocks.prototype.repeatUntil = function(args, util) {
Scratch3ControlBlocks.prototype.repeatUntil = function (args, util) {
var condition = Cast.toBoolean(args.CONDITION);
// If the condition is true, start the branch.
if (!condition) {
@ -61,18 +61,18 @@ Scratch3ControlBlocks.prototype.repeatUntil = function(args, util) {
}
};
Scratch3ControlBlocks.prototype.waitUntil = function(args, util) {
Scratch3ControlBlocks.prototype.waitUntil = function (args, util) {
var condition = Cast.toBoolean(args.CONDITION);
if (!condition) {
util.yield();
}
};
Scratch3ControlBlocks.prototype.forever = function(args, util) {
Scratch3ControlBlocks.prototype.forever = function (args, util) {
util.startBranch(1, true);
};
Scratch3ControlBlocks.prototype.wait = function(args, util) {
Scratch3ControlBlocks.prototype.wait = function (args, util) {
if (!util.stackFrame.timer) {
util.stackFrame.timer = new Timer();
util.stackFrame.timer.start();
@ -86,14 +86,14 @@ Scratch3ControlBlocks.prototype.wait = function(args, util) {
}
};
Scratch3ControlBlocks.prototype.if = function(args, util) {
Scratch3ControlBlocks.prototype.if = function (args, util) {
var condition = Cast.toBoolean(args.CONDITION);
if (condition) {
util.startBranch(1, false);
}
};
Scratch3ControlBlocks.prototype.ifElse = function(args, util) {
Scratch3ControlBlocks.prototype.ifElse = function (args, util) {
var condition = Cast.toBoolean(args.CONDITION);
if (condition) {
util.startBranch(1, false);
@ -102,7 +102,7 @@ Scratch3ControlBlocks.prototype.ifElse = function(args, util) {
}
};
Scratch3ControlBlocks.prototype.stop = function(args, util) {
Scratch3ControlBlocks.prototype.stop = function (args, util) {
var option = args.STOP_OPTION;
if (option == 'all') {
util.stopAll();

View file

@ -1,6 +1,6 @@
var Cast = require('../util/cast');
function Scratch3DataBlocks(runtime) {
function Scratch3DataBlocks (runtime) {
/**
* The runtime instantiating this block package.
* @type {Runtime}

View file

@ -1,6 +1,6 @@
var Cast = require('../util/cast');
function Scratch3EventBlocks(runtime) {
function Scratch3EventBlocks (runtime) {
/**
* The runtime instantiating this block package.
* @type {Runtime}
@ -12,7 +12,7 @@ function Scratch3EventBlocks(runtime) {
* Retrieve the block primitives implemented by this package.
* @return {Object.<string, Function>} Mapping of opcode to Function.
*/
Scratch3EventBlocks.prototype.getPrimitives = function() {
Scratch3EventBlocks.prototype.getPrimitives = function () {
return {
'event_broadcast': this.broadcast,
'event_broadcastandwait': this.broadcastAndWait,
@ -54,7 +54,7 @@ Scratch3EventBlocks.prototype.hatGreaterThanPredicate = function (args, util) {
return false;
};
Scratch3EventBlocks.prototype.broadcast = function(args, util) {
Scratch3EventBlocks.prototype.broadcast = function (args, util) {
var broadcastOption = Cast.toString(args.BROADCAST_OPTION);
util.startHats('event_whenbroadcastreceived', {
'BROADCAST_OPTION': broadcastOption
@ -78,7 +78,7 @@ Scratch3EventBlocks.prototype.broadcastAndWait = function (args, util) {
}
// We've run before; check if the wait is still going on.
var instance = this;
var waiting = util.stackFrame.startedThreads.some(function(thread) {
var waiting = util.stackFrame.startedThreads.some(function (thread) {
return instance.runtime.isActiveThread(thread);
});
if (waiting) {

View file

@ -1,6 +1,6 @@
var Cast = require('../util/cast');
function Scratch3LooksBlocks(runtime) {
function Scratch3LooksBlocks (runtime) {
/**
* The runtime instantiating this block package.
* @type {Runtime}
@ -12,7 +12,7 @@ function Scratch3LooksBlocks(runtime) {
* Retrieve the block primitives implemented by this package.
* @return {Object.<string, Function>} Mapping of opcode to Function.
*/
Scratch3LooksBlocks.prototype.getPrimitives = function() {
Scratch3LooksBlocks.prototype.getPrimitives = function () {
return {
'looks_say': this.say,
'looks_sayforsecs': this.sayforsecs,
@ -45,8 +45,8 @@ Scratch3LooksBlocks.prototype.say = function (args, util) {
Scratch3LooksBlocks.prototype.sayforsecs = function (args, util) {
util.target.setSay('say', args.MESSAGE);
return new Promise(function(resolve) {
setTimeout(function() {
return new Promise(function (resolve) {
setTimeout(function () {
// Clear say bubble and proceed.
util.target.setSay();
resolve();
@ -60,8 +60,8 @@ Scratch3LooksBlocks.prototype.think = function (args, util) {
Scratch3LooksBlocks.prototype.thinkforsecs = function (args, util) {
util.target.setSay('think', args.MESSAGE);
return new Promise(function(resolve) {
setTimeout(function() {
return new Promise(function (resolve) {
setTimeout(function () {
// Clear say bubble and proceed.
util.target.setSay();
resolve();
@ -149,7 +149,7 @@ Scratch3LooksBlocks.prototype.switchBackdropAndWait = function (args, util) {
}
// We've run before; check if the wait is still going on.
var instance = this;
var waiting = util.stackFrame.startedThreads.some(function(thread) {
var waiting = util.stackFrame.startedThreads.some(function (thread) {
return instance.runtime.isActiveThread(thread);
});
if (waiting) {

View file

@ -2,7 +2,7 @@ var Cast = require('../util/cast');
var MathUtil = require('../util/math-util');
var Timer = require('../util/timer');
function Scratch3MotionBlocks(runtime) {
function Scratch3MotionBlocks (runtime) {
/**
* The runtime instantiating this block package.
* @type {Runtime}
@ -14,7 +14,7 @@ function Scratch3MotionBlocks(runtime) {
* Retrieve the block primitives implemented by this package.
* @return {Object.<string, Function>} Mapping of opcode to Function.
*/
Scratch3MotionBlocks.prototype.getPrimitives = function() {
Scratch3MotionBlocks.prototype.getPrimitives = function () {
return {
'motion_movesteps': this.moveSteps,
'motion_gotoxy': this.goToXY,

View file

@ -1,6 +1,6 @@
var Cast = require('../util/cast.js');
function Scratch3OperatorsBlocks(runtime) {
function Scratch3OperatorsBlocks (runtime) {
/**
* The runtime instantiating this block package.
* @type {Runtime}
@ -12,7 +12,7 @@ function Scratch3OperatorsBlocks(runtime) {
* Retrieve the block primitives implemented by this package.
* @return {Object.<string, Function>} Mapping of opcode to Function.
*/
Scratch3OperatorsBlocks.prototype.getPrimitives = function() {
Scratch3OperatorsBlocks.prototype.getPrimitives = function () {
return {
'operator_add': this.add,
'operator_subtract': this.subtract,

View file

@ -1,4 +1,4 @@
function Scratch3ProcedureBlocks(runtime) {
function Scratch3ProcedureBlocks (runtime) {
/**
* The runtime instantiating this block package.
* @type {Runtime}
@ -10,7 +10,7 @@ function Scratch3ProcedureBlocks(runtime) {
* Retrieve the block primitives implemented by this package.
* @return {Object.<string, Function>} Mapping of opcode to Function.
*/
Scratch3ProcedureBlocks.prototype.getPrimitives = function() {
Scratch3ProcedureBlocks.prototype.getPrimitives = function () {
return {
'procedures_defnoreturn': this.defNoReturn,
'procedures_callnoreturn': this.callNoReturn,

View file

@ -1,6 +1,6 @@
var Cast = require('../util/cast');
function Scratch3SensingBlocks(runtime) {
function Scratch3SensingBlocks (runtime) {
/**
* The runtime instantiating this block package.
* @type {Runtime}
@ -12,7 +12,7 @@ function Scratch3SensingBlocks(runtime) {
* Retrieve the block primitives implemented by this package.
* @return {Object.<string, Function>} Mapping of opcode to Function.
*/
Scratch3SensingBlocks.prototype.getPrimitives = function() {
Scratch3SensingBlocks.prototype.getPrimitives = function () {
return {
'sensing_touchingobject': this.touchingObject,
'sensing_touchingcolor': this.touchingColor,
@ -114,11 +114,11 @@ Scratch3SensingBlocks.prototype.getKeyPressed = function (args, util) {
return util.ioQuery('keyboard', 'getKeyIsDown', args.KEY_OPTION);
};
Scratch3SensingBlocks.prototype.daysSince2000 = function()
Scratch3SensingBlocks.prototype.daysSince2000 = function ()
{
var msPerDay = 24 * 60 * 60 * 1000;
var start = new Date(2000, 1-1, 1);
var today = new Date();
var start = new Date(2000, 1-1, 1);
var today = new Date();
var dstAdjust = today.getTimezoneOffset() - start.getTimezoneOffset();
var mSecsSinceStart = today.valueOf() - start.valueOf();
mSecsSinceStart += ((today.getTimezoneOffset() - dstAdjust) * 60 * 1000);

View file

@ -170,7 +170,7 @@ var execute = function (sequencer, thread) {
primitiveReportedValue = blockFunction(argValues, {
stackFrame: currentStackFrame.executionContext,
target: target,
yield: function() {
yield: function () {
thread.status = Thread.STATUS_YIELD;
},
startBranch: function (branchNum, isLoop) {
@ -179,10 +179,10 @@ var execute = function (sequencer, thread) {
stopAll: function () {
runtime.stopAll();
},
stopOtherTargetThreads: function() {
stopOtherTargetThreads: function () {
runtime.stopForTarget(target, thread);
},
stopThread: function() {
stopThread: function () {
sequencer.retireThread(thread);
},
startProcedure: function (procedureCode) {
@ -197,7 +197,7 @@ var execute = function (sequencer, thread) {
getParam: function (paramName) {
return thread.getParam(paramName);
},
startHats: function(requestedHat, opt_matchFields, opt_target) {
startHats: function (requestedHat, opt_matchFields, opt_target) {
return (
runtime.startHats(requestedHat, opt_matchFields, opt_target)
);
@ -224,7 +224,7 @@ var execute = function (sequencer, thread) {
thread.status = Thread.STATUS_PROMISE_WAIT;
}
// Promise handlers
primitiveReportedValue.then(function(resolvedValue) {
primitiveReportedValue.then(function (resolvedValue) {
handleReport(resolvedValue);
if (typeof resolvedValue !== 'undefined') {
thread.popStack();
@ -233,7 +233,7 @@ var execute = function (sequencer, thread) {
var nextBlockId = thread.target.blocks.getNextBlock(popped);
thread.pushStack(nextBlockId);
}
}, function(rejectionReason) {
}, function (rejectionReason) {
// Promise rejected: the primitive had some error.
// Log it and proceed.
console.warn('Primitive rejected promise: ', rejectionReason);

View file

@ -394,7 +394,7 @@ Runtime.prototype.startHats = function (requestedHatOpcode,
var instance = this;
var newThreads = [];
// Consider all scripts, looking for hats with opcode `requestedHatOpcode`.
this.allScriptsDo(function(topBlockId, target) {
this.allScriptsDo(function (topBlockId, target) {
var potentialHatOpcode = target.blocks.getBlock(topBlockId).opcode;
if (potentialHatOpcode !== requestedHatOpcode) {
// Not the right hat.
@ -750,7 +750,7 @@ Runtime.prototype.start = function () {
interval = Runtime.THREAD_STEP_INTERVAL_COMPATIBILITY;
}
this.currentStepTime = interval;
this._steppingInterval = self.setInterval(function() {
this._steppingInterval = self.setInterval(function () {
this._step();
}.bind(this), interval);
};

View file

@ -78,7 +78,7 @@ Sequencer.prototype.stepThreads = function () {
ranFirstTick = true;
}
// Filter inactive threads from `this.runtime.threads`.
this.runtime.threads = this.runtime.threads.filter(function(thread) {
this.runtime.threads = this.runtime.threads.filter(function (thread) {
if (inactiveThreads.indexOf(thread) > -1) {
return false;
}

View file

@ -226,7 +226,7 @@ Thread.prototype.isRecursiveCall = function (procedureCode) {
for (var i = sp - 1; i >= 0; i--) {
var block = this.target.blocks.getBlock(this.stack[i]);
if (block.opcode == 'procedures_callnoreturn' &&
block.mutation.proccode == procedureCode) {
block.mutation.proccode == procedureCode) {
return true;
}
if (--callCount < 0) return false;

File diff suppressed because it is too large Load diff

View file

@ -106,11 +106,11 @@ VirtualMachine.prototype.clear = function () {
VirtualMachine.prototype.getPlaygroundData = function () {
var instance = this;
// Only send back thread data for the current editingTarget.
var threadData = this.runtime.threads.filter(function(thread) {
var threadData = this.runtime.threads.filter(function (thread) {
return thread.target == instance.editingTarget;
});
// Remove the target key, since it's a circular reference.
var filteredThreadData = JSON.stringify(threadData, function(key, value) {
var filteredThreadData = JSON.stringify(threadData, function (key, value) {
if (key == 'target') return undefined;
return value;
}, 2);
@ -297,7 +297,7 @@ VirtualMachine.prototype.emitTargetsUpdate = function () {
targetList: this.runtime.targets.filter(function (target) {
// Don't report clones.
return !target.hasOwnProperty('isOriginal') || target.isOriginal;
}).map(function(target) {
}).map(function (target) {
return [target.id, target.getName()];
}),
// Currently editing target id.

View file

@ -12,7 +12,7 @@ function Mouse (runtime) {
this.runtime = runtime;
}
Mouse.prototype.postData = function(data) {
Mouse.prototype.postData = function (data) {
if (data.x) {
this._x = data.x - data.canvasWidth / 2;
}

View file

@ -8,7 +8,7 @@ var Target = require('../engine/target');
* @param {Runtime} runtime Reference to the runtime.
* @constructor
*/
function Clone(sprite, runtime) {
function Clone (sprite, runtime) {
Target.call(this, sprite.blocks);
this.runtime = runtime;
/**
@ -447,7 +447,7 @@ Clone.prototype.isTouchingSprite = function (spriteName) {
if (!firstClone || !this.renderer) {
return false;
}
var drawableCandidates = firstClone.sprite.clones.map(function(clone) {
var drawableCandidates = firstClone.sprite.clones.map(function (clone) {
return clone.drawableID;
});
return this.renderer.isTouchingDrawables(

View file

@ -35,7 +35,7 @@ Color.decimalToRgb = function (decimal) {
*/
Color.hexToRgb = function (hex) {
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function(m, r, g, b) {
hex = hex.replace(shorthandRegex, function (m, r, g, b) {
return r + r + g + g + b + b;
});
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);

View file

@ -9,75 +9,75 @@ test('getPrimitives', function (t) {
});
test('add', function (t) {
t.strictEqual(blocks.add({NUM1:'1', NUM2:'1'}), 2);
t.strictEqual(blocks.add({NUM1:'foo', NUM2:'bar'}), 0);
t.strictEqual(blocks.add({NUM1: '1', NUM2: '1'}), 2);
t.strictEqual(blocks.add({NUM1: 'foo', NUM2: 'bar'}), 0);
t.end();
});
test('subtract', function (t) {
t.strictEqual(blocks.subtract({NUM1:'1', NUM2:'1'}), 0);
t.strictEqual(blocks.subtract({NUM1:'foo', NUM2:'bar'}), 0);
t.strictEqual(blocks.subtract({NUM1: '1', NUM2: '1'}), 0);
t.strictEqual(blocks.subtract({NUM1: 'foo', NUM2: 'bar'}), 0);
t.end();
});
test('multiply', function (t) {
t.strictEqual(blocks.multiply({NUM1:'2', NUM2:'2'}), 4);
t.strictEqual(blocks.multiply({NUM1:'foo', NUM2:'bar'}), 0);
t.strictEqual(blocks.multiply({NUM1: '2', NUM2: '2'}), 4);
t.strictEqual(blocks.multiply({NUM1: 'foo', NUM2: 'bar'}), 0);
t.end();
});
test('divide', function (t) {
t.strictEqual(blocks.divide({NUM1:'2', NUM2:'2'}), 1);
t.strictEqual(blocks.divide({NUM1:'1', NUM2:'0'}), Infinity); // @todo
t.ok(isNaN(blocks.divide({NUM1:'foo', NUM2:'bar'}))); // @todo
t.strictEqual(blocks.divide({NUM1: '2', NUM2: '2'}), 1);
t.strictEqual(blocks.divide({NUM1: '1', NUM2: '0'}), Infinity); // @todo
t.ok(isNaN(blocks.divide({NUM1: 'foo', NUM2: 'bar'}))); // @todo
t.end();
});
test('lt', function (t) {
t.strictEqual(blocks.lt({OPERAND1:'1', OPERAND2:'2'}), true);
t.strictEqual(blocks.lt({OPERAND1:'2', OPERAND2:'1'}), false);
t.strictEqual(blocks.lt({OPERAND1:'1', OPERAND2:'1'}), false);
t.strictEqual(blocks.lt({OPERAND1: '1', OPERAND2: '2'}), true);
t.strictEqual(blocks.lt({OPERAND1: '2', OPERAND2: '1'}), false);
t.strictEqual(blocks.lt({OPERAND1: '1', OPERAND2: '1'}), false);
t.end();
});
test('equals', function (t) {
t.strictEqual(blocks.equals({OPERAND1:'1', OPERAND2:'2'}), false);
t.strictEqual(blocks.equals({OPERAND1:'2', OPERAND2:'1'}), false);
t.strictEqual(blocks.equals({OPERAND1:'1', OPERAND2:'1'}), true);
t.strictEqual(blocks.equals({OPERAND1: '1', OPERAND2: '2'}), false);
t.strictEqual(blocks.equals({OPERAND1: '2', OPERAND2: '1'}), false);
t.strictEqual(blocks.equals({OPERAND1: '1', OPERAND2: '1'}), true);
t.end();
});
test('gt', function (t) {
t.strictEqual(blocks.gt({OPERAND1:'1', OPERAND2:'2'}), false);
t.strictEqual(blocks.gt({OPERAND1:'2', OPERAND2:'1'}), true);
t.strictEqual(blocks.gt({OPERAND1:'1', OPERAND2:'1'}), false);
t.strictEqual(blocks.gt({OPERAND1: '1', OPERAND2: '2'}), false);
t.strictEqual(blocks.gt({OPERAND1: '2', OPERAND2: '1'}), true);
t.strictEqual(blocks.gt({OPERAND1: '1', OPERAND2: '1'}), false);
t.end();
});
test('and', function (t) {
t.strictEqual(blocks.and({OPERAND1:true, OPERAND2:true}), true);
t.strictEqual(blocks.and({OPERAND1:true, OPERAND2:false}), false);
t.strictEqual(blocks.and({OPERAND1:false, OPERAND2:false}), false);
t.strictEqual(blocks.and({OPERAND1: true, OPERAND2: true}), true);
t.strictEqual(blocks.and({OPERAND1: true, OPERAND2: false}), false);
t.strictEqual(blocks.and({OPERAND1: false, OPERAND2: false}), false);
t.end();
});
test('or', function (t) {
t.strictEqual(blocks.or({OPERAND1:true, OPERAND2:true}), true);
t.strictEqual(blocks.or({OPERAND1:true, OPERAND2:false}), true);
t.strictEqual(blocks.or({OPERAND1:false, OPERAND2:false}), false);
t.strictEqual(blocks.or({OPERAND1: true, OPERAND2: true}), true);
t.strictEqual(blocks.or({OPERAND1: true, OPERAND2: false}), true);
t.strictEqual(blocks.or({OPERAND1: false, OPERAND2: false}), false);
t.end();
});
test('not', function (t) {
t.strictEqual(blocks.not({OPERAND:true}), false);
t.strictEqual(blocks.not({OPERAND:false}), true);
t.strictEqual(blocks.not({OPERAND: true}), false);
t.strictEqual(blocks.not({OPERAND: false}), true);
t.end();
});
test('random', function (t) {
var min = 0;
var max = 100;
var result = blocks.random({FROM:min, TO:max});
var result = blocks.random({FROM: min, TO: max});
t.ok(result >= min);
t.ok(result <= max);
t.end();
@ -86,14 +86,14 @@ test('random', function (t) {
test('random - equal', function (t) {
var min = 1;
var max = 1;
t.strictEqual(blocks.random({FROM:min, TO:max}), min);
t.strictEqual(blocks.random({FROM: min, TO: max}), min);
t.end();
});
test('random - decimal', function (t) {
var min = 0.1;
var max = 10;
var result = blocks.random({FROM:min, TO:max});
var result = blocks.random({FROM: min, TO: max});
t.ok(result >= min);
t.ok(result <= max);
t.end();
@ -102,7 +102,7 @@ test('random - decimal', function (t) {
test('random - int', function (t) {
var min = 0;
var max = 10;
var result = blocks.random({FROM:min, TO:max});
var result = blocks.random({FROM: min, TO: max});
t.ok(result >= min);
t.ok(result <= max);
t.end();
@ -111,65 +111,65 @@ test('random - int', function (t) {
test('random - reverse', function (t) {
var min = 0;
var max = 10;
var result = blocks.random({FROM:max, TO:min});
var result = blocks.random({FROM: max, TO: min});
t.ok(result >= min);
t.ok(result <= max);
t.end();
});
test('join', function (t) {
t.strictEqual(blocks.join({STRING1:'foo', STRING2:'bar'}), 'foobar');
t.strictEqual(blocks.join({STRING1:'1', STRING2:'2'}), '12');
t.strictEqual(blocks.join({STRING1: 'foo', STRING2: 'bar'}), 'foobar');
t.strictEqual(blocks.join({STRING1: '1', STRING2: '2'}), '12');
t.end();
});
test('letterOf', function (t) {
t.strictEqual(blocks.letterOf({STRING:'foo', LETTER:0}), '');
t.strictEqual(blocks.letterOf({STRING:'foo', LETTER:1}), 'f');
t.strictEqual(blocks.letterOf({STRING:'foo', LETTER:2}), 'o');
t.strictEqual(blocks.letterOf({STRING:'foo', LETTER:3}), 'o');
t.strictEqual(blocks.letterOf({STRING:'foo', LETTER:4}), '');
t.strictEqual(blocks.letterOf({STRING:'foo', LETTER:'bar'}), '');
t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 0}), '');
t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 1}), 'f');
t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 2}), 'o');
t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 3}), 'o');
t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 4}), '');
t.strictEqual(blocks.letterOf({STRING: 'foo', LETTER: 'bar'}), '');
t.end();
});
test('length', function (t) {
t.strictEqual(blocks.length({STRING:''}), 0);
t.strictEqual(blocks.length({STRING:'foo'}), 3);
t.strictEqual(blocks.length({STRING:'1'}), 1);
t.strictEqual(blocks.length({STRING:'100'}), 3);
t.strictEqual(blocks.length({STRING: ''}), 0);
t.strictEqual(blocks.length({STRING: 'foo'}), 3);
t.strictEqual(blocks.length({STRING: '1'}), 1);
t.strictEqual(blocks.length({STRING: '100'}), 3);
t.end();
});
test('mod', function (t) {
t.strictEqual(blocks.mod({NUM1:1, NUM2:1}), 0);
t.strictEqual(blocks.mod({NUM1:3, NUM2:6}), 3);
t.strictEqual(blocks.mod({NUM1:-3, NUM2:6}), 3);
t.strictEqual(blocks.mod({NUM1: 1, NUM2: 1}), 0);
t.strictEqual(blocks.mod({NUM1: 3, NUM2: 6}), 3);
t.strictEqual(blocks.mod({NUM1: -3, NUM2: 6}), 3);
t.end();
});
test('round', function (t) {
t.strictEqual(blocks.round({NUM:1}), 1);
t.strictEqual(blocks.round({NUM:1.1}), 1);
t.strictEqual(blocks.round({NUM:1.5}), 2);
t.strictEqual(blocks.round({NUM: 1}), 1);
t.strictEqual(blocks.round({NUM: 1.1}), 1);
t.strictEqual(blocks.round({NUM: 1.5}), 2);
t.end();
});
test('mathop', function (t) {
t.strictEqual(blocks.mathop({OPERATOR:'abs', NUM:-1}), 1);
t.strictEqual(blocks.mathop({OPERATOR:'floor', NUM:1.5}), 1);
t.strictEqual(blocks.mathop({OPERATOR:'ceiling', NUM:0.1}), 1);
t.strictEqual(blocks.mathop({OPERATOR:'sqrt', NUM:1}), 1);
t.strictEqual(blocks.mathop({OPERATOR:'sin', NUM:1}), 0.01745240643728351);
t.strictEqual(blocks.mathop({OPERATOR:'cos', NUM:1}), 0.9998476951563913);
t.strictEqual(blocks.mathop({OPERATOR:'tan', NUM:1}), 0.017455064928217585);
t.strictEqual(blocks.mathop({OPERATOR:'asin', NUM:1}), 90);
t.strictEqual(blocks.mathop({OPERATOR:'acos', NUM:1}), 0);
t.strictEqual(blocks.mathop({OPERATOR:'atan', NUM:1}), 45);
t.strictEqual(blocks.mathop({OPERATOR:'ln', NUM:1}), 0);
t.strictEqual(blocks.mathop({OPERATOR:'log', NUM:1}), 0);
t.strictEqual(blocks.mathop({OPERATOR:'e ^', NUM:1}), 2.718281828459045);
t.strictEqual(blocks.mathop({OPERATOR:'10 ^', NUM:1}), 10);
t.strictEqual(blocks.mathop({OPERATOR:'undefined', NUM:1}), 0);
t.strictEqual(blocks.mathop({OPERATOR: 'abs', NUM: -1}), 1);
t.strictEqual(blocks.mathop({OPERATOR: 'floor', NUM: 1.5}), 1);
t.strictEqual(blocks.mathop({OPERATOR: 'ceiling', NUM: 0.1}), 1);
t.strictEqual(blocks.mathop({OPERATOR: 'sqrt', NUM: 1}), 1);
t.strictEqual(blocks.mathop({OPERATOR: 'sin', NUM: 1}), 0.01745240643728351);
t.strictEqual(blocks.mathop({OPERATOR: 'cos', NUM: 1}), 0.9998476951563913);
t.strictEqual(blocks.mathop({OPERATOR: 'tan', NUM: 1}), 0.017455064928217585);
t.strictEqual(blocks.mathop({OPERATOR: 'asin', NUM: 1}), 90);
t.strictEqual(blocks.mathop({OPERATOR: 'acos', NUM: 1}), 0);
t.strictEqual(blocks.mathop({OPERATOR: 'atan', NUM: 1}), 45);
t.strictEqual(blocks.mathop({OPERATOR: 'ln', NUM: 1}), 0);
t.strictEqual(blocks.mathop({OPERATOR: 'log', NUM: 1}), 0);
t.strictEqual(blocks.mathop({OPERATOR: 'e ^', NUM: 1}), 2.718281828459045);
t.strictEqual(blocks.mathop({OPERATOR: '10 ^', NUM: 1}), 10);
t.strictEqual(blocks.mathop({OPERATOR: 'undefined', NUM: 1}), 0);
t.end();
});

View file

@ -7,10 +7,10 @@ test('spec', function (t) {
t.end();
});
test('invalid inputs', function(t) {
test('invalid inputs', function (t) {
var nothing = adapter('not an object');
t.type(nothing, 'undefined');
nothing = adapter({noxmlproperty:true});
nothing = adapter({noxmlproperty: true});
t.type(nothing, 'undefined');
t.end();
});
@ -26,7 +26,7 @@ test('create event', function (t) {
t.type(result[0].opcode, 'string');
t.type(result[0].fields, 'object');
t.type(result[0].inputs, 'object');
t.type(result[0].inputs['DURATION'], 'object');
t.type(result[0].inputs.DURATION, 'object');
t.type(result[0].topLevel, 'boolean');
t.equal(result[0].topLevel, true);
@ -35,8 +35,8 @@ test('create event', function (t) {
t.type(result[1].opcode, 'string');
t.type(result[1].fields, 'object');
t.type(result[1].inputs, 'object');
t.type(result[1].fields['NUM'], 'object');
t.type(result[1].fields['NUM'].value, '10');
t.type(result[1].fields.NUM, 'object');
t.type(result[1].fields.NUM.value, '10');
t.type(result[1].topLevel, 'boolean');
t.equal(result[1].topLevel, false);
@ -50,12 +50,12 @@ test('create with branch', function (t) {
t.type(result[0].opcode, 'string');
t.type(result[0].fields, 'object');
t.type(result[0].inputs, 'object');
t.type(result[0].inputs['SUBSTACK'], 'object');
t.type(result[0].inputs.SUBSTACK, 'object');
t.type(result[0].topLevel, 'boolean');
t.equal(result[0].topLevel, true);
// In branch
var branchBlockId = result[0].inputs['SUBSTACK']['block'];
var branchShadowId = result[0].inputs['SUBSTACK']['shadow'];
var branchBlockId = result[0].inputs.SUBSTACK.block;
var branchShadowId = result[0].inputs.SUBSTACK.shadow;
t.type(branchBlockId, 'string');
t.equal(branchShadowId, null);
// Find actual branch block
@ -76,17 +76,17 @@ test('create with two branches', function (t) {
t.type(result[0].opcode, 'string');
t.type(result[0].fields, 'object');
t.type(result[0].inputs, 'object');
t.type(result[0].inputs['SUBSTACK'], 'object');
t.type(result[0].inputs['SUBSTACK2'], 'object');
t.type(result[0].inputs.SUBSTACK, 'object');
t.type(result[0].inputs.SUBSTACK2, 'object');
t.type(result[0].topLevel, 'boolean');
t.equal(result[0].topLevel, true);
// In branchs
var firstBranchBlockId = result[0].inputs['SUBSTACK']['block'];
var secondBranchBlockId = result[0].inputs['SUBSTACK2']['block'];
var firstBranchBlockId = result[0].inputs.SUBSTACK.block;
var secondBranchBlockId = result[0].inputs.SUBSTACK2.block;
t.type(firstBranchBlockId, 'string');
t.type(secondBranchBlockId, 'string');
var firstBranchShadowBlockId = result[0].inputs['SUBSTACK']['shadow'];
var secondBranchShadowBlockId = result[0].inputs['SUBSTACK2']['shadow'];
var firstBranchShadowBlockId = result[0].inputs.SUBSTACK.shadow;
var secondBranchShadowBlockId = result[0].inputs.SUBSTACK2.shadow;
t.equal(firstBranchShadowBlockId, null);
t.equal(secondBranchShadowBlockId, null);
// Find actual branch blocks

View file

@ -245,8 +245,8 @@ test('create', function (t) {
topLevel: true
});
t.type(b._blocks['foo'], 'object');
t.equal(b._blocks['foo'].opcode, 'TEST_BLOCK');
t.type(b._blocks.foo, 'object');
t.equal(b._blocks.foo.opcode, 'TEST_BLOCK');
t.notEqual(b._scripts.indexOf('foo'), -1);
t.end();
});
@ -277,7 +277,7 @@ test('move', function (t) {
});
t.equal(b._scripts.length, 1);
t.equal(Object.keys(b._blocks).length, 2);
t.equal(b._blocks['foo'].next, 'bar');
t.equal(b._blocks.foo.next, 'bar');
// Detach 'bar' from 'foo'
b.moveBlock({
@ -286,7 +286,7 @@ test('move', function (t) {
});
t.equal(b._scripts.length, 2);
t.equal(Object.keys(b._blocks).length, 2);
t.equal(b._blocks['foo'].next, null);
t.equal(b._blocks.foo.next, null);
t.end();
});
@ -314,7 +314,7 @@ test('move into empty', function (t) {
newInput: 'fooInput',
newParent: 'foo'
});
t.equal(b._blocks['foo'].inputs['fooInput'].block, 'bar');
t.equal(b._blocks.foo.inputs.fooInput.block, 'bar');
t.end();
});
@ -347,8 +347,8 @@ test('move no obscure shadow', function (t) {
newInput: 'fooInput',
newParent: 'foo'
});
t.equal(b._blocks['foo'].inputs['fooInput'].block, 'bar');
t.equal(b._blocks['foo'].inputs['fooInput'].shadow, 'y');
t.equal(b._blocks.foo.inputs.fooInput.block, 'bar');
t.equal(b._blocks.foo.inputs.fooInput.shadow, 'y');
t.end();
});
@ -369,7 +369,7 @@ test('change', function (t) {
});
// Test that the field is updated
t.equal(b._blocks['foo'].fields.someField.value, 'initial-value');
t.equal(b._blocks.foo.fields.someField.value, 'initial-value');
b.changeBlock({
element: 'field',
@ -378,7 +378,7 @@ test('change', function (t) {
value: 'final-value'
});
t.equal(b._blocks['foo'].fields.someField.value, 'final-value');
t.equal(b._blocks.foo.fields.someField.value, 'final-value');
// Invalid cases
// No `element`
@ -387,7 +387,7 @@ test('change', function (t) {
name: 'someField',
value: 'invalid-value'
});
t.equal(b._blocks['foo'].fields.someField.value, 'final-value');
t.equal(b._blocks.foo.fields.someField.value, 'final-value');
// No block ID
b.changeBlock({
@ -395,7 +395,7 @@ test('change', function (t) {
name: 'someField',
value: 'invalid-value'
});
t.equal(b._blocks['foo'].fields.someField.value, 'final-value');
t.equal(b._blocks.foo.fields.someField.value, 'final-value');
// No such field
b.changeBlock({
@ -404,7 +404,7 @@ test('change', function (t) {
name: 'someWrongField',
value: 'final-value'
});
t.equal(b._blocks['foo'].fields.someField.value, 'final-value');
t.equal(b._blocks.foo.fields.someField.value, 'final-value');
t.end();
});
@ -423,7 +423,7 @@ test('delete', function (t) {
id: 'foo'
});
t.type(b._blocks['foo'], 'undefined');
t.type(b._blocks.foo, 'undefined');
t.equal(b._scripts.indexOf('foo'), -1);
t.end();
});
@ -459,9 +459,9 @@ test('delete chain', function (t) {
b.deleteBlock({
id: 'foo'
});
t.type(b._blocks['foo'], 'undefined');
t.type(b._blocks['foo2'], 'undefined');
t.type(b._blocks['foo3'], 'undefined');
t.type(b._blocks.foo, 'undefined');
t.type(b._blocks.foo2, 'undefined');
t.type(b._blocks.foo3, 'undefined');
t.equal(b._scripts.indexOf('foo'), -1);
t.equal(Object.keys(b._blocks).length, 0);
t.equal(b._scripts.length, 0);
@ -532,11 +532,11 @@ test('delete inputs', function (t) {
b.deleteBlock({
id: 'foo'
});
t.type(b._blocks['foo'], 'undefined');
t.type(b._blocks['foo2'], 'undefined');
t.type(b._blocks['foo3'], 'undefined');
t.type(b._blocks['foo4'], 'undefined');
t.type(b._blocks['foo5'], 'undefined');
t.type(b._blocks.foo, 'undefined');
t.type(b._blocks.foo2, 'undefined');
t.type(b._blocks.foo3, 'undefined');
t.type(b._blocks.foo4, 'undefined');
t.type(b._blocks.foo5, 'undefined');
t.equal(b._scripts.indexOf('foo'), -1);
t.equal(Object.keys(b._blocks).length, 0);
t.equal(b._scripts.length, 0);

View file

@ -11,25 +11,25 @@ test('decimalToHex', function (t) {
});
test('decimalToRgb', function (t) {
t.deepEqual(color.decimalToRgb(0), {r:0,g:0,b:0});
t.deepEqual(color.decimalToRgb(1), {r:0,g:0,b:1});
t.deepEqual(color.decimalToRgb(16777215), {r:255,g:255,b:255});
t.deepEqual(color.decimalToRgb(-16777215), {r:0,g:0,b:1});
t.deepEqual(color.decimalToRgb(99999999), {r:245,g:224,b:255});
t.deepEqual(color.decimalToRgb(0), {r: 0,g: 0,b: 0});
t.deepEqual(color.decimalToRgb(1), {r: 0,g: 0,b: 1});
t.deepEqual(color.decimalToRgb(16777215), {r: 255,g: 255,b: 255});
t.deepEqual(color.decimalToRgb(-16777215), {r: 0,g: 0,b: 1});
t.deepEqual(color.decimalToRgb(99999999), {r: 245,g: 224,b: 255});
t.end();
});
test('hexToRgb', function (t) {
t.deepEqual(color.hexToRgb('#000'), {r:0,g:0,b:0});
t.deepEqual(color.hexToRgb('#000000'), {r:0,g:0,b:0});
t.deepEqual(color.hexToRgb('#fff'), {r:255,g:255,b:255});
t.deepEqual(color.hexToRgb('#ffffff'), {r:255,g:255,b:255});
t.deepEqual(color.hexToRgb('#0fa'), {r:0,g:255,b:170});
t.deepEqual(color.hexToRgb('#00ffaa'), {r:0,g:255,b:170});
t.deepEqual(color.hexToRgb('#000'), {r: 0,g: 0,b: 0});
t.deepEqual(color.hexToRgb('#000000'), {r: 0,g: 0,b: 0});
t.deepEqual(color.hexToRgb('#fff'), {r: 255,g: 255,b: 255});
t.deepEqual(color.hexToRgb('#ffffff'), {r: 255,g: 255,b: 255});
t.deepEqual(color.hexToRgb('#0fa'), {r: 0,g: 255,b: 170});
t.deepEqual(color.hexToRgb('#00ffaa'), {r: 0,g: 255,b: 170});
t.deepEqual(color.hexToRgb('000'), {r:0,g:0,b:0});
t.deepEqual(color.hexToRgb('fff'), {r:255,g:255,b:255});
t.deepEqual(color.hexToRgb('00ffaa'), {r:0,g:255,b:170});
t.deepEqual(color.hexToRgb('000'), {r: 0,g: 0,b: 0});
t.deepEqual(color.hexToRgb('fff'), {r: 255,g: 255,b: 255});
t.deepEqual(color.hexToRgb('00ffaa'), {r: 0,g: 255,b: 170});
t.deepEqual(color.hexToRgb('0'), null);
t.deepEqual(color.hexToRgb('hello world'), null);
@ -38,16 +38,16 @@ test('hexToRgb', function (t) {
});
test('rgbToHex', function (t) {
t.strictEqual(color.rgbToHex({r:0,g:0,b:0}), '#000000');
t.strictEqual(color.rgbToHex({r:255,g:255,b:255}), '#ffffff');
t.strictEqual(color.rgbToHex({r:0,g:255,b:170}), '#00ffaa');
t.strictEqual(color.rgbToHex({r: 0,g: 0,b: 0}), '#000000');
t.strictEqual(color.rgbToHex({r: 255,g: 255,b: 255}), '#ffffff');
t.strictEqual(color.rgbToHex({r: 0,g: 255,b: 170}), '#00ffaa');
t.end();
});
test('rgbToDecimal', function (t) {
t.strictEqual(color.rgbToDecimal({r:0,g:0,b:0}), 0);
t.strictEqual(color.rgbToDecimal({r:255,g:255,b:255}), 16777215);
t.strictEqual(color.rgbToDecimal({r:0,g:255,b:170}), 65450);
t.strictEqual(color.rgbToDecimal({r: 0,g: 0,b: 0}), 0);
t.strictEqual(color.rgbToDecimal({r: 255,g: 255,b: 255}), 16777215);
t.strictEqual(color.rgbToDecimal({r: 0,g: 255,b: 170}), 65450);
t.end();
});