if an while allow not in the comparision

master
Marc Wäckerlin 4 years ago
parent 7b9b1f379e
commit d20f50e087
  1. 50
      src/commands.hxx

@ -2365,7 +2365,7 @@ class If: public CommandContainer {
}
QString description() const {
return
tag()+" <variable> <cmp> <value>\n"
tag()+" [not] <variable> <cmp> <value>\n"
" <command1>\n"
" <command2>\n"
" <...>\n"
@ -2374,7 +2374,7 @@ class If: public CommandContainer {
" <command4>\n"
" <...>\n"
"\n\n"+
tag()+" <selector> -> <text>\n"
tag()+" [not] <selector> -> <text>\n"
" <command1>\n"
" <command2>\n"
" <...>\n"
@ -2392,10 +2392,11 @@ class If: public CommandContainer {
"The second variant checks for a text in a selector, "
"similar to command exists. The text can be empty to just "
"check for the existence of a selector. "
"There is an optional else part.";
"There is an optional else part. Optionally start with "
"not to invert the test.";
}
QString command() const {
return tag()+" "+_variable+" "+_cmp+" "+_value
return tag()+(_not?" not ":" ")+_variable+" "+_cmp+" "+_value
+(_script.get()?"\n "+_script->print().join("\n "):"")
+(_else.get()?"\nelse\n "+_else->print().join("\n "):"");
}
@ -2403,6 +2404,11 @@ class If: public CommandContainer {
QStringList& in, QString file, int line,
int indent) {
std::shared_ptr<If> cmd(new If());
QRegularExpressionMatch m;
if (args.contains(QRegularExpression("^ *not +"), &m)) {
args.remove(0, m.capturedLength());
cmd->_not = true;
}
int pos(args.indexOf(QRegularExpression("[=!.^~<>]")));
int len(1);
if (args.contains("->")) {
@ -2437,8 +2443,9 @@ class If: public CommandContainer {
break;
}
}
log(QString("evaluated expression to ")+(check?"true":"false")+": "
+selector+" "+_cmp+" "+value);
if (_not) check=!check;
log(QString("evaluated expression to ")+(check?"true":"false")
+(_not?": not ":": ")+selector+" "+_cmp+" "+value);
} else {
switch (_cmp[0].toLatin1()) {
case '=': check = script->variable(_variable)==value;
@ -2458,8 +2465,9 @@ class If: public CommandContainer {
break;
default:;
}
log(QString("evaluated expression to ")+(check?"true":"false")+": "
+script->variable(_variable)+" "+_cmp+" "+value);
if (_not) check=!check;
log(QString("evaluated expression to ")+(check?"true":"false")
+(_not?": not ":": ")+script->variable(_variable)+" "+_cmp+" "+value);
}
if (check) return runScript(log, this, _script, script, frame);
else if (_else) return runScript(log, this, _else, script, frame);
@ -2475,6 +2483,7 @@ class If: public CommandContainer {
QString _cmp;
QString _value;
std::shared_ptr<Script> _else;
bool _not = false;
};
class While: public CommandContainer {
@ -2484,12 +2493,12 @@ class While: public CommandContainer {
}
QString description() const {
return
tag()+" <variable> <cmp> <value>\n"
tag()+ " [not] <variable> <cmp> <value>\n"
" <command1>\n"
" <command2>\n"
" <...>\n"
"\n\n"+
tag()+" <selector> -> <text>\n"
tag()+" [not] <selector> -> <text>\n"
" <command1>\n"
" <command2>\n"
" <...>\n"
@ -2502,16 +2511,22 @@ class While: public CommandContainer {
"Match allows a regular expression. "
"The second variant checks for a text in a selector, "
"similar to command exists. The text can be empty to just "
"check for the existence of a selector.";
"check for the existence of a selector. Optionally start with "
"not to invert the test.";
}
QString command() const {
return tag()+" "+_variable+" "+_cmp+" "+_value
return tag()+(_not?" not ":" ")+_variable+" "+_cmp+" "+_value
+(_script.get()?"\n "+_script->print().join("\n "):"");
}
std::shared_ptr<Command> parse(Script* script, QString args,
QStringList& in, QString file, int line,
int indent) {
std::shared_ptr<While> cmd(new While());
QRegularExpressionMatch m;
if (args.contains(QRegularExpression("^ *not +"), &m)) {
args.remove(0, m.capturedLength());
cmd->_not = true;
}
int pos(args.indexOf(QRegularExpression("[=!.^~<>]")));
int len(1);
if (args.contains("->")) {
@ -2543,8 +2558,9 @@ class While: public CommandContainer {
break;
}
}
log(QString("evaluated expression to ")+(check?"true":"false")+": "
+selector+" "+_cmp+" "+value);
if (_not) check=!check;
log(QString("evaluated expression to ")+(check?"true":"false")
+(_not?": not ":": ")+selector+" "+_cmp+" "+value);
} else {
switch (_cmp[0].toLatin1()) {
case '=': check = script->variable(_variable)==value;
@ -2564,8 +2580,9 @@ class While: public CommandContainer {
break;
default:;
}
log(QString("evaluated expression to ")+(check?"true":"false")+": "
+script->variable(_variable)+" "+_cmp+" "+value);
if (_not) check=!check;
log(QString("evaluated expression to ")+(check?"true":"false")
+(_not?": not ":": ")+script->variable(_variable)+" "+_cmp+" "+value);
}
if (check) if (!runScript(log, this, _script, script, frame)) return false;
}
@ -2575,6 +2592,7 @@ class While: public CommandContainer {
QString _variable;
QString _cmp;
QString _value;
bool _not = false;
};
class TestSuite: public Command {

Loading…
Cancel
Save