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