mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-08-29 03:39:57 +00:00
refactor: simplify sources processing
Also fix desktop source
This commit is contained in:
@ -15,7 +15,6 @@
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "testawpatternfunctions.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
@ -36,12 +35,12 @@ void TestAWPatternFunctions::cleanupTestCase() {}
|
||||
|
||||
void TestAWPatternFunctions::test_findFunctionCalls()
|
||||
{
|
||||
QString name = QString("aw_%1").arg(AWTestLibrary::randomString(1, 10));
|
||||
QString code = AWTestLibrary::randomString(1, 20);
|
||||
QStringList args = AWTestLibrary::randomStringList(20);
|
||||
QString function = QString("$%1<%2>{{%3}}").arg(name).arg(args.join(',')).arg(code);
|
||||
auto name = QString("aw_%1").arg(AWTestLibrary::randomString(1, 10));
|
||||
auto code = AWTestLibrary::randomString(1, 20);
|
||||
auto args = AWTestLibrary::randomStringList(20);
|
||||
auto function = QString("$%1<%2>{{%3}}").arg(name).arg(args.join(',')).arg(code);
|
||||
|
||||
QString pattern = AWTestLibrary::randomString() + function + AWTestLibrary::randomString();
|
||||
auto pattern = AWTestLibrary::randomString() + function + AWTestLibrary::randomString();
|
||||
|
||||
QList<AWPatternFunctions::AWFunction> found = AWPatternFunctions::findFunctionCalls(name, pattern);
|
||||
QCOMPARE(found.count(), 1);
|
||||
@ -54,9 +53,9 @@ void TestAWPatternFunctions::test_findFunctionCalls()
|
||||
|
||||
void TestAWPatternFunctions::test_findKeys()
|
||||
{
|
||||
int count = AWTestLibrary::randomInt(200);
|
||||
auto count = AWTestLibrary::randomInt(200);
|
||||
QStringList allKeys;
|
||||
for (int i = 0; i < count; i++) {
|
||||
for (auto i = 0; i < count; i++) {
|
||||
auto key = AWTestLibrary::randomString(1, 20);
|
||||
while (allKeys.indexOf(QRegularExpression(QString("^%1.*").arg(key))) != -1)
|
||||
key = AWTestLibrary::randomString(1, 20);
|
||||
@ -65,8 +64,8 @@ void TestAWPatternFunctions::test_findKeys()
|
||||
|
||||
auto keys = AWTestLibrary::randomSelect(allKeys);
|
||||
auto bars = AWTestLibrary::randomSelect(allKeys);
|
||||
std::for_each(bars.begin(), bars.end(), [](QString &bar) { bar.prepend("bar"); });
|
||||
QString pattern = QString("$%1 $%2").arg(keys.join(" $")).arg(bars.join(" $"));
|
||||
std::for_each(bars.begin(), bars.end(), [](auto &bar) { bar.prepend("bar"); });
|
||||
auto pattern = QString("$%1 $%2").arg(keys.join(" $")).arg(bars.join(" $"));
|
||||
|
||||
allKeys.append(bars);
|
||||
allKeys.sort();
|
||||
@ -74,9 +73,9 @@ void TestAWPatternFunctions::test_findKeys()
|
||||
keys.sort();
|
||||
bars.sort();
|
||||
|
||||
QStringList foundKeys = AWPatternFunctions::findKeys(pattern, allKeys, false);
|
||||
auto foundKeys = AWPatternFunctions::findKeys(pattern, allKeys, false);
|
||||
foundKeys.sort();
|
||||
QStringList foundBars = AWPatternFunctions::findKeys(pattern, allKeys, true);
|
||||
auto foundBars = AWPatternFunctions::findKeys(pattern, allKeys, true);
|
||||
foundBars.sort();
|
||||
|
||||
QCOMPARE(foundKeys, keys);
|
||||
@ -86,8 +85,8 @@ void TestAWPatternFunctions::test_findKeys()
|
||||
|
||||
void TestAWPatternFunctions::test_findLambdas()
|
||||
{
|
||||
QStringList lambdas = AWTestLibrary::randomStringList(20);
|
||||
QString pattern
|
||||
auto lambdas = AWTestLibrary::randomStringList(20);
|
||||
auto pattern
|
||||
= AWTestLibrary::randomString() + QString("${{%1}}").arg(lambdas.join("}}${{")) + AWTestLibrary::randomString();
|
||||
|
||||
QCOMPARE(AWPatternFunctions::findLambdas(pattern), lambdas);
|
||||
@ -96,12 +95,12 @@ void TestAWPatternFunctions::test_findLambdas()
|
||||
|
||||
void TestAWPatternFunctions::test_expandTemplates()
|
||||
{
|
||||
int firstValue = AWTestLibrary::randomInt();
|
||||
int secondValue = AWTestLibrary::randomInt();
|
||||
int result = firstValue + secondValue;
|
||||
QString code = QString("$template{{%1+%2}}").arg(firstValue).arg(secondValue);
|
||||
QString prefix = AWTestLibrary::randomString();
|
||||
QString pattern = prefix + code;
|
||||
auto firstValue = AWTestLibrary::randomInt();
|
||||
auto secondValue = AWTestLibrary::randomInt();
|
||||
auto result = firstValue + secondValue;
|
||||
auto code = QString("$template{{%1+%2}}").arg(firstValue).arg(secondValue);
|
||||
auto prefix = AWTestLibrary::randomString();
|
||||
auto pattern = prefix + code;
|
||||
|
||||
QCOMPARE(AWPatternFunctions::expandTemplates(pattern), QString("%1%2").arg(prefix).arg(result));
|
||||
}
|
||||
|
Reference in New Issue
Block a user