minor refactor on bonfire framework.js

This commit is contained in:
Michael Q Larson
2015-01-21 16:59:19 -08:00
parent ae50945e1a
commit 9e41b0ca7b

View File

@ -80,28 +80,25 @@ var replaceQuotesInTests = function() {
}; };
var tests; var tests;
var testWords = ["expect", "assert"];
var testSalt = Math.random(); var testSalt = Math.random();
var scrapeTests = function(js) { var scrapeTests = function(userJavaScript) {
var counter = 0; var counter = 0;
for (var i = 0; i < testWords.length; i++) { var regex = new RegExp(/(expect(\s+)?\(.*\;)|(assert(\s+)?\(.*\;)|(assert\.\w.*\;)/);
var regex = new RegExp(testWords[i] + "[^;]+;",'g'); var match = regex.exec(userJavaScript);
var match = regex.exec(js); while (match != null) {
while (match != null) { var replacement = '//' + counter + testSalt;
var replacement = '//' + counter + testSalt; userJavaScript = userJavaScript.substring(0, match.index)
js = js.substring(0, match.index) + replacement
+ replacement + userJavaScript.substring(match.index + match[0].length);
+ js.substring(match.index + match[0].length);
if (!tests) tests = []; if (!tests) tests = [];
tests.push({"text": match[0], "line": counter, "err": null}); tests.push({"text": match[0], "line": counter, "err": null});
counter++; counter++;
match = regex.exec(js); match = regex.exec(userJavaScript);
}
} }
replaceQuotesInTests(); replaceQuotesInTests();
return js; return userJavaScript;
}; };
$('#submitButton').on('click', function () { $('#submitButton').on('click', function () {
@ -111,10 +108,9 @@ $('#submitButton').on('click', function () {
function bonfireExecute() { function bonfireExecute() {
tests = undefined; tests = undefined;
$('#codeOutput').empty(); $('#codeOutput').empty();
var js = myCodeMirror.getValue(); var userJavaScript = myCodeMirror.getValue();
js = scrapeTests(js); userJavaScript = scrapeTests(userJavaScript);
console.log(js); submit(userJavaScript, function(cls, message) {
submit(js, function(cls, message) {
if (cls) { if (cls) {
codeOutput.setValue(message.error); codeOutput.setValue(message.error);
runTests('Error', null); runTests('Error', null);
@ -130,7 +126,6 @@ var createTestDisplay = function() {
if (pushed) { if (pushed) {
tests.pop(); tests.pop();
} }
console.log(tests);
for (var i = 0; i < tests.length;i++) { for (var i = 0; i < tests.length;i++) {
var test = tests[i]; var test = tests[i];
var testDoc = document.createElement("li"); var testDoc = document.createElement("li");