Created
December 19, 2012 12:20
-
-
Save tenbits/4336299 to your computer and use it in GitHub Desktop.
Komodo IDE Macro. Unit Testing Thing. Evaluate selected or full source code. Evaluates also code in comment: /*{test} .... */
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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