mirror of
https://github.com/google/blockly.git
synced 2026-01-09 18:10:08 +01:00
Merge branch 'develop' into moniika-render-collapsed
This commit is contained in:
@@ -429,7 +429,7 @@ Blockly.Events.Move.prototype.fromJson = function(json) {
|
||||
if (json['newCoordinate']) {
|
||||
var xy = json['newCoordinate'].split(',');
|
||||
this.newCoordinate =
|
||||
new Blockly.utils.Coordinate(parseFloat(xy[0]), parseFloat(xy[1]));
|
||||
new Blockly.utils.Coordinate(Number(xy[0]), Number(xy[1]));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -605,7 +605,7 @@ Blockly.BlockSvg.prototype.createTabList_ = function() {
|
||||
var list = [];
|
||||
for (var i = 0, input; input = this.inputList[i]; i++) {
|
||||
for (var j = 0, field; field = input.fieldRow[j]; j++) {
|
||||
if (field instanceof Blockly.FieldTextInput) {
|
||||
if (field instanceof Blockly.FieldTextInput && field.isVisible()) {
|
||||
// TODO (#1276): Also support dropdown fields.
|
||||
list.push(field);
|
||||
}
|
||||
|
||||
@@ -340,11 +340,10 @@ Blockly.FieldAngle.prototype.updateGraph_ = function() {
|
||||
* @override
|
||||
*/
|
||||
Blockly.FieldAngle.prototype.doClassValidation_ = function(opt_newValue) {
|
||||
if (isNaN(opt_newValue)) {
|
||||
var n = Number(opt_newValue) % 360;
|
||||
if (isNaN(n)) {
|
||||
return null;
|
||||
}
|
||||
var n = parseFloat(opt_newValue || 0);
|
||||
n %= 360;
|
||||
if (n < 0) {
|
||||
n += 360;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ Blockly.FieldNumber.prototype.SERIALIZABLE = true;
|
||||
|
||||
/**
|
||||
* Set the maximum, minimum and precision constraints on this field.
|
||||
* Any of these properties may be undefiend or NaN to be disabled.
|
||||
* Any of these properties may be undefined or NaN to be disabled.
|
||||
* Setting precision (usually a power of 10) enforces a minimum step between
|
||||
* values. That is, the user's value will rounded to the closest multiple of
|
||||
* precision. The least significant digit place is inferred from the precision.
|
||||
@@ -87,15 +87,15 @@ Blockly.FieldNumber.prototype.SERIALIZABLE = true;
|
||||
* @param {number|string|undefined} precision Precision for value.
|
||||
*/
|
||||
Blockly.FieldNumber.prototype.setConstraints = function(min, max, precision) {
|
||||
precision = parseFloat(precision);
|
||||
precision = Number(precision);
|
||||
this.precision_ = isNaN(precision) ? 0 : precision;
|
||||
var precisionString = this.precision_.toString();
|
||||
var decimalIndex = precisionString.indexOf('.');
|
||||
this.fractionalDigits_ = (decimalIndex == -1) ? -1 :
|
||||
precisionString.length - (decimalIndex + 1);
|
||||
min = parseFloat(min);
|
||||
min = Number(min);
|
||||
this.min_ = isNaN(min) ? -Infinity : min;
|
||||
max = parseFloat(max);
|
||||
max = Number(max);
|
||||
this.max_ = isNaN(max) ? Infinity : max;
|
||||
this.setValue(this.getValue());
|
||||
};
|
||||
@@ -121,7 +121,7 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) {
|
||||
newValue = newValue.replace(/,/g, '');
|
||||
|
||||
// Clean up number.
|
||||
var n = parseFloat(newValue || 0);
|
||||
var n = Number(newValue || 0);
|
||||
if (isNaN(n)) {
|
||||
// Invalid number.
|
||||
return null;
|
||||
|
||||
@@ -410,7 +410,7 @@ Blockly.FieldTextInput.numberValidator = function(text) {
|
||||
text = text.replace(/O/ig, '0');
|
||||
// Strip out thousands separators.
|
||||
text = text.replace(/,/g, '');
|
||||
var n = parseFloat(text || 0);
|
||||
var n = Number(text || 0);
|
||||
return isNaN(n) ? null : String(n);
|
||||
};
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ Blockly.FieldVariable = function(varname, opt_validator, opt_variableTypes,
|
||||
this.menuGenerator_ = Blockly.FieldVariable.dropdownCreate;
|
||||
this.size_ = new Blockly.utils.Size(0, Blockly.BlockSvg.MIN_BLOCK_Y);
|
||||
opt_validator && this.setValidator(opt_validator);
|
||||
this.defaultVariableName = (varname || '');
|
||||
this.defaultVariableName = varname || '';
|
||||
|
||||
this.setTypes_(opt_variableTypes, opt_defaultType);
|
||||
this.value_ = null;
|
||||
|
||||
@@ -132,7 +132,7 @@ Blockly.ASTNode.createFieldNode = function(field) {
|
||||
* @return {Blockly.ASTNode} An AST node pointing to a connection.
|
||||
*/
|
||||
Blockly.ASTNode.createConnectionNode = function(connection) {
|
||||
if (!connection){
|
||||
if (!connection) {
|
||||
return null;
|
||||
}
|
||||
if (connection.type === Blockly.INPUT_VALUE) {
|
||||
@@ -209,7 +209,7 @@ Blockly.ASTNode.createWorkspaceNode = function(workspace, wsCoordinate) {
|
||||
* @param {Object} params The user specified parameters.
|
||||
* @private
|
||||
*/
|
||||
Blockly.ASTNode.prototype.processParams_ = function(params){
|
||||
Blockly.ASTNode.prototype.processParams_ = function(params) {
|
||||
if (!params) {
|
||||
return;
|
||||
}
|
||||
@@ -608,8 +608,8 @@ Blockly.ASTNode.prototype.in = function() {
|
||||
return Blockly.ASTNode.createConnectionNode(targetConnection);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
@@ -682,9 +682,8 @@ Blockly.ASTNode.prototype.out = function() {
|
||||
var target = this.location_.targetConnection;
|
||||
if (target) {
|
||||
return Blockly.ASTNode.createConnectionNode(target);
|
||||
} else {
|
||||
return Blockly.ASTNode.createStackNode(this.location_.getSourceBlock());
|
||||
}
|
||||
return Blockly.ASTNode.createStackNode(this.location_.getSourceBlock());
|
||||
|
||||
case Blockly.ASTNode.types.FIELD:
|
||||
return Blockly.ASTNode.createBlockNode(this.location_.getSourceBlock());
|
||||
|
||||
@@ -219,22 +219,22 @@ Blockly.Options.parseZoomOptions_ = function(options) {
|
||||
if (zoom['startScale'] === undefined) {
|
||||
zoomOptions.startScale = 1;
|
||||
} else {
|
||||
zoomOptions.startScale = parseFloat(zoom['startScale']);
|
||||
zoomOptions.startScale = Number(zoom['startScale']);
|
||||
}
|
||||
if (zoom['maxScale'] === undefined) {
|
||||
zoomOptions.maxScale = 3;
|
||||
} else {
|
||||
zoomOptions.maxScale = parseFloat(zoom['maxScale']);
|
||||
zoomOptions.maxScale = Number(zoom['maxScale']);
|
||||
}
|
||||
if (zoom['minScale'] === undefined) {
|
||||
zoomOptions.minScale = 0.3;
|
||||
} else {
|
||||
zoomOptions.minScale = parseFloat(zoom['minScale']);
|
||||
zoomOptions.minScale = Number(zoom['minScale']);
|
||||
}
|
||||
if (zoom['scaleSpeed'] === undefined) {
|
||||
zoomOptions.scaleSpeed = 1.2;
|
||||
} else {
|
||||
zoomOptions.scaleSpeed = parseFloat(zoom['scaleSpeed']);
|
||||
zoomOptions.scaleSpeed = Number(zoom['scaleSpeed']);
|
||||
}
|
||||
return zoomOptions;
|
||||
};
|
||||
@@ -250,9 +250,9 @@ Blockly.Options.parseZoomOptions_ = function(options) {
|
||||
Blockly.Options.parseGridOptions_ = function(options) {
|
||||
var grid = options['grid'] || {};
|
||||
var gridOptions = {};
|
||||
gridOptions.spacing = parseFloat(grid['spacing']) || 0;
|
||||
gridOptions.spacing = Number(grid['spacing']) || 0;
|
||||
gridOptions.colour = grid['colour'] || '#888';
|
||||
gridOptions.length = parseFloat(grid['length']) || 1;
|
||||
gridOptions.length = Number(grid['length']) || 1;
|
||||
gridOptions.snap = gridOptions.spacing > 0 && !!grid['snap'];
|
||||
return gridOptions;
|
||||
};
|
||||
|
||||
@@ -357,7 +357,7 @@ Blockly.blockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, ne
|
||||
if (prev.isIcon()) {
|
||||
return (Blockly.blockRendering.constants.LARGE_PADDING * 2) + 1;
|
||||
}
|
||||
if (prev.isHat()){
|
||||
if (prev.isHat()) {
|
||||
return Blockly.blockRendering.constants.NO_PADDING;
|
||||
}
|
||||
// Establish a minimum width for a block with a previous or next connection.
|
||||
@@ -442,7 +442,7 @@ Blockly.blockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, ne
|
||||
}
|
||||
|
||||
// Spacing between a rounded corner and a previous or next connection.
|
||||
if (prev.isRoundedCorner()){
|
||||
if (prev.isRoundedCorner()) {
|
||||
if (next.isPreviousConnection()) {
|
||||
return Blockly.blockRendering.constants.NOTCH_OFFSET_ROUNDED_CORNER_PREV;
|
||||
} else if (next.isNextConnection()) {
|
||||
|
||||
@@ -85,9 +85,9 @@ Blockly.utils.getRelativeXY = function(element) {
|
||||
var transform = element.getAttribute('transform');
|
||||
var r = transform && transform.match(Blockly.utils.getRelativeXY.XY_REGEX_);
|
||||
if (r) {
|
||||
xy.x += parseFloat(r[1]);
|
||||
xy.x += Number(r[1]);
|
||||
if (r[3]) {
|
||||
xy.y += parseFloat(r[3]);
|
||||
xy.y += Number(r[3]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,9 +97,9 @@ Blockly.utils.getRelativeXY = function(element) {
|
||||
var styleComponents =
|
||||
style.match(Blockly.utils.getRelativeXY.XY_STYLE_REGEX_);
|
||||
if (styleComponents) {
|
||||
xy.x += parseFloat(styleComponents[1]);
|
||||
xy.x += Number(styleComponents[1]);
|
||||
if (styleComponents[3]) {
|
||||
xy.y += parseFloat(styleComponents[3]);
|
||||
xy.y += Number(styleComponents[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,8 +345,8 @@ Blockly.Events.CommentMove.prototype.type = Blockly.Events.COMMENT_MOVE;
|
||||
/**
|
||||
* Override the location before the move. Use this if you don't create the
|
||||
* event until the end of the move, but you know the original location.
|
||||
* @param {!Blockly.utils.Coordinate} xy The location before the move, in workspace
|
||||
* coordinates.
|
||||
* @param {!Blockly.utils.Coordinate} xy The location before the move,
|
||||
* in workspace coordinates.
|
||||
*/
|
||||
Blockly.Events.CommentMove.prototype.setOldCoordinate = function(xy) {
|
||||
this.oldCoordinate_ = xy;
|
||||
@@ -376,7 +376,7 @@ Blockly.Events.CommentMove.prototype.fromJson = function(json) {
|
||||
if (json['newCoordinate']) {
|
||||
var xy = json['newCoordinate'].split(',');
|
||||
this.newCoordinate_ =
|
||||
new Blockly.utils.Coordinate(parseFloat(xy[0]), parseFloat(xy[1]));
|
||||
new Blockly.utils.Coordinate(Number(xy[0]), Number(xy[1]));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -385,7 +385,8 @@ Blockly.Events.CommentMove.prototype.fromJson = function(json) {
|
||||
* @return {boolean} False if something changed.
|
||||
*/
|
||||
Blockly.Events.CommentMove.prototype.isNull = function() {
|
||||
return Blockly.utils.Coordinate.equals(this.oldCoordinate_, this.newCoordinate_);
|
||||
return Blockly.utils.Coordinate.equals(this.oldCoordinate_,
|
||||
this.newCoordinate_);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -253,8 +253,8 @@ BlockExporterController.prototype.selectUsedBlocks = function() {
|
||||
}
|
||||
this.view.listSelectedBlocks();
|
||||
|
||||
if (unstoredCustomBlockTypes.length > 0){
|
||||
// Warn user to import block defifnitions and generator code for blocks
|
||||
if (unstoredCustomBlockTypes.length > 0) {
|
||||
// Warn user to import block definitions and generator code for blocks
|
||||
// not in their Block Library nor Blockly's standard library.
|
||||
var blockTypesText = unstoredCustomBlockTypes.join(', ');
|
||||
var customWarning = 'Custom blocks used in workspace factory but not ' +
|
||||
|
||||
@@ -335,7 +335,7 @@ button, .buttonStyle {
|
||||
padding: 5px 19px;
|
||||
}
|
||||
|
||||
.tab:hover:not(.tabon){
|
||||
.tab:hover:not(.tabon) {
|
||||
background-color: #e8e8e8;
|
||||
}
|
||||
|
||||
|
||||
@@ -443,7 +443,7 @@ FactoryUtils.getFieldsJs_ = function(block) {
|
||||
case 'field_angle':
|
||||
// Result: new Blockly.FieldAngle(90), 'ANGLE'
|
||||
fields.push('new Blockly.FieldAngle(' +
|
||||
parseFloat(block.getFieldValue('ANGLE')) + '), ' +
|
||||
Number(block.getFieldValue('ANGLE')) + '), ' +
|
||||
JSON.stringify(block.getFieldValue('FIELDNAME')));
|
||||
break;
|
||||
case 'field_checkbox':
|
||||
@@ -536,17 +536,17 @@ FactoryUtils.getFieldsJson_ = function(block) {
|
||||
var obj = {
|
||||
type: block.type,
|
||||
name: block.getFieldValue('FIELDNAME'),
|
||||
value: parseFloat(block.getFieldValue('VALUE'))
|
||||
value: Number(block.getFieldValue('VALUE'))
|
||||
};
|
||||
var min = parseFloat(block.getFieldValue('MIN'));
|
||||
var min = Number(block.getFieldValue('MIN'));
|
||||
if (min > -Infinity) {
|
||||
obj.min = min;
|
||||
}
|
||||
var max = parseFloat(block.getFieldValue('MAX'));
|
||||
var max = Number(block.getFieldValue('MAX'));
|
||||
if (max < Infinity) {
|
||||
obj.max = max;
|
||||
}
|
||||
var precision = parseFloat(block.getFieldValue('PRECISION'));
|
||||
var precision = Number(block.getFieldValue('PRECISION'));
|
||||
if (precision) {
|
||||
obj.precision = precision;
|
||||
}
|
||||
@@ -902,9 +902,9 @@ FactoryUtils.defineAndGetBlockTypes = function(blockDefsString, format) {
|
||||
FactoryUtils.injectCode = function(code, id) {
|
||||
var pre = document.getElementById(id);
|
||||
pre.textContent = code;
|
||||
code = pre.textContent;
|
||||
code = PR.prettyPrintOne(code, 'js');
|
||||
pre.innerHTML = code;
|
||||
// Remove the 'prettyprinted' class, so that Prettify will recalculate.
|
||||
pre.className = pre.className.replace('prettyprinted', '');
|
||||
PR.prettyPrint();
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -124,11 +124,11 @@
|
||||
<h3>Export Preview</h3>
|
||||
<div id="blockDefs" class="exportPreviewTextArea">
|
||||
<p id="blockDefs_label">Block Definitions:</p>
|
||||
<pre id="blockDefs_textArea"></pre>
|
||||
<pre id="blockDefs_textArea" class="prettyprint lang-js"></pre>
|
||||
</div>
|
||||
<div id="genStubs" class="exportPreviewTextArea">
|
||||
<p id="genStubs_label">Generator Stubs:</p>
|
||||
<pre id="genStubs_textArea"></pre>
|
||||
<pre id="genStubs_textArea" class="prettyprint lang-js"></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -378,7 +378,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="30%">
|
||||
<pre id="languagePre"></pre>
|
||||
<pre id="languagePre" class="prettyprint lang-js"></pre>
|
||||
<textarea id="languageTA"></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -397,7 +397,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="30%">
|
||||
<pre id="generatorPre"></pre>
|
||||
<pre id="generatorPre" class="prettyprint lang-js"></pre>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -1179,19 +1179,19 @@ WorkspaceFactoryController.prototype.readOptions_ = function() {
|
||||
var startScaleValue =
|
||||
document.getElementById('zoomOption_startScale_number').value;
|
||||
zoom['startScale'] = typeof startScaleValue == 'string' ?
|
||||
parseFloat(startScaleValue) : startScaleValue;
|
||||
Number(startScaleValue) : startScaleValue;
|
||||
var maxScaleValue =
|
||||
document.getElementById('zoomOption_maxScale_number').value;
|
||||
zoom['maxScale'] = typeof maxScaleValue == 'string' ?
|
||||
parseFloat(maxScaleValue) : maxScaleValue;
|
||||
Number(maxScaleValue) : maxScaleValue;
|
||||
var minScaleValue =
|
||||
document.getElementById('zoomOption_minScale_number').value;
|
||||
zoom['minScale'] = typeof minScaleValue == 'string' ?
|
||||
parseFloat(minScaleValue) : minScaleValue;
|
||||
Number(minScaleValue) : minScaleValue;
|
||||
var scaleSpeedValue =
|
||||
document.getElementById('zoomOption_scaleSpeed_number').value;
|
||||
zoom['scaleSpeed'] = typeof scaleSpeedValue == 'string' ?
|
||||
parseFloat(scaleSpeedValue) : scaleSpeedValue;
|
||||
Number(scaleSpeedValue) : scaleSpeedValue;
|
||||
optionsObj['zoom'] = zoom;
|
||||
}
|
||||
|
||||
|
||||
@@ -416,17 +416,17 @@ function getFieldsJson_(block) {
|
||||
var obj = {
|
||||
type: block.type,
|
||||
name: block.getFieldValue('FIELDNAME'),
|
||||
value: parseFloat(block.getFieldValue('VALUE'))
|
||||
value: Number(block.getFieldValue('VALUE'))
|
||||
};
|
||||
var min = parseFloat(block.getFieldValue('MIN'));
|
||||
var min = Number(block.getFieldValue('MIN'));
|
||||
if (min > -Infinity) {
|
||||
obj.min = min;
|
||||
}
|
||||
var max = parseFloat(block.getFieldValue('MAX'));
|
||||
var max = Number(block.getFieldValue('MAX'));
|
||||
if (max < Infinity) {
|
||||
obj.max = max;
|
||||
}
|
||||
var precision = parseFloat(block.getFieldValue('PRECISION'));
|
||||
var precision = Number(block.getFieldValue('PRECISION'));
|
||||
if (precision) {
|
||||
obj.precision = precision;
|
||||
}
|
||||
@@ -748,9 +748,9 @@ function updatePreview() {
|
||||
function injectCode(code, id) {
|
||||
var pre = document.getElementById(id);
|
||||
pre.textContent = code;
|
||||
code = pre.textContent;
|
||||
code = PR.prettyPrintOne(code, 'js');
|
||||
pre.innerHTML = code;
|
||||
// Remove the 'prettyprinted' class, so that Prettify will recalculate.
|
||||
pre.className = pre.className.replace('prettyprinted', '');
|
||||
PR.prettyPrint();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -148,7 +148,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="30%">
|
||||
<pre id="languagePre"></pre>
|
||||
<pre id="languagePre" class="prettyprint lang-js"></pre>
|
||||
<textarea id="languageTA"></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -167,7 +167,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="30%">
|
||||
<pre id="generatorPre"></pre>
|
||||
<pre id="generatorPre" class="prettyprint lang-js"></pre>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -89,11 +89,11 @@ Blockly.Dart['controls_for'] = function(block) {
|
||||
if (Blockly.isNumber(argument0) && Blockly.isNumber(argument1) &&
|
||||
Blockly.isNumber(increment)) {
|
||||
// All arguments are simple numbers.
|
||||
var up = parseFloat(argument0) <= parseFloat(argument1);
|
||||
var up = Number(argument0) <= Number(argument1);
|
||||
code = 'for (' + variable0 + ' = ' + argument0 + '; ' +
|
||||
variable0 + (up ? ' <= ' : ' >= ') + argument1 + '; ' +
|
||||
variable0;
|
||||
var step = Math.abs(parseFloat(increment));
|
||||
var step = Math.abs(Number(increment));
|
||||
if (step == 1) {
|
||||
code += up ? '++' : '--';
|
||||
} else {
|
||||
|
||||
@@ -33,7 +33,7 @@ Blockly.Dart.addReservedWords('Math');
|
||||
|
||||
Blockly.Dart['math_number'] = function(block) {
|
||||
// Numeric value.
|
||||
var code = parseFloat(block.getFieldValue('NUM'));
|
||||
var code = Number(block.getFieldValue('NUM'));
|
||||
var order;
|
||||
if (code == Infinity) {
|
||||
code = 'double.infinity';
|
||||
|
||||
@@ -103,7 +103,7 @@ Blockly.JavaScript.ORDER_LOGICAL_AND = 13; // &&
|
||||
Blockly.JavaScript.ORDER_LOGICAL_OR = 14; // ||
|
||||
Blockly.JavaScript.ORDER_CONDITIONAL = 15; // ?:
|
||||
Blockly.JavaScript.ORDER_ASSIGNMENT = 16; // = += -= **= *= /= %= <<= >>= ...
|
||||
Blockly.JavaScript.ORDER_YIELD = 17; // yield
|
||||
Blockly.JavaScript.ORDER_YIELD = 17; // yield
|
||||
Blockly.JavaScript.ORDER_COMMA = 18; // ,
|
||||
Blockly.JavaScript.ORDER_NONE = 99; // (...)
|
||||
|
||||
@@ -304,7 +304,7 @@ Blockly.JavaScript.getAdjusted = function(block, atId, opt_delta, opt_negate,
|
||||
|
||||
if (Blockly.isNumber(at)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
at = parseFloat(at) + delta;
|
||||
at = Number(at) + delta;
|
||||
if (opt_negate) {
|
||||
at = -at;
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ Blockly.JavaScript['lists_sort'] = function(block) {
|
||||
'(type, direction) {',
|
||||
' var compareFuncs = {',
|
||||
' "NUMERIC": function(a, b) {',
|
||||
' return parseFloat(a) - parseFloat(b); },',
|
||||
' return Number(a) - Number(b); },',
|
||||
' "TEXT": function(a, b) {',
|
||||
' return a.toString() > b.toString() ? 1 : -1; },',
|
||||
' "IGNORE_CASE": function(a, b) {',
|
||||
|
||||
@@ -90,11 +90,11 @@ Blockly.JavaScript['controls_for'] = function(block) {
|
||||
if (Blockly.isNumber(argument0) && Blockly.isNumber(argument1) &&
|
||||
Blockly.isNumber(increment)) {
|
||||
// All arguments are simple numbers.
|
||||
var up = parseFloat(argument0) <= parseFloat(argument1);
|
||||
var up = Number(argument0) <= Number(argument1);
|
||||
code = 'for (' + variable0 + ' = ' + argument0 + '; ' +
|
||||
variable0 + (up ? ' <= ' : ' >= ') + argument1 + '; ' +
|
||||
variable0;
|
||||
var step = Math.abs(parseFloat(increment));
|
||||
var step = Math.abs(Number(increment));
|
||||
if (step == 1) {
|
||||
code += up ? '++' : '--';
|
||||
} else {
|
||||
|
||||
@@ -31,7 +31,7 @@ goog.require('Blockly.JavaScript');
|
||||
|
||||
Blockly.JavaScript['math_number'] = function(block) {
|
||||
// Numeric value.
|
||||
var code = parseFloat(block.getFieldValue('NUM'));
|
||||
var code = Number(block.getFieldValue('NUM'));
|
||||
var order = code >= 0 ? Blockly.JavaScript.ORDER_ATOMIC :
|
||||
Blockly.JavaScript.ORDER_UNARY_NEGATION;
|
||||
return [code, order];
|
||||
|
||||
@@ -316,7 +316,7 @@ Blockly.JavaScript['text_prompt_ext'] = function(block) {
|
||||
var code = 'window.prompt(' + msg + ')';
|
||||
var toNumber = block.getFieldValue('TYPE') == 'NUMBER';
|
||||
if (toNumber) {
|
||||
code = 'parseFloat(' + code + ')';
|
||||
code = 'Number(' + code + ')';
|
||||
}
|
||||
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
|
||||
};
|
||||
|
||||
@@ -116,8 +116,8 @@ Blockly.Lua['controls_for'] = function(block) {
|
||||
if (Blockly.isNumber(startVar) && Blockly.isNumber(endVar) &&
|
||||
Blockly.isNumber(increment)) {
|
||||
// All arguments are simple numbers.
|
||||
var up = parseFloat(startVar) <= parseFloat(endVar);
|
||||
var step = Math.abs(parseFloat(increment));
|
||||
var up = Number(startVar) <= Number(endVar);
|
||||
var step = Math.abs(Number(increment));
|
||||
incValue = (up ? '' : '-') + step;
|
||||
} else {
|
||||
code = '';
|
||||
|
||||
@@ -31,7 +31,7 @@ goog.require('Blockly.Lua');
|
||||
|
||||
Blockly.Lua['math_number'] = function(block) {
|
||||
// Numeric value.
|
||||
var code = parseFloat(block.getFieldValue('NUM'));
|
||||
var code = Number(block.getFieldValue('NUM'));
|
||||
var order = code < 0 ? Blockly.Lua.ORDER_UNARY :
|
||||
Blockly.Lua.ORDER_ATOMIC;
|
||||
return [code, order];
|
||||
@@ -434,4 +434,4 @@ Blockly.Lua['math_atan2'] = function(block) {
|
||||
Blockly.Lua.ORDER_NONE) || '0';
|
||||
return ['math.deg(math.atan2(' + argument1 + ', ' + argument0 + '))',
|
||||
Blockly.Lua.ORDER_HIGH];
|
||||
};
|
||||
};
|
||||
|
||||
@@ -285,7 +285,7 @@ Blockly.PHP.getAdjusted = function(block, atId, opt_delta, opt_negate,
|
||||
|
||||
if (Blockly.isNumber(at)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
at = parseFloat(at) + delta;
|
||||
at = Number(at) + delta;
|
||||
if (opt_negate) {
|
||||
at = -at;
|
||||
}
|
||||
|
||||
@@ -430,7 +430,7 @@ Blockly.PHP['lists_getSublist'] = function(block) {
|
||||
' $at1 = count($list) - 1 - $at1;',
|
||||
' } else if ($where1 == \'FIRST\') {',
|
||||
' $at1 = 0;',
|
||||
' } else if ($where1 != \'FROM_START\'){',
|
||||
' } else if ($where1 != \'FROM_START\') {',
|
||||
' throw new Exception(\'Unhandled option (lists_get_sublist).\');',
|
||||
' }',
|
||||
' $length = 0;',
|
||||
|
||||
@@ -89,11 +89,11 @@ Blockly.PHP['controls_for'] = function(block) {
|
||||
if (Blockly.isNumber(argument0) && Blockly.isNumber(argument1) &&
|
||||
Blockly.isNumber(increment)) {
|
||||
// All arguments are simple numbers.
|
||||
var up = parseFloat(argument0) <= parseFloat(argument1);
|
||||
var up = Number(argument0) <= Number(argument1);
|
||||
code = 'for (' + variable0 + ' = ' + argument0 + '; ' +
|
||||
variable0 + (up ? ' <= ' : ' >= ') + argument1 + '; ' +
|
||||
variable0;
|
||||
var step = Math.abs(parseFloat(increment));
|
||||
var step = Math.abs(Number(increment));
|
||||
if (step == 1) {
|
||||
code += up ? '++' : '--';
|
||||
} else {
|
||||
|
||||
@@ -31,7 +31,7 @@ goog.require('Blockly.PHP');
|
||||
|
||||
Blockly.PHP['math_number'] = function(block) {
|
||||
// Numeric value.
|
||||
var code = parseFloat(block.getFieldValue('NUM'));
|
||||
var code = Number(block.getFieldValue('NUM'));
|
||||
var order = code >= 0 ? Blockly.PHP.ORDER_ATOMIC :
|
||||
Blockly.PHP.ORDER_UNARY_NEGATION;
|
||||
if (code == Infinity) {
|
||||
|
||||
@@ -174,7 +174,7 @@ Blockly.PHP['text_getSubstring'] = function(block) {
|
||||
' $at1 = strlen($text) - 1 - $at1;',
|
||||
' } else if ($where1 == \'FIRST\') {',
|
||||
' $at1 = 0;',
|
||||
' } else if ($where1 != \'FROM_START\'){',
|
||||
' } else if ($where1 != \'FROM_START\') {',
|
||||
' throw new Exception(\'Unhandled option (text_get_substring).\');',
|
||||
' }',
|
||||
' $length = 0;',
|
||||
|
||||
@@ -113,9 +113,9 @@ Blockly.Python['controls_for'] = function(block) {
|
||||
if (Blockly.isNumber(argument0) && Blockly.isNumber(argument1) &&
|
||||
Blockly.isNumber(increment)) {
|
||||
// All parameters are simple numbers.
|
||||
argument0 = parseFloat(argument0);
|
||||
argument1 = parseFloat(argument1);
|
||||
increment = Math.abs(parseFloat(increment));
|
||||
argument0 = Number(argument0);
|
||||
argument1 = Number(argument1);
|
||||
increment = Math.abs(Number(increment));
|
||||
if (argument0 % 1 === 0 && argument1 % 1 === 0 && increment % 1 === 0) {
|
||||
// All parameters are integers.
|
||||
if (argument0 <= argument1) {
|
||||
@@ -151,7 +151,7 @@ Blockly.Python['controls_for'] = function(block) {
|
||||
var scrub = function(arg, suffix) {
|
||||
if (Blockly.isNumber(arg)) {
|
||||
// Simple number.
|
||||
arg = parseFloat(arg);
|
||||
arg = Number(arg);
|
||||
} else if (arg.match(/^\w+$/)) {
|
||||
// Variable.
|
||||
arg = 'float(' + arg + ')';
|
||||
|
||||
@@ -34,7 +34,7 @@ Blockly.Python.addReservedWords('math,random,Number');
|
||||
|
||||
Blockly.Python['math_number'] = function(block) {
|
||||
// Numeric value.
|
||||
var code = parseFloat(block.getFieldValue('NUM'));
|
||||
var code = Number(block.getFieldValue('NUM'));
|
||||
var order;
|
||||
if (code == Infinity) {
|
||||
code = 'float("inf")';
|
||||
|
||||
@@ -1440,7 +1440,7 @@ function test_split() {
|
||||
function listsGetSortCompare(type, direction) {
|
||||
var compareFuncs = {
|
||||
"NUMERIC": function(a, b) {
|
||||
return parseFloat(a) - parseFloat(b); },
|
||||
return Number(a) - Number(b); },
|
||||
"TEXT": function(a, b) {
|
||||
return a.toString() > b.toString() ? 1 : -1; },
|
||||
"IGNORE_CASE": function(a, b) {
|
||||
|
||||
@@ -778,7 +778,7 @@ function text_get_substring($text, $where1, $at1, $where2, $at2) {
|
||||
$at1 = strlen($text) - 1 - $at1;
|
||||
} else if ($where1 == 'FIRST') {
|
||||
$at1 = 0;
|
||||
} else if ($where1 != 'FROM_START'){
|
||||
} else if ($where1 != 'FROM_START') {
|
||||
throw new Exception('Unhandled option (text_get_substring).');
|
||||
}
|
||||
$length = 0;
|
||||
@@ -1296,7 +1296,7 @@ function lists_get_sublist($list, $where1, $at1, $where2, $at2) {
|
||||
$at1 = count($list) - 1 - $at1;
|
||||
} else if ($where1 == 'FIRST') {
|
||||
$at1 = 0;
|
||||
} else if ($where1 != 'FROM_START'){
|
||||
} else if ($where1 != 'FROM_START') {
|
||||
throw new Exception('Unhandled option (lists_get_sublist).');
|
||||
}
|
||||
$length = 0;
|
||||
|
||||
@@ -166,7 +166,7 @@ Blockly.Dart['unittest_adjustindex'] = function(block) {
|
||||
if (block.workspace.options.oneBasedIndex) {
|
||||
if (Blockly.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [parseFloat(index) + 1, Blockly.Dart.ORDER_ATOMIC];
|
||||
return [Number(index) + 1, Blockly.Dart.ORDER_ATOMIC];
|
||||
} else {
|
||||
// If the index is dynamic, adjust it in code.
|
||||
index = index + ' + 1';
|
||||
|
||||
@@ -170,7 +170,7 @@ Blockly.JavaScript['unittest_adjustindex'] = function(block) {
|
||||
if (block.workspace.options.oneBasedIndex) {
|
||||
if (Blockly.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [parseFloat(index) + 1, Blockly.JavaScript.ORDER_ATOMIC];
|
||||
return [Number(index) + 1, Blockly.JavaScript.ORDER_ATOMIC];
|
||||
} else {
|
||||
// If the index is dynamic, adjust it in code.
|
||||
index = index + ' + 1';
|
||||
|
||||
@@ -173,7 +173,7 @@ Blockly.Lua['unittest_adjustindex'] = function(block) {
|
||||
Blockly.Lua.ORDER_ADDITIVE) || '0';
|
||||
if (Blockly.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [parseFloat(index) + 1, Blockly.Lua.ORDER_ATOMIC];
|
||||
return [Number(index) + 1, Blockly.Lua.ORDER_ATOMIC];
|
||||
}
|
||||
// If the index is dynamic, adjust it in code.
|
||||
return [index + ' + 1', Blockly.Lua.ORDER_ATOMIC];
|
||||
|
||||
@@ -157,7 +157,7 @@ Blockly.PHP['unittest_adjustindex'] = function(block) {
|
||||
if (block.workspace.options.oneBasedIndex) {
|
||||
if (Blockly.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [parseFloat(index) + 1, Blockly.PHP.ORDER_ATOMIC];
|
||||
return [Number(index) + 1, Blockly.PHP.ORDER_ATOMIC];
|
||||
} else {
|
||||
// If the index is dynamic, adjust it in code.
|
||||
index = index + ' + 1';
|
||||
|
||||
@@ -141,7 +141,7 @@ Blockly.Python['unittest_adjustindex'] = function(block) {
|
||||
if (block.workspace.options.oneBasedIndex) {
|
||||
if (Blockly.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [parseFloat(index) + 1, Blockly.Python.ORDER_ATOMIC];
|
||||
return [Number(index) + 1, Blockly.Python.ORDER_ATOMIC];
|
||||
} else {
|
||||
// If the index is dynamic, adjust it in code.
|
||||
index = index + ' + 1';
|
||||
|
||||
@@ -24,7 +24,7 @@ suite('Angle Fields', function() {
|
||||
var actualText = angleField.getText();
|
||||
opt_expectedText = opt_expectedText || String(expectedValue);
|
||||
assertEquals(String(actualValue), String(expectedValue));
|
||||
assertEquals(parseFloat(actualValue), expectedValue);
|
||||
assertEquals(Number(actualValue), expectedValue);
|
||||
assertEquals(actualText, opt_expectedText);
|
||||
}
|
||||
function assertValueDefault(angleField) {
|
||||
@@ -35,10 +35,6 @@ suite('Angle Fields', function() {
|
||||
var angleField = new Blockly.FieldAngle();
|
||||
assertValueDefault(angleField);
|
||||
});
|
||||
test('Null', function() {
|
||||
var angleField = new Blockly.FieldAngle(null);
|
||||
assertValueDefault(angleField);
|
||||
});
|
||||
test('Undefined', function() {
|
||||
var angleField = new Blockly.FieldAngle(undefined);
|
||||
assertValueDefault(angleField);
|
||||
@@ -71,16 +67,20 @@ suite('Angle Fields', function() {
|
||||
var angleField = new Blockly.FieldAngle(362);
|
||||
assertValue(angleField, 2);
|
||||
});
|
||||
test('Infinity', function() {
|
||||
var angleField = new Blockly.FieldAngle(Infinity);
|
||||
assertValueDefault(angleField);
|
||||
});
|
||||
test('Negative Infinity String', function() {
|
||||
var angleField = new Blockly.FieldAngle('-Infinity');
|
||||
assertValueDefault(angleField);
|
||||
});
|
||||
});
|
||||
suite('fromJson', function() {
|
||||
test('Empty', function() {
|
||||
var angleField = Blockly.FieldAngle.fromJson({});
|
||||
assertValueDefault(angleField);
|
||||
});
|
||||
test('Null', function() {
|
||||
var angleField = Blockly.FieldAngle.fromJson({ angle:null });
|
||||
assertValueDefault(angleField);
|
||||
});
|
||||
test('Undefined', function() {
|
||||
var angleField = Blockly.FieldAngle.fromJson({ angle:undefined });
|
||||
assertValueDefault(angleField);
|
||||
@@ -113,6 +113,14 @@ suite('Angle Fields', function() {
|
||||
var angleField = Blockly.FieldAngle.fromJson({ angle:362 });
|
||||
assertValue(angleField, 2);
|
||||
});
|
||||
test('Infinity', function() {
|
||||
var angleField = Blockly.FieldAngle.fromJson({ angle:Infinity });
|
||||
assertValueDefault(angleField);
|
||||
});
|
||||
test('Negative Infinity String', function() {
|
||||
var angleField = Blockly.FieldAngle.fromJson({ angle:'-Infinity' });
|
||||
assertValueDefault(angleField);
|
||||
});
|
||||
});
|
||||
suite('setValue', function() {
|
||||
suite('Empty -> New Value', function() {
|
||||
@@ -155,6 +163,14 @@ suite('Angle Fields', function() {
|
||||
this.angleField.setValue(362);
|
||||
assertValue(this.angleField, 2);
|
||||
});
|
||||
test('Infinity', function() {
|
||||
this.angleField.setValue(Infinity);
|
||||
assertValueDefault(this.angleField);
|
||||
});
|
||||
test('Negative Infinity String', function() {
|
||||
this.angleField.setValue('-Infinity');
|
||||
assertValueDefault(this.angleField);
|
||||
});
|
||||
});
|
||||
suite('Value -> New Value', function() {
|
||||
setup(function() {
|
||||
@@ -196,6 +212,14 @@ suite('Angle Fields', function() {
|
||||
this.angleField.setValue(362);
|
||||
assertValue(this.angleField, 2);
|
||||
});
|
||||
test('Infinity', function() {
|
||||
this.angleField.setValue(Infinity);
|
||||
assertValue(this.angleField, 1);
|
||||
});
|
||||
test('Negative Infinity String', function() {
|
||||
this.angleField.setValue('-Infinity');
|
||||
assertValue(this.angleField, 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
suite('Validators', function() {
|
||||
|
||||
@@ -29,8 +29,8 @@ suite('Checkbox Fields', function() {
|
||||
assertValue(checkboxField, 'FALSE', 'false');
|
||||
}
|
||||
suite('Constructor', function() {
|
||||
test('Null', function() {
|
||||
var checkboxField = new Blockly.FieldCheckbox(null);
|
||||
test('Empty', function() {
|
||||
var checkboxField = new Blockly.FieldCheckbox();
|
||||
assertValueDefault(checkboxField);
|
||||
});
|
||||
test('Undefined', function() {
|
||||
@@ -59,8 +59,8 @@ suite('Checkbox Fields', function() {
|
||||
});
|
||||
});
|
||||
suite('fromJson', function() {
|
||||
test('Null', function() {
|
||||
var checkboxField = Blockly.FieldCheckbox.fromJson({ checked: null});
|
||||
test('Empty', function() {
|
||||
var checkboxField = Blockly.FieldCheckbox.fromJson({});
|
||||
assertValueDefault(checkboxField);
|
||||
});
|
||||
test('Undefined', function() {
|
||||
|
||||
@@ -49,10 +49,6 @@ suite('Colour Fields', function() {
|
||||
var colourField = new Blockly.FieldColour();
|
||||
assertValueDefault(colourField);
|
||||
});
|
||||
test('Null', function() {
|
||||
var colourField = new Blockly.FieldColour(null);
|
||||
assertValueDefault(colourField);
|
||||
});
|
||||
test('Undefined', function() {
|
||||
var colourField = new Blockly.FieldColour(undefined);
|
||||
assertValueDefault(colourField);
|
||||
@@ -107,10 +103,6 @@ suite('Colour Fields', function() {
|
||||
var colourField = new Blockly.FieldColour.fromJson({});
|
||||
assertValueDefault(colourField);
|
||||
});
|
||||
test('Null', function() {
|
||||
var colourField = new Blockly.FieldColour.fromJson({ colour:null });
|
||||
assertValueDefault(colourField);
|
||||
});
|
||||
test('Undefined', function() {
|
||||
var colourField = new Blockly.FieldColour.fromJson({ colour:undefined });
|
||||
assertValueDefault(colourField);
|
||||
|
||||
@@ -34,10 +34,6 @@ suite('Date Fields', function() {
|
||||
var dateField = new Blockly.FieldDate();
|
||||
assertValueDefault(dateField);
|
||||
});
|
||||
test('Null', function() {
|
||||
var dateField = new Blockly.FieldDate(null);
|
||||
assertValueDefault(dateField);
|
||||
});
|
||||
test('Undefined', function() {
|
||||
var dateField = new Blockly.FieldDate(undefined);
|
||||
assertValueDefault(dateField);
|
||||
@@ -64,10 +60,6 @@ suite('Date Fields', function() {
|
||||
var dateField = Blockly.FieldDate.fromJson({});
|
||||
assertValueDefault(dateField);
|
||||
});
|
||||
test('Null', function() {
|
||||
var dateField = Blockly.FieldDate.fromJson({ date: null });
|
||||
assertValueDefault(dateField);
|
||||
});
|
||||
test('Undefined', function() {
|
||||
var dateField = Blockly.FieldDate.fromJson({ date: undefined });
|
||||
assertValueDefault(dateField);
|
||||
|
||||
@@ -31,11 +31,6 @@ suite('Dropdown Fields', function() {
|
||||
new Blockly.FieldDropdown();
|
||||
});
|
||||
});
|
||||
test('Null', function() {
|
||||
chai.assert.throws(function() {
|
||||
new Blockly.FieldDropdown(null);
|
||||
});
|
||||
});
|
||||
test('Undefined', function() {
|
||||
chai.assert.throws(function() {
|
||||
new Blockly.FieldDropdown(undefined);
|
||||
@@ -102,11 +97,6 @@ suite('Dropdown Fields', function() {
|
||||
Blockly.FieldDropdown.fromJson({});
|
||||
});
|
||||
});
|
||||
test('Null', function() {
|
||||
chai.assert.throws(function() {
|
||||
Blockly.FieldDropdown.fromJson({ options: null });
|
||||
});
|
||||
});
|
||||
test('Undefined', function() {
|
||||
chai.assert.throws(function() {
|
||||
Blockly.FieldDropdown.fromJson({ options: undefined });
|
||||
|
||||
@@ -31,21 +31,11 @@ suite('Image Fields', function() {
|
||||
new Blockly.FieldImage();
|
||||
});
|
||||
});
|
||||
test('Null Src', function() {
|
||||
chai.assert.throws(function() {
|
||||
new Blockly.FieldImage(null, 1, 1);
|
||||
});
|
||||
});
|
||||
test('Undefined Src', function() {
|
||||
chai.assert.throws(function() {
|
||||
new Blockly.FieldImage(undefined, 1, 1);
|
||||
});
|
||||
});
|
||||
test('Null Size', function() {
|
||||
chai.assert.throws(function() {
|
||||
new Blockly.FieldImage('src', null, null);
|
||||
});
|
||||
});
|
||||
test('Undefined Size', function() {
|
||||
chai.assert.throws(function() {
|
||||
new Blockly.FieldImage('src', undefined, undefined);
|
||||
@@ -79,15 +69,6 @@ suite('Image Fields', function() {
|
||||
Blockly.FieldImage.fromJson({});
|
||||
});
|
||||
});
|
||||
test('Null Src', function() {
|
||||
chai.assert.throws(function() {
|
||||
Blockly.FieldImage.fromJson({
|
||||
src: null,
|
||||
width: 1,
|
||||
height: 1
|
||||
});
|
||||
});
|
||||
});
|
||||
test('Undefined Src', function() {
|
||||
chai.assert.throws(function() {
|
||||
Blockly.FieldImage.fromJson({
|
||||
@@ -97,15 +78,6 @@ suite('Image Fields', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
test('Null Size', function() {
|
||||
chai.assert.throws(function() {
|
||||
Blockly.FieldImage.fromJson({
|
||||
src: 'src',
|
||||
width: null,
|
||||
height: null
|
||||
});
|
||||
});
|
||||
});
|
||||
test('Undefined Size', function() {
|
||||
chai.assert.throws(function() {
|
||||
Blockly.FieldImage.fromJson({
|
||||
|
||||
@@ -33,10 +33,6 @@ suite('Label Fields', function() {
|
||||
var labelField = new Blockly.FieldLabel();
|
||||
assertValueDefault(labelField);
|
||||
});
|
||||
test('Null', function() {
|
||||
var labelField = new Blockly.FieldLabel(null);
|
||||
assertValueDefault(labelField);
|
||||
});
|
||||
test('Undefined', function() {
|
||||
var labelField = new Blockly.FieldLabel(undefined);
|
||||
assertValueDefault(labelField);
|
||||
@@ -67,10 +63,6 @@ suite('Label Fields', function() {
|
||||
var labelField = new Blockly.FieldLabel.fromJson({});
|
||||
assertValueDefault(labelField);
|
||||
});
|
||||
test('Null', function() {
|
||||
var labelField = new Blockly.FieldLabel.fromJson({ text:null });
|
||||
assertValueDefault(labelField);
|
||||
});
|
||||
test('Undefined', function() {
|
||||
var labelField = new Blockly.FieldLabel.fromJson({ text:undefined });
|
||||
assertValueDefault(labelField);
|
||||
|
||||
@@ -24,7 +24,7 @@ suite('Number Fields', function() {
|
||||
var actualText = numberField.getText();
|
||||
opt_expectedText = opt_expectedText || String(expectedValue);
|
||||
assertEquals(String(actualValue), String(expectedValue));
|
||||
assertEquals(parseFloat(actualValue), expectedValue);
|
||||
assertEquals(Number(actualValue), expectedValue);
|
||||
assertEquals(actualText, opt_expectedText);
|
||||
}
|
||||
function assertValueDefault(numberField) {
|
||||
@@ -55,10 +55,6 @@ suite('Number Fields', function() {
|
||||
var numberField = new Blockly.FieldNumber();
|
||||
assertNumberFieldDefault(numberField);
|
||||
});
|
||||
test('Null', function() {
|
||||
var numberField = createNumberFieldSameValuesConstructor(null);
|
||||
assertNumberFieldDefault(numberField);
|
||||
});
|
||||
test('Undefined', function() {
|
||||
var numberField = createNumberFieldSameValuesConstructor(undefined);
|
||||
assertNumberFieldDefault(numberField);
|
||||
@@ -87,16 +83,20 @@ suite('Number Fields', function() {
|
||||
var numberField = createNumberFieldSameValuesConstructor('1.5');
|
||||
assertNumberFieldSameValues(numberField, 1.5);
|
||||
});
|
||||
test('Infinity', function() {
|
||||
var numberField = createNumberFieldSameValuesConstructor('Infinity');
|
||||
assertNumberFieldSameValues(numberField, Infinity);
|
||||
});
|
||||
test('Negative Infinity String', function() {
|
||||
var numberField = createNumberFieldSameValuesConstructor('-Infinity');
|
||||
assertNumberFieldSameValues(numberField, -Infinity);
|
||||
});
|
||||
});
|
||||
suite('fromJson', function() {
|
||||
test('Empty', function() {
|
||||
var numberField = Blockly.FieldNumber.fromJson({});
|
||||
assertNumberFieldDefault(numberField);
|
||||
});
|
||||
test('Null', function() {
|
||||
var numberField = createNumberFieldSameValuesJson(null);
|
||||
assertNumberFieldDefault(numberField);
|
||||
});
|
||||
test('Undefined', function() {
|
||||
var numberField = createNumberFieldSameValuesJson(undefined);
|
||||
assertNumberFieldDefault(numberField);
|
||||
@@ -125,6 +125,14 @@ suite('Number Fields', function() {
|
||||
var numberField = createNumberFieldSameValuesJson('1.5');
|
||||
assertNumberFieldSameValues(numberField, 1.5);
|
||||
});
|
||||
test('Infinity', function() {
|
||||
var numberField = createNumberFieldSameValuesJson('Infinity');
|
||||
assertNumberFieldSameValues(numberField, Infinity);
|
||||
});
|
||||
test('Negative Infinity String', function() {
|
||||
var numberField = createNumberFieldSameValuesJson('-Infinity');
|
||||
assertNumberFieldSameValues(numberField, -Infinity);
|
||||
});
|
||||
});
|
||||
suite('setValue', function() {
|
||||
suite('Value Types', function() {
|
||||
@@ -164,6 +172,14 @@ suite('Number Fields', function() {
|
||||
this.numberField.setValue('2.5');
|
||||
assertValue(this.numberField, 2.5);
|
||||
});
|
||||
test('Infinity', function() {
|
||||
this.numberField.setValue(Infinity);
|
||||
assertValue(this.numberField, Infinity);
|
||||
});
|
||||
test('Negative Infinity String', function() {
|
||||
this.numberField.setValue('-Infinity');
|
||||
assertValue(this.numberField, -Infinity);
|
||||
});
|
||||
});
|
||||
suite('Value -> New Value', function() {
|
||||
setup(function() {
|
||||
@@ -201,6 +217,14 @@ suite('Number Fields', function() {
|
||||
this.numberField.setValue('2.5');
|
||||
assertValue(this.numberField, 2.5);
|
||||
});
|
||||
test('Infinity', function() {
|
||||
this.numberField.setValue(Infinity);
|
||||
assertValue(this.numberField, Infinity);
|
||||
});
|
||||
test('Negative Infinity String', function() {
|
||||
this.numberField.setValue('-Infinity');
|
||||
assertValue(this.numberField, -Infinity);
|
||||
});
|
||||
});
|
||||
});
|
||||
suite('Constraints', function() {
|
||||
|
||||
@@ -34,10 +34,6 @@ suite('Text Input Fields', function() {
|
||||
var textInputField = new Blockly.FieldTextInput();
|
||||
assertValueDefault(textInputField);
|
||||
});
|
||||
test('Null', function() {
|
||||
var textInputField = new Blockly.FieldTextInput(null);
|
||||
assertValueDefault(textInputField);
|
||||
});
|
||||
test('Undefined', function() {
|
||||
var textInputField = new Blockly.FieldTextInput(undefined);
|
||||
assertValueDefault(textInputField);
|
||||
@@ -68,10 +64,6 @@ suite('Text Input Fields', function() {
|
||||
var textInputField = new Blockly.FieldTextInput.fromJson({});
|
||||
assertValueDefault(textInputField);
|
||||
});
|
||||
test('Null', function() {
|
||||
var textInputField = new Blockly.FieldTextInput.fromJson({ text: null});
|
||||
assertValueDefault(textInputField);
|
||||
});
|
||||
test('Undefined', function() {
|
||||
var textInputField = new Blockly.FieldTextInput
|
||||
.fromJson({ text: undefined});
|
||||
|
||||
Reference in New Issue
Block a user