mirror of
https://github.com/google/blockly.git
synced 2026-01-07 17:10:11 +01:00
refactor!: Remove remaining use of goog.module.declareLegacyNamespace. (#6254)
* fix(build): Minor corrections to build_tasks.js
- Use TSC_OUTPUT_DIR to find goog/goog.js when suppressing warnings.
- Remove unnecessary trailing semicolons.
* refactor(blocks): Remove declareLegacyNamespace
Remove the call to goog.module.declareLegacyNamespace from
Blockly.libraryBlocks. This entails:
- Changes to the UMD wrapper to be able to find the exports object.
- Changes to tests/bootstrap_helper.js to save the exports object
in the libraryBlocks global variable.
- As a precaution, renaming the tests/compile/test_blocks.js module
so that goog.provide does not touch Blockly or
Blockly.libraryBlocks, which may not exist / be writable.
* feat(build): Add support named exports from chunks
We need to convert the generators to named exports. For backwards
compatibility we still want e.g. Blockly.JavaScript to point at
the generator object when the chunk is loaded using a script tag.
Modify chunkWrapper to honour a .reexportOnly property in the
chunks table and generate suitable additional code in the UMD
wrapper.
* refactor(generators): Migrate JavaScript generator to named export
- Export the JavaScript generator object as javascriptGenerator
from the Blockly.JavaScript module(generators/javascript.js).
- Modify the Blockly.JavaScript.all module
(generators/javascript/all.js) to reexport the exports from
Blockly.JavaScript.
- Update chunk configuration so the generator object remains
available as Blockly.JavaScript when loading
javascript_compressed.js via a <script> tag.
(N.B. it is otherwise necessary to destructure the require
/ import.)
- Modify bootstrap_helper.js to store that export as
window.javascriptGenerator for use in test code.
- Modify test code to use javascriptGenerator instead of
Blockly.JavaScript.
- Modify .eslintrc.json so that javascriptGenerator is allowed
as a global in test/. (Also restrict use of Blockly global
to test/.)
N.B. that demo code in demos/code/code.js uses <script> tag
loading and so will continue to access Blockly.JavaScript.
* refactor(generators): Migrate Lua generator to named export
* refactor(generators): Migrate PHP generator to named export
* refactor(generators): Migrate Python generator to named export
* refactor(generators): Remove declareLegacyNamespace calls
Remove the goog.module.declareLegacyNamespace calls from the
generators.
This turns out to have the unexpected side-effect of causing the
compiler to rename the core/blockly.js exports object from
$.Blockly to just Blockly in blockly_compressed.js - presumably
because it no longer needs to be accessed in any subsequent chunk
because they no longer add properties to it. This requires
some changes (mainly simplification) to the chunkWrapper function
in build_tasks.js.
* refactor(core): Remove declareLegacyNamespace from blockly.js
So easy to do _now_: just need to:
- Make sure the UMD wrapper for the first chunk knows where the
exports object is.
- Use that same value to set the Blockly.VERSION @define.
- Have bootstrap_helper.js set window.Blockly to the exports
object.
- Fix tests/compile/test_blocks.js to not assume a Blockly
global variable, by converting it to a goog.module so we
can use a named require.
This commit is contained in:
committed by
GitHub
parent
9797943938
commit
f947b3f4f6
@@ -170,31 +170,31 @@ function toXml() {
|
||||
|
||||
function toJavaScript() {
|
||||
var code = '\'use strict\';\n\n'
|
||||
code += Blockly.JavaScript.workspaceToCode(demoWorkspace);
|
||||
code += javascriptGenerator.workspaceToCode(demoWorkspace);
|
||||
setOutput(code);
|
||||
outputCode = code;
|
||||
}
|
||||
|
||||
function toPython() {
|
||||
var code = Blockly.Python.workspaceToCode(demoWorkspace);
|
||||
var code = pythonGenerator.workspaceToCode(demoWorkspace);
|
||||
setOutput(code);
|
||||
outputCode = code;
|
||||
}
|
||||
|
||||
function toPhp() {
|
||||
var code = Blockly.PHP.workspaceToCode(demoWorkspace);
|
||||
var code = phpGenerator.workspaceToCode(demoWorkspace);
|
||||
setOutput(code);
|
||||
outputCode = code;
|
||||
}
|
||||
|
||||
function toLua() {
|
||||
var code = Blockly.Lua.workspaceToCode(demoWorkspace);
|
||||
var code = luaGenerator.workspaceToCode(demoWorkspace);
|
||||
setOutput(code);
|
||||
outputCode = code;
|
||||
}
|
||||
|
||||
function toDart() {
|
||||
var code = Blockly.Dart.workspaceToCode(demoWorkspace);
|
||||
var code = dartGenerator.workspaceToCode(demoWorkspace);
|
||||
setOutput(code);
|
||||
outputCode = code;
|
||||
}
|
||||
|
||||
@@ -9,13 +9,13 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Blockly.Dart['unittest_main'] = function(block) {
|
||||
dartGenerator['unittest_main'] = function(block) {
|
||||
// Container for unit tests.
|
||||
var resultsVar = Blockly.Dart.nameDB_.getName('unittestResults',
|
||||
var resultsVar = dartGenerator.nameDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.Dart.provideFunction_(
|
||||
var functionName = dartGenerator.provideFunction_(
|
||||
'unittest_report',
|
||||
[ 'String ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ + '() {',
|
||||
[ 'String ' + dartGenerator.FUNCTION_NAME_PLACEHOLDER_ + '() {',
|
||||
' // Create test report.',
|
||||
' List report = [];',
|
||||
' StringBuffer summary = new StringBuffer();',
|
||||
@@ -50,7 +50,7 @@ Blockly.Dart['unittest_main'] = function(block) {
|
||||
block.getFieldValue('SUITE_NAME') +
|
||||
'\');\n';
|
||||
// Run tests (unindented).
|
||||
code += Blockly.Dart.statementToCode(block, 'DO')
|
||||
code += dartGenerator.statementToCode(block, 'DO')
|
||||
.replace(/^ /, '').replace(/\n /g, '\n');
|
||||
// Print the report to the console (that's where errors will go anyway).
|
||||
code += 'print(' + functionName + '());\n';
|
||||
@@ -59,12 +59,12 @@ Blockly.Dart['unittest_main'] = function(block) {
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Dart['unittest_main'].defineAssert_ = function() {
|
||||
var resultsVar = Blockly.Dart.nameDB_.getName('unittestResults',
|
||||
dartGenerator['unittest_main'].defineAssert_ = function() {
|
||||
var resultsVar = dartGenerator.nameDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.Dart.provideFunction_(
|
||||
var functionName = dartGenerator.provideFunction_(
|
||||
'unittest_assertequals',
|
||||
[ 'void ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
[ 'void ' + dartGenerator.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'(dynamic actual, dynamic expected, String message) {',
|
||||
' // Asserts that a value equals another value.',
|
||||
' if (' + resultsVar + ' == null) {',
|
||||
@@ -96,24 +96,24 @@ Blockly.Dart['unittest_main'].defineAssert_ = function() {
|
||||
return functionName;
|
||||
};
|
||||
|
||||
Blockly.Dart['unittest_assertequals'] = function(block) {
|
||||
dartGenerator['unittest_assertequals'] = function(block) {
|
||||
// Asserts that a value equals another value.
|
||||
var message = Blockly.Dart.valueToCode(block, 'MESSAGE',
|
||||
Blockly.Dart.ORDER_NONE) || '';
|
||||
var actual = Blockly.Dart.valueToCode(block, 'ACTUAL',
|
||||
Blockly.Dart.ORDER_NONE) || 'null';
|
||||
var expected = Blockly.Dart.valueToCode(block, 'EXPECTED',
|
||||
Blockly.Dart.ORDER_NONE) || 'null';
|
||||
return Blockly.Dart['unittest_main'].defineAssert_() +
|
||||
var message = dartGenerator.valueToCode(block, 'MESSAGE',
|
||||
dartGenerator.ORDER_NONE) || '';
|
||||
var actual = dartGenerator.valueToCode(block, 'ACTUAL',
|
||||
dartGenerator.ORDER_NONE) || 'null';
|
||||
var expected = dartGenerator.valueToCode(block, 'EXPECTED',
|
||||
dartGenerator.ORDER_NONE) || 'null';
|
||||
return dartGenerator['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.Dart['unittest_assertvalue'] = function(block) {
|
||||
dartGenerator['unittest_assertvalue'] = function(block) {
|
||||
// Asserts that a value is true, false, or null.
|
||||
var message = Blockly.Dart.valueToCode(block, 'MESSAGE',
|
||||
Blockly.Dart.ORDER_NONE) || '';
|
||||
var actual = Blockly.Dart.valueToCode(block, 'ACTUAL',
|
||||
Blockly.Dart.ORDER_NONE) || 'null';
|
||||
var message = dartGenerator.valueToCode(block, 'MESSAGE',
|
||||
dartGenerator.ORDER_NONE) || '';
|
||||
var actual = dartGenerator.valueToCode(block, 'ACTUAL',
|
||||
dartGenerator.ORDER_NONE) || 'null';
|
||||
var expected = block.getFieldValue('EXPECTED');
|
||||
if (expected === 'TRUE') {
|
||||
expected = 'true';
|
||||
@@ -122,18 +122,18 @@ Blockly.Dart['unittest_assertvalue'] = function(block) {
|
||||
} else if (expected === 'NULL') {
|
||||
expected = 'null';
|
||||
}
|
||||
return Blockly.Dart['unittest_main'].defineAssert_() +
|
||||
return dartGenerator['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.Dart['unittest_fail'] = function(block) {
|
||||
dartGenerator['unittest_fail'] = function(block) {
|
||||
// Always assert an error.
|
||||
var resultsVar = Blockly.Dart.nameDB_.getName('unittestResults',
|
||||
var resultsVar = dartGenerator.nameDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var message = Blockly.Dart.quote_(block.getFieldValue('MESSAGE'));
|
||||
var functionName = Blockly.Dart.provideFunction_(
|
||||
var message = dartGenerator.quote_(block.getFieldValue('MESSAGE'));
|
||||
var functionName = dartGenerator.provideFunction_(
|
||||
'unittest_fail',
|
||||
[ 'void ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
[ 'void ' + dartGenerator.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'(String message) {',
|
||||
' // Always assert an error.',
|
||||
' if (' + resultsVar + ' == null) {',
|
||||
@@ -144,20 +144,20 @@ Blockly.Dart['unittest_fail'] = function(block) {
|
||||
return functionName + '(' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.Dart['unittest_adjustindex'] = function(block) {
|
||||
var index = Blockly.Dart.valueToCode(block, 'INDEX',
|
||||
Blockly.Dart.ORDER_ADDITIVE) || '0';
|
||||
dartGenerator['unittest_adjustindex'] = function(block) {
|
||||
var index = dartGenerator.valueToCode(block, 'INDEX',
|
||||
dartGenerator.ORDER_ADDITIVE) || '0';
|
||||
// Adjust index if using one-based indexing.
|
||||
if (block.workspace.options.oneBasedIndex) {
|
||||
if (Blockly.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [Number(index) + 1, Blockly.Dart.ORDER_ATOMIC];
|
||||
return [Number(index) + 1, dartGenerator.ORDER_ATOMIC];
|
||||
} else {
|
||||
// If the index is dynamic, adjust it in code.
|
||||
index = index + ' + 1';
|
||||
}
|
||||
} else if (Blockly.isNumber(index)) {
|
||||
return [index, Blockly.Dart.ORDER_ATOMIC];
|
||||
return [index, dartGenerator.ORDER_ATOMIC];
|
||||
}
|
||||
return [index, Blockly.Dart.ORDER_ADDITIVE];
|
||||
return [index, dartGenerator.ORDER_ADDITIVE];
|
||||
};
|
||||
|
||||
@@ -9,13 +9,13 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Blockly.JavaScript['unittest_main'] = function(block) {
|
||||
javascriptGenerator['unittest_main'] = function(block) {
|
||||
// Container for unit tests.
|
||||
var resultsVar = Blockly.JavaScript.nameDB_.getName('unittestResults',
|
||||
var resultsVar = javascriptGenerator.nameDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.JavaScript.provideFunction_(
|
||||
var functionName = javascriptGenerator.provideFunction_(
|
||||
'unittest_report',
|
||||
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + '() {',
|
||||
[ 'function ' + javascriptGenerator.FUNCTION_NAME_PLACEHOLDER_ + '() {',
|
||||
' // Create test report.',
|
||||
' var report = [];',
|
||||
' var summary = [];',
|
||||
@@ -51,7 +51,7 @@ Blockly.JavaScript['unittest_main'] = function(block) {
|
||||
block.getFieldValue('SUITE_NAME') +
|
||||
'\')\n';
|
||||
// Run tests (unindented).
|
||||
code += Blockly.JavaScript.statementToCode(block, 'DO')
|
||||
code += javascriptGenerator.statementToCode(block, 'DO')
|
||||
.replace(/^ /, '').replace(/\n /g, '\n');
|
||||
// Send the report to the console (that's where errors will go anyway).
|
||||
code += 'console.log(' + functionName + '());\n';
|
||||
@@ -60,12 +60,12 @@ Blockly.JavaScript['unittest_main'] = function(block) {
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.JavaScript['unittest_main'].defineAssert_ = function(block) {
|
||||
var resultsVar = Blockly.JavaScript.nameDB_.getName('unittestResults',
|
||||
javascriptGenerator['unittest_main'].defineAssert_ = function(block) {
|
||||
var resultsVar = javascriptGenerator.nameDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.JavaScript.provideFunction_(
|
||||
var functionName = javascriptGenerator.provideFunction_(
|
||||
'assertEquals',
|
||||
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
[ 'function ' + javascriptGenerator.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'(actual, expected, message) {',
|
||||
' // Asserts that a value equals another value.',
|
||||
' if (!' + resultsVar + ') {',
|
||||
@@ -100,24 +100,24 @@ Blockly.JavaScript['unittest_main'].defineAssert_ = function(block) {
|
||||
return functionName;
|
||||
};
|
||||
|
||||
Blockly.JavaScript['unittest_assertequals'] = function(block) {
|
||||
javascriptGenerator['unittest_assertequals'] = function(block) {
|
||||
// Asserts that a value equals another value.
|
||||
var message = Blockly.JavaScript.valueToCode(block, 'MESSAGE',
|
||||
Blockly.JavaScript.ORDER_NONE) || '';
|
||||
var actual = Blockly.JavaScript.valueToCode(block, 'ACTUAL',
|
||||
Blockly.JavaScript.ORDER_NONE) || 'null';
|
||||
var expected = Blockly.JavaScript.valueToCode(block, 'EXPECTED',
|
||||
Blockly.JavaScript.ORDER_NONE) || 'null';
|
||||
return Blockly.JavaScript['unittest_main'].defineAssert_() +
|
||||
var message = javascriptGenerator.valueToCode(block, 'MESSAGE',
|
||||
javascriptGenerator.ORDER_NONE) || '';
|
||||
var actual = javascriptGenerator.valueToCode(block, 'ACTUAL',
|
||||
javascriptGenerator.ORDER_NONE) || 'null';
|
||||
var expected = javascriptGenerator.valueToCode(block, 'EXPECTED',
|
||||
javascriptGenerator.ORDER_NONE) || 'null';
|
||||
return javascriptGenerator['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.JavaScript['unittest_assertvalue'] = function(block) {
|
||||
javascriptGenerator['unittest_assertvalue'] = function(block) {
|
||||
// Asserts that a value is true, false, or null.
|
||||
var message = Blockly.JavaScript.valueToCode(block, 'MESSAGE',
|
||||
Blockly.JavaScript.ORDER_NONE) || '';
|
||||
var actual = Blockly.JavaScript.valueToCode(block, 'ACTUAL',
|
||||
Blockly.JavaScript.ORDER_NONE) || 'null';
|
||||
var message = javascriptGenerator.valueToCode(block, 'MESSAGE',
|
||||
javascriptGenerator.ORDER_NONE) || '';
|
||||
var actual = javascriptGenerator.valueToCode(block, 'ACTUAL',
|
||||
javascriptGenerator.ORDER_NONE) || 'null';
|
||||
var expected = block.getFieldValue('EXPECTED');
|
||||
if (expected === 'TRUE') {
|
||||
expected = 'true';
|
||||
@@ -126,18 +126,18 @@ Blockly.JavaScript['unittest_assertvalue'] = function(block) {
|
||||
} else if (expected === 'NULL') {
|
||||
expected = 'null';
|
||||
}
|
||||
return Blockly.JavaScript['unittest_main'].defineAssert_() +
|
||||
return javascriptGenerator['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.JavaScript['unittest_fail'] = function(block) {
|
||||
javascriptGenerator['unittest_fail'] = function(block) {
|
||||
// Always assert an error.
|
||||
var resultsVar = Blockly.JavaScript.nameDB_.getName('unittestResults',
|
||||
var resultsVar = javascriptGenerator.nameDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var message = Blockly.JavaScript.quote_(block.getFieldValue('MESSAGE'));
|
||||
var functionName = Blockly.JavaScript.provideFunction_(
|
||||
var message = javascriptGenerator.quote_(block.getFieldValue('MESSAGE'));
|
||||
var functionName = javascriptGenerator.provideFunction_(
|
||||
'unittest_fail',
|
||||
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
[ 'function ' + javascriptGenerator.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'(message) {',
|
||||
' // Always assert an error.',
|
||||
' if (!' + resultsVar + ') {',
|
||||
@@ -148,20 +148,20 @@ Blockly.JavaScript['unittest_fail'] = function(block) {
|
||||
return functionName + '(' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.JavaScript['unittest_adjustindex'] = function(block) {
|
||||
var index = Blockly.JavaScript.valueToCode(block, 'INDEX',
|
||||
Blockly.JavaScript.ORDER_ADDITION) || '0';
|
||||
javascriptGenerator['unittest_adjustindex'] = function(block) {
|
||||
var index = javascriptGenerator.valueToCode(block, 'INDEX',
|
||||
javascriptGenerator.ORDER_ADDITION) || '0';
|
||||
// Adjust index if using one-based indexing.
|
||||
if (block.workspace.options.oneBasedIndex) {
|
||||
if (Blockly.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [Number(index) + 1, Blockly.JavaScript.ORDER_ATOMIC];
|
||||
return [Number(index) + 1, javascriptGenerator.ORDER_ATOMIC];
|
||||
} else {
|
||||
// If the index is dynamic, adjust it in code.
|
||||
index = index + ' + 1';
|
||||
}
|
||||
} else if (Blockly.isNumber(index)) {
|
||||
return [index, Blockly.JavaScript.ORDER_ATOMIC];
|
||||
return [index, javascriptGenerator.ORDER_ATOMIC];
|
||||
}
|
||||
return [index, Blockly.JavaScript.ORDER_ADDITION];
|
||||
return [index, javascriptGenerator.ORDER_ADDITION];
|
||||
};
|
||||
|
||||
@@ -9,13 +9,13 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Blockly.Lua['unittest_main'] = function(block) {
|
||||
luaGenerator['unittest_main'] = function(block) {
|
||||
// Container for unit tests.
|
||||
var resultsVar = Blockly.Lua.nameDB_.getName('unittestResults',
|
||||
var resultsVar = luaGenerator.nameDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.Lua.provideFunction_(
|
||||
var functionName = luaGenerator.provideFunction_(
|
||||
'unittest_report',
|
||||
['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ + '()',
|
||||
['function ' + luaGenerator.FUNCTION_NAME_PLACEHOLDER_ + '()',
|
||||
' -- Create test report.',
|
||||
' local report = {}',
|
||||
' local summary = {}',
|
||||
@@ -49,7 +49,7 @@ Blockly.Lua['unittest_main'] = function(block) {
|
||||
block.getFieldValue('SUITE_NAME') +
|
||||
'\')\n';
|
||||
// Run tests (unindented).
|
||||
code += Blockly.Lua.statementToCode(block, 'DO')
|
||||
code += luaGenerator.statementToCode(block, 'DO')
|
||||
.replace(/^ /, '').replace(/\n /g, '\n');
|
||||
// Print the report.
|
||||
code += 'print(' + functionName + '())\n';
|
||||
@@ -58,12 +58,12 @@ Blockly.Lua['unittest_main'] = function(block) {
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Lua['unittest_main'].defineAssert_ = function(block) {
|
||||
var resultsVar = Blockly.Lua.nameDB_.getName('unittestResults',
|
||||
luaGenerator['unittest_main'].defineAssert_ = function(block) {
|
||||
var resultsVar = luaGenerator.nameDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.Lua.provideFunction_(
|
||||
var functionName = luaGenerator.provideFunction_(
|
||||
'assertEquals',
|
||||
['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
['function ' + luaGenerator.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'(actual, expected, message)',
|
||||
' -- Asserts that a value equals another value.',
|
||||
' assert(' + resultsVar + ' ~= nil, ' +
|
||||
@@ -106,24 +106,24 @@ Blockly.Lua['unittest_main'].defineAssert_ = function(block) {
|
||||
return functionName;
|
||||
};
|
||||
|
||||
Blockly.Lua['unittest_assertequals'] = function(block) {
|
||||
luaGenerator['unittest_assertequals'] = function(block) {
|
||||
// Asserts that a value equals another value.
|
||||
var message = Blockly.Lua.valueToCode(block, 'MESSAGE',
|
||||
Blockly.Lua.ORDER_NONE) || '';
|
||||
var actual = Blockly.Lua.valueToCode(block, 'ACTUAL',
|
||||
Blockly.Lua.ORDER_NONE) || 'nil';
|
||||
var expected = Blockly.Lua.valueToCode(block, 'EXPECTED',
|
||||
Blockly.Lua.ORDER_NONE) || 'nil';
|
||||
return Blockly.Lua['unittest_main'].defineAssert_() +
|
||||
var message = luaGenerator.valueToCode(block, 'MESSAGE',
|
||||
luaGenerator.ORDER_NONE) || '';
|
||||
var actual = luaGenerator.valueToCode(block, 'ACTUAL',
|
||||
luaGenerator.ORDER_NONE) || 'nil';
|
||||
var expected = luaGenerator.valueToCode(block, 'EXPECTED',
|
||||
luaGenerator.ORDER_NONE) || 'nil';
|
||||
return luaGenerator['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ')\n';
|
||||
};
|
||||
|
||||
Blockly.Lua['unittest_assertvalue'] = function(block) {
|
||||
luaGenerator['unittest_assertvalue'] = function(block) {
|
||||
// Asserts that a value is true, false, or null.
|
||||
var message = Blockly.Lua.valueToCode(block, 'MESSAGE',
|
||||
Blockly.Lua.ORDER_NONE) || '';
|
||||
var actual = Blockly.Lua.valueToCode(block, 'ACTUAL',
|
||||
Blockly.Lua.ORDER_NONE) || 'nil';
|
||||
var message = luaGenerator.valueToCode(block, 'MESSAGE',
|
||||
luaGenerator.ORDER_NONE) || '';
|
||||
var actual = luaGenerator.valueToCode(block, 'ACTUAL',
|
||||
luaGenerator.ORDER_NONE) || 'nil';
|
||||
var expected = block.getFieldValue('EXPECTED');
|
||||
if (expected == 'TRUE') {
|
||||
expected = 'true';
|
||||
@@ -132,18 +132,18 @@ Blockly.Lua['unittest_assertvalue'] = function(block) {
|
||||
} else if (expected == 'NULL') {
|
||||
expected = 'nil';
|
||||
}
|
||||
return Blockly.Lua.unittest_main.defineAssert_() +
|
||||
return luaGenerator.unittest_main.defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ')\n';
|
||||
};
|
||||
|
||||
Blockly.Lua['unittest_fail'] = function(block) {
|
||||
luaGenerator['unittest_fail'] = function(block) {
|
||||
// Always assert an error.
|
||||
var resultsVar = Blockly.Lua.nameDB_.getName('unittestResults',
|
||||
var resultsVar = luaGenerator.nameDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var message = Blockly.Lua.quote_(block.getFieldValue('MESSAGE'));
|
||||
var functionName = Blockly.Lua.provideFunction_(
|
||||
var message = luaGenerator.quote_(block.getFieldValue('MESSAGE'));
|
||||
var functionName = luaGenerator.provideFunction_(
|
||||
'unittest_fail',
|
||||
['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ + '(message)',
|
||||
['function ' + luaGenerator.FUNCTION_NAME_PLACEHOLDER_ + '(message)',
|
||||
' -- Always assert an error.',
|
||||
' assert(' + resultsVar +
|
||||
' ~= nil, "Orphaned assert fail: " .. message)',
|
||||
@@ -153,13 +153,13 @@ Blockly.Lua['unittest_fail'] = function(block) {
|
||||
return functionName + '(' + message + ')\n';
|
||||
};
|
||||
|
||||
Blockly.Lua['unittest_adjustindex'] = function(block) {
|
||||
var index = Blockly.Lua.valueToCode(block, 'INDEX',
|
||||
Blockly.Lua.ORDER_ADDITIVE) || '0';
|
||||
luaGenerator['unittest_adjustindex'] = function(block) {
|
||||
var index = luaGenerator.valueToCode(block, 'INDEX',
|
||||
luaGenerator.ORDER_ADDITIVE) || '0';
|
||||
if (Blockly.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [Number(index) + 1, Blockly.Lua.ORDER_ATOMIC];
|
||||
return [Number(index) + 1, luaGenerator.ORDER_ATOMIC];
|
||||
}
|
||||
// If the index is dynamic, adjust it in code.
|
||||
return [index + ' + 1', Blockly.Lua.ORDER_ADDITIVE];
|
||||
return [index + ' + 1', luaGenerator.ORDER_ADDITIVE];
|
||||
};
|
||||
|
||||
@@ -9,13 +9,13 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Blockly.PHP['unittest_main'] = function(block) {
|
||||
phpGenerator['unittest_main'] = function(block) {
|
||||
// Container for unit tests.
|
||||
var resultsVar = Blockly.PHP.nameDB_.getName('unittestResults',
|
||||
var resultsVar = phpGenerator.nameDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.PHP.provideFunction_(
|
||||
var functionName = phpGenerator.provideFunction_(
|
||||
'unittest_report',
|
||||
[ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ + '() {',
|
||||
[ 'function ' + phpGenerator.FUNCTION_NAME_PLACEHOLDER_ + '() {',
|
||||
' global ' + resultsVar + ';',
|
||||
' // Create test report.',
|
||||
' $report = array();',
|
||||
@@ -51,7 +51,7 @@ Blockly.PHP['unittest_main'] = function(block) {
|
||||
block.getFieldValue('SUITE_NAME') +
|
||||
'\\n");\n';
|
||||
// Run tests (unindented).
|
||||
code += Blockly.PHP.statementToCode(block, 'DO')
|
||||
code += phpGenerator.statementToCode(block, 'DO')
|
||||
.replace(/^ /, '').replace(/\n /g, '\n');
|
||||
// Send the report to the console (that's where errors will go anyway).
|
||||
code += 'print(' + functionName + '());\n';
|
||||
@@ -60,12 +60,12 @@ Blockly.PHP['unittest_main'] = function(block) {
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.PHP['unittest_main'].defineAssert_ = function(block) {
|
||||
var resultsVar = Blockly.PHP.nameDB_.getName('unittestResults',
|
||||
phpGenerator['unittest_main'].defineAssert_ = function(block) {
|
||||
var resultsVar = phpGenerator.nameDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.PHP.provideFunction_(
|
||||
var functionName = phpGenerator.provideFunction_(
|
||||
'assertEquals',
|
||||
['function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
['function ' + phpGenerator.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'($actual, $expected, $message) {',
|
||||
' global ' + resultsVar + ';',
|
||||
' // Asserts that a value equals another value.',
|
||||
@@ -86,24 +86,24 @@ Blockly.PHP['unittest_main'].defineAssert_ = function(block) {
|
||||
return functionName;
|
||||
};
|
||||
|
||||
Blockly.PHP['unittest_assertequals'] = function(block) {
|
||||
phpGenerator['unittest_assertequals'] = function(block) {
|
||||
// Asserts that a value equals another value.
|
||||
var message = Blockly.PHP.valueToCode(block, 'MESSAGE',
|
||||
Blockly.PHP.ORDER_NONE) || '';
|
||||
var actual = Blockly.PHP.valueToCode(block, 'ACTUAL',
|
||||
Blockly.PHP.ORDER_NONE) || 'null';
|
||||
var expected = Blockly.PHP.valueToCode(block, 'EXPECTED',
|
||||
Blockly.PHP.ORDER_NONE) || 'null';
|
||||
return Blockly.PHP['unittest_main'].defineAssert_() +
|
||||
var message = phpGenerator.valueToCode(block, 'MESSAGE',
|
||||
phpGenerator.ORDER_NONE) || '';
|
||||
var actual = phpGenerator.valueToCode(block, 'ACTUAL',
|
||||
phpGenerator.ORDER_NONE) || 'null';
|
||||
var expected = phpGenerator.valueToCode(block, 'EXPECTED',
|
||||
phpGenerator.ORDER_NONE) || 'null';
|
||||
return phpGenerator['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.PHP['unittest_assertvalue'] = function(block) {
|
||||
phpGenerator['unittest_assertvalue'] = function(block) {
|
||||
// Asserts that a value is true, false, or null.
|
||||
var message = Blockly.PHP.valueToCode(block, 'MESSAGE',
|
||||
Blockly.PHP.ORDER_NONE) || '';
|
||||
var actual = Blockly.PHP.valueToCode(block, 'ACTUAL',
|
||||
Blockly.PHP.ORDER_NONE) || 'null';
|
||||
var message = phpGenerator.valueToCode(block, 'MESSAGE',
|
||||
phpGenerator.ORDER_NONE) || '';
|
||||
var actual = phpGenerator.valueToCode(block, 'ACTUAL',
|
||||
phpGenerator.ORDER_NONE) || 'null';
|
||||
var expected = block.getFieldValue('EXPECTED');
|
||||
if (expected == 'TRUE') {
|
||||
expected = 'true';
|
||||
@@ -112,18 +112,18 @@ Blockly.PHP['unittest_assertvalue'] = function(block) {
|
||||
} else if (expected == 'NULL') {
|
||||
expected = 'null';
|
||||
}
|
||||
return Blockly.PHP['unittest_main'].defineAssert_() +
|
||||
return phpGenerator['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.PHP['unittest_fail'] = function(block) {
|
||||
phpGenerator['unittest_fail'] = function(block) {
|
||||
// Always assert an error.
|
||||
var resultsVar = Blockly.PHP.nameDB_.getName('unittestResults',
|
||||
var resultsVar = phpGenerator.nameDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var message = Blockly.PHP.quote_(block.getFieldValue('MESSAGE'));
|
||||
var functionName = Blockly.PHP.provideFunction_(
|
||||
var message = phpGenerator.quote_(block.getFieldValue('MESSAGE'));
|
||||
var functionName = phpGenerator.provideFunction_(
|
||||
'unittest_fail',
|
||||
[ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
[ 'function ' + phpGenerator.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'($message) {',
|
||||
' global ' + resultsVar + ';',
|
||||
' // Always assert an error.',
|
||||
@@ -135,20 +135,20 @@ Blockly.PHP['unittest_fail'] = function(block) {
|
||||
return functionName + '(' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.PHP['unittest_adjustindex'] = function(block) {
|
||||
var index = Blockly.PHP.valueToCode(block, 'INDEX',
|
||||
Blockly.PHP.ORDER_ADDITION) || '0';
|
||||
phpGenerator['unittest_adjustindex'] = function(block) {
|
||||
var index = phpGenerator.valueToCode(block, 'INDEX',
|
||||
phpGenerator.ORDER_ADDITION) || '0';
|
||||
// Adjust index if using one-based indexing.
|
||||
if (block.workspace.options.oneBasedIndex) {
|
||||
if (Blockly.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [Number(index) + 1, Blockly.PHP.ORDER_ATOMIC];
|
||||
return [Number(index) + 1, phpGenerator.ORDER_ATOMIC];
|
||||
} else {
|
||||
// If the index is dynamic, adjust it in code.
|
||||
index = index + ' + 1';
|
||||
}
|
||||
} else if (Blockly.isNumber(index)) {
|
||||
return [index, Blockly.PHP.ORDER_ATOMIC];
|
||||
return [index, phpGenerator.ORDER_ATOMIC];
|
||||
}
|
||||
return [index, Blockly.PHP.ORDER_ADDITION];
|
||||
return [index, phpGenerator.ORDER_ADDITION];
|
||||
};
|
||||
|
||||
@@ -9,13 +9,13 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Blockly.Python['unittest_main'] = function(block) {
|
||||
pythonGenerator['unittest_main'] = function(block) {
|
||||
// Container for unit tests.
|
||||
var resultsVar = Blockly.Python.nameDB_.getName('unittestResults',
|
||||
var resultsVar = pythonGenerator.nameDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.Python.provideFunction_(
|
||||
var functionName = pythonGenerator.provideFunction_(
|
||||
'unittest_report',
|
||||
['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + '():',
|
||||
['def ' + pythonGenerator.FUNCTION_NAME_PLACEHOLDER_ + '():',
|
||||
' # Create test report.',
|
||||
' report = []',
|
||||
' summary = []',
|
||||
@@ -47,7 +47,7 @@ Blockly.Python['unittest_main'] = function(block) {
|
||||
block.getFieldValue('SUITE_NAME') +
|
||||
'\')\n';
|
||||
// Run tests (unindented).
|
||||
code += Blockly.Python.statementToCode(block, 'DO')
|
||||
code += pythonGenerator.statementToCode(block, 'DO')
|
||||
.replace(/^ /, '').replace(/\n /g, '\n');
|
||||
// Print the report.
|
||||
code += 'print(' + functionName + '())\n';
|
||||
@@ -56,12 +56,12 @@ Blockly.Python['unittest_main'] = function(block) {
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Python['unittest_main'].defineAssert_ = function() {
|
||||
var resultsVar = Blockly.Python.nameDB_.getName('unittestResults',
|
||||
pythonGenerator['unittest_main'].defineAssert_ = function() {
|
||||
var resultsVar = pythonGenerator.nameDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.Python.provideFunction_(
|
||||
var functionName = pythonGenerator.provideFunction_(
|
||||
'assertEquals',
|
||||
['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
['def ' + pythonGenerator.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'(actual, expected, message):',
|
||||
' # Asserts that a value equals another value.',
|
||||
' if ' + resultsVar + ' == None:',
|
||||
@@ -74,24 +74,24 @@ Blockly.Python['unittest_main'].defineAssert_ = function() {
|
||||
return functionName;
|
||||
};
|
||||
|
||||
Blockly.Python['unittest_assertequals'] = function(block) {
|
||||
pythonGenerator['unittest_assertequals'] = function(block) {
|
||||
// Asserts that a value equals another value.
|
||||
var message = Blockly.Python.valueToCode(block, 'MESSAGE',
|
||||
Blockly.Python.ORDER_NONE) || '';
|
||||
var actual = Blockly.Python.valueToCode(block, 'ACTUAL',
|
||||
Blockly.Python.ORDER_NONE) || 'None';
|
||||
var expected = Blockly.Python.valueToCode(block, 'EXPECTED',
|
||||
Blockly.Python.ORDER_NONE) || 'None';
|
||||
return Blockly.Python['unittest_main'].defineAssert_() +
|
||||
var message = pythonGenerator.valueToCode(block, 'MESSAGE',
|
||||
pythonGenerator.ORDER_NONE) || '';
|
||||
var actual = pythonGenerator.valueToCode(block, 'ACTUAL',
|
||||
pythonGenerator.ORDER_NONE) || 'None';
|
||||
var expected = pythonGenerator.valueToCode(block, 'EXPECTED',
|
||||
pythonGenerator.ORDER_NONE) || 'None';
|
||||
return pythonGenerator['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ')\n';
|
||||
};
|
||||
|
||||
Blockly.Python['unittest_assertvalue'] = function(block) {
|
||||
pythonGenerator['unittest_assertvalue'] = function(block) {
|
||||
// Asserts that a value is true, false, or null.
|
||||
var message = Blockly.Python.valueToCode(block, 'MESSAGE',
|
||||
Blockly.Python.ORDER_NONE) || '';
|
||||
var actual = Blockly.Python.valueToCode(block, 'ACTUAL',
|
||||
Blockly.Python.ORDER_NONE) || 'None';
|
||||
var message = pythonGenerator.valueToCode(block, 'MESSAGE',
|
||||
pythonGenerator.ORDER_NONE) || '';
|
||||
var actual = pythonGenerator.valueToCode(block, 'ACTUAL',
|
||||
pythonGenerator.ORDER_NONE) || 'None';
|
||||
var expected = block.getFieldValue('EXPECTED');
|
||||
if (expected == 'TRUE') {
|
||||
expected = 'True';
|
||||
@@ -100,18 +100,18 @@ Blockly.Python['unittest_assertvalue'] = function(block) {
|
||||
} else if (expected == 'NULL') {
|
||||
expected = 'None';
|
||||
}
|
||||
return Blockly.Python['unittest_main'].defineAssert_() +
|
||||
return pythonGenerator['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ')\n';
|
||||
};
|
||||
|
||||
Blockly.Python['unittest_fail'] = function(block) {
|
||||
pythonGenerator['unittest_fail'] = function(block) {
|
||||
// Always assert an error.
|
||||
var resultsVar = Blockly.Python.nameDB_.getName('unittestResults',
|
||||
var resultsVar = pythonGenerator.nameDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var message = Blockly.Python.quote_(block.getFieldValue('MESSAGE'));
|
||||
var functionName = Blockly.Python.provideFunction_(
|
||||
var message = pythonGenerator.quote_(block.getFieldValue('MESSAGE'));
|
||||
var functionName = pythonGenerator.provideFunction_(
|
||||
'fail',
|
||||
['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + '(message):',
|
||||
['def ' + pythonGenerator.FUNCTION_NAME_PLACEHOLDER_ + '(message):',
|
||||
' # Always assert an error.',
|
||||
' if ' + resultsVar + ' == None:',
|
||||
' raise Exception("Orphaned assert equals: " + message)',
|
||||
@@ -119,20 +119,20 @@ Blockly.Python['unittest_fail'] = function(block) {
|
||||
return functionName + '(' + message + ')\n';
|
||||
};
|
||||
|
||||
Blockly.Python['unittest_adjustindex'] = function(block) {
|
||||
var index = Blockly.Python.valueToCode(block, 'INDEX',
|
||||
Blockly.Python.ORDER_ADDITIVE) || '0';
|
||||
pythonGenerator['unittest_adjustindex'] = function(block) {
|
||||
var index = pythonGenerator.valueToCode(block, 'INDEX',
|
||||
pythonGenerator.ORDER_ADDITIVE) || '0';
|
||||
// Adjust index if using one-based indexing.
|
||||
if (block.workspace.options.oneBasedIndex) {
|
||||
if (Blockly.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [Number(index) + 1, Blockly.Python.ORDER_ATOMIC];
|
||||
return [Number(index) + 1, pythonGenerator.ORDER_ATOMIC];
|
||||
} else {
|
||||
// If the index is dynamic, adjust it in code.
|
||||
index = index + ' + 1';
|
||||
}
|
||||
} else if (Blockly.isNumber(index)) {
|
||||
return [index, Blockly.Python.ORDER_ATOMIC];
|
||||
return [index, pythonGenerator.ORDER_ATOMIC];
|
||||
}
|
||||
return [index, Blockly.Python.ORDER_ADDITIVE];
|
||||
return [index, pythonGenerator.ORDER_ADDITIVE];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user