Skip to content

Commit

Permalink
Merge c387d5f into 0477ee9
Browse files Browse the repository at this point in the history
  • Loading branch information
Sedictious committed Apr 16, 2019
2 parents 0477ee9 + c387d5f commit 741954e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/core/attrsgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,17 @@ AttrsGeneratorPtr AttrsGenerator::parse(const AttributesScope& attrsScope,
int size = cmd.toInt(&sizeIsValid);
if (sizeIsValid) { // cmd is just an interger
_cmd = QString("*%1;min").arg(size);
cmds.push_back(cmd);
cmds.push_back("min");
} else {
} else if (cmd.indexOf(";") != -1){
cmds = cmd.split(";");
QString sizeStr = cmds.first();
size = sizeStr.remove(0,1).toInt(&sizeIsValid);
_cmd = cmd;
} else { // if cmd isn't an integer or semicolon seperated, throw an error
error = "the command '" + cmd + "' is invalid!";
qWarning() << error;
return nullptr;
}

if (sizeIsValid) {
Expand Down
18 changes: 18 additions & 0 deletions src/test/tst_attrsgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private slots:
void cleanupTestCase() {}
void tst_parseStarCmd();
void tst_parseHashCmd();
void tst_parseIntegerCmd();

private:
void _tst_attrs(const SetOfAttributes& res,
Expand Down Expand Up @@ -171,6 +172,23 @@ void TestAttrsGenerator::_tst_parseStarCmd(const QString& func, const Attributes
}
}

void TestAttrsGenerator::tst_parseIntegerCmd()
{
const int sizeOfAgen = 1;
const QStringList attrRgeStrs = {"int[0,16]"};
const QStringList names = {"test0"};

QString error;
QString _cmd = "8";
QString _exp_cmd = "*8;min";
const QString def_func = "min";

const AttributesScope attrsScope = _newAttrsScope(names, attrRgeStrs);
auto agen = AttrsGenerator::parse(attrsScope, _cmd, error);

QCOMPARE(agen->command(), _exp_cmd);
}

void TestAttrsGenerator::tst_parseStarCmd()
{
const QStringList names = {"test0", "test1", "test2"};
Expand Down

0 comments on commit 741954e

Please sign in to comment.