Saturday, April 9, 2011

STIQ-Pipe Format JS for IDE

var SEPARATORS = {
comma: ",",
Pipe: "|",
tab: "\t",
Tilde: '~~'
};

function formatCommands(commands) {
var result = '';
var sep = SEPARATORS[options['separator']];
for (var i = 0; i < commands.length; i++) {
var command = commands[i];
if (command.type == 'command') {
switch (sep) {
case '|':
result += sep+command.command + sep + command.target + sep + command.value + sep+ "\r\n";
break;
case '~~':
result += sep+command.command + sep + command.target + sep + command.value + sep+ "\r\n";
break;
default:
result += command.command + sep + command.target + sep + command.value + "\r\n";
}
}
}
//alert(result);
return result;
}

function parse(testCase, source) {
var doc = source;
var commands = [];
var sep = SEPARATORS[options['separator']];
//alert("sep"+sep)
while (doc.length > 0) {
var line = /(.*)(\r\n|[\r\n])?/.exec(doc);
var array = line[1].split(sep);
if (array.length >= 3) {
var command = new Command();
switch (sep) {
case '|':
command.command = array[1];
command.target = array[2];
command.value = array[3];
break;
case '~~':
command.command = array[1];
command.target = array[2];
command.value = array[3];
break;

default:
command.command = array[0];
command.target = array[1];
command.value = array[2];
}
commands.push(command);
}
doc = doc.substr(line[0].length);
}
testCase.setCommands(commands);
}

function format(testCase, name) {
return formatCommands(testCase.commands);
}

options = {separator: 'comma',separator: 'Pipe',separator: 'Tilde'};

configForm =
'Separator' +
'' +
'' +
'' +
'' +
'' +
'' +
'
' +
'
';

No comments:

Post a Comment