now also supports optional else after command if

master
Marc Wäckerlin 9 years ago
parent 9335d5f6bb
commit 13b8752c7a
  1. 7
      ChangeLog
  2. 9
      doc/makefile.amto
  3. 22
      src/commands.hxx

@ -1,3 +1,10 @@
2015-05-09 12:27 marc
* ChangeLog, ax_check_qt.m4, ax_init_standard_project.m4,
bootstrap.sh, doc/makefile.amto, src/commands.hxx,
src/testgui.hxx, src/webrunner.cxx: new commands testsuite and
testcase
2015-05-08 15:34 marc
* ChangeLog, ax_init_standard_project.m4, bootstrap.sh,

@ -1,9 +0,0 @@
## @id $Id$
#
# This file has been added by bootstrap.sh on Sat, 09 May 2015 14:15:27 +0200
# Feel free to change it or even remove and rebuild it, up to your needs
#
## 1 2 3 4 5 6 7 8
## 45678901234567890123456789012345678901234567890123456789012345678901234567890
MAINTAINERCLEANFILES = makefile.in

@ -111,7 +111,7 @@ class Command: public QObject {
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
protected:
void subScript(std::shared_ptr<Script> script,
void runScript(std::shared_ptr<Script> script,
Script* parent, QWebFrame* frame,
QStringList vars = QStringList(),
QStringList args = QStringList());
@ -1843,7 +1843,7 @@ class Function: public Command {
bool call(QStringList args, Script* script, QWebFrame* frame) {
Logger log(this, script);
try {
subScript(_script, script, frame, _vars, args);
runScript(_script, script, frame, _vars, args);
} catch (const std::exception& x) {
throw FunctionCallFailed(_name, _vars, args, x);
}
@ -1902,12 +1902,17 @@ class If: public Command {
" <command1>\n"
" <command2>\n"
" <...>\n"
"else\n"
" <command3>\n"
" <command4>\n"
" <...>\n"
"\n\n"
"Execute commands conditionally. "
"The comparision <cmp> can be = ^ ~ < >, "
"which means equal, different, match, "
"less (as integer), bigger (as integer). "
"Match allows a regular expression.";
"Match allows a regular expression. "
"There is an optional else part.";
}
QString command() const {
return tag()+" "+_variable+" "+QString(_cmp)+" "+_value
@ -1923,6 +1928,11 @@ class If: public Command {
cmd->_value = args.mid(pos+1).trimmed();
cmd->_script = std::shared_ptr<Script>(new Script);
cmd->_script->parse(subCommandBlock(in));
if (in.size() && in.first().contains(QRegularExpression("^else *$"))) {
in.removeFirst();
cmd->_else = std::shared_ptr<Script>(new Script);
cmd->_else->parse(subCommandBlock(in));
}
return cmd;
}
bool execute(Script* script, QWebFrame* frame) {
@ -1943,7 +1953,8 @@ class If: public Command {
break;
default:;
}
if (check) subScript(_script, script, frame);
if (check) runScript(_script, script, frame);
else if (_else) runScript(_else, script, frame);
return true;
}
private:
@ -1951,6 +1962,7 @@ class If: public Command {
char _cmp;
QString _value;
std::shared_ptr<Script> _script;
std::shared_ptr<Script> _else;
};
class TestSuite: public Command {
@ -2067,7 +2079,7 @@ inline Logger::~Logger() {
_script->log("---------------------");
}
inline void Command::subScript(std::shared_ptr<Script> script,
inline void Command::runScript(std::shared_ptr<Script> script,
Script* parent, QWebFrame* frame,
QStringList vars,
QStringList args) {

Loading…
Cancel
Save