mirror of
https://github.com/google/blockly.git
synced 2026-01-09 01:50:11 +01:00
Button to load all XML files for testing
This commit is contained in:
@@ -70,6 +70,7 @@
|
||||
<script src="../../blocks/colour.js"></script>
|
||||
<script src="../../blocks/variables.js"></script>
|
||||
<script src="../../blocks/procedures.js"></script>
|
||||
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
@@ -89,6 +90,49 @@ function start() {
|
||||
changeIndex();
|
||||
}
|
||||
|
||||
var all_test_names = [
|
||||
'logic',
|
||||
'loops1',
|
||||
'loops2',
|
||||
'loops3',
|
||||
'math',
|
||||
'text',
|
||||
'lists',
|
||||
'colour',
|
||||
'variables',
|
||||
'functions'
|
||||
];
|
||||
|
||||
/*
|
||||
* Run this test to load all of the test files in all_test_names. The contents
|
||||
* will be loaded into the workspace in order. To test the generators:
|
||||
* - select your language from the buttons above the text area
|
||||
* - copy all of the generated code
|
||||
* - run it in an interpreter of your choice
|
||||
* - scan all of the results for "FAIL". All test suites are running in order,
|
||||
* and each will report OK or FAIL based only on the tests in that suite.
|
||||
* If some tests are failing, load test suites individually to continue
|
||||
* debugging.
|
||||
*/
|
||||
function loadAll() {
|
||||
var output = document.getElementById('importExport');
|
||||
output.style.background = 'gray';
|
||||
|
||||
var loadingElem = document.getElementById('loading');
|
||||
loadingElem.textContent = 'loading...';
|
||||
for (var i = 0; i < all_test_names.length; i++) {
|
||||
var testName = all_test_names[i];
|
||||
var url = testName + '.xml';
|
||||
|
||||
var xmlText = fetchFile(url);
|
||||
if (xmlText !== null) {
|
||||
fromXml(url, xmlText, /* opt_append */ true);
|
||||
}
|
||||
}
|
||||
output.style.background = '';
|
||||
loadingElem.textContent = 'done';
|
||||
}
|
||||
|
||||
function loadXml() {
|
||||
var dropdown = document.getElementById('testUrl');
|
||||
var url = dropdown.options[dropdown.selectedIndex].value;
|
||||
@@ -127,16 +171,24 @@ function fetchFile(xmlUrl) {
|
||||
/**
|
||||
* @param {string} filename The URL (or other name) of the XML, for reporting.
|
||||
* @param {string} xmlText The actual XML text.
|
||||
* @param {boolean=} opt_append True if the XML should be appended to the
|
||||
* workspace. Otherwise the workspace is cleared and the new XML is loaded.
|
||||
*/
|
||||
function fromXml(filename, xmlText) {
|
||||
function fromXml(filename, xmlText, opt_append) {
|
||||
var output = document.getElementById('importExport');
|
||||
output.value = xmlText;
|
||||
output.scrollTop = 0;
|
||||
output.scrollLeft = 0;
|
||||
demoWorkspace.clear();
|
||||
if (!opt_append) {
|
||||
demoWorkspace.clear();
|
||||
}
|
||||
try {
|
||||
var xmlDoc = Blockly.Xml.textToDom(xmlText);
|
||||
Blockly.Xml.domToWorkspace(xmlDoc, demoWorkspace);
|
||||
if (opt_append) {
|
||||
Blockly.Xml.appendDomToWorkspace(xmlDoc, demoWorkspace);
|
||||
} else {
|
||||
Blockly.Xml.domToWorkspace(xmlDoc, demoWorkspace);
|
||||
}
|
||||
} catch (e) {
|
||||
var msg = 'Error parsing XML: ' + filename + '\n\n\t' + e;
|
||||
if (e.stack) {
|
||||
@@ -220,6 +272,9 @@ h1 {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
#loading {
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body onload="start()">
|
||||
@@ -341,6 +396,11 @@ h1 {
|
||||
<input type="button" value="Load" onclick="loadXml()">
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<input type="button" value="Load all" id="loadAllBtn" onclick="loadAll()">
|
||||
<label for="loadAllBtn" id="loading"></label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<input id="indexing" type="checkbox" onchange="changeIndex()" checked>
|
||||
<label for="indexing">Generate with one-based indexing</label>
|
||||
|
||||
Reference in New Issue
Block a user