Skip to content

Instantly share code, notes, and snippets.

@tenbits
Created Dec 19, 2012
Embed
What would you like to do?
Komodo IDE Macro. Unit Testing Thing. Evaluate selected or full source code. Evaluates also code in comment: /*{test} .... */
var view = ko.views.manager.currentView,
scimoz = view.scimoz,
selection = scimoz.selText || scimoz.text,
service = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService),
log = function() {
var message = '';
for (var i = 0; i < arguments.length; i++) {
message += arguments[i] + ' ';
}
service.logStringMessage(message);
},
stringInsert = function(text, str, index){
return text.substring(0, index) + str + text.substring(index);
},
index = 0;
while ((index = selection.indexOf('{test}', index)) > -1){
var newLine = selection.indexOf('\n', index);
if (newLine > -1) {
selection = stringInsert(selection, '*/', newLine - 1);
newLine += 3;
var end = selection.indexOf('*/', newLine);
selection = stringInsert(selection, '/*', end);
index = end + 2;
}
}
try {
var console = {
log: log
}
service.reset();
window.openDialog("chrome://global/content/console.xul", "_blank");
var result = eval(selection);
log('Output:', result);
} catch (e) {
log('Error:', e, 'Line:', e.lineNumber - 703);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment