mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-03 00:45:56 +00:00
add tests for pattern functions some simplifications
This commit is contained in:
@ -30,7 +30,7 @@ set(TEST_MODULES
|
||||
abstractformatter datetimeformatter floatformatter noformatter scriptformatter
|
||||
extitemaggregator
|
||||
batterysource desktopsource gpuloadsource gputempsource hddtempsource networksource playersource processessource
|
||||
awkeycache awupdatehelper
|
||||
awkeycache awpatternfunctions awupdatehelper
|
||||
dpplugin)
|
||||
foreach (TEST_MODULE ${TEST_MODULES})
|
||||
set(${TEST_MODULE}_HEADERS test${TEST_MODULE}.h)
|
||||
@ -38,11 +38,15 @@ foreach (TEST_MODULE ${TEST_MODULES})
|
||||
if (TEST_MODULE MATCHES "dpplugin")
|
||||
set(${TEST_MODULE}_SOURCES ${${TEST_MODULE}_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/../desktop-panel/plugin/dpadds.cpp
|
||||
${PROJECT_TRDPARTY_DIR}/fontdialog/fontdialog.cpp)
|
||||
elseif(TEST_MODULE MATCHES "awkeycache")
|
||||
elseif (TEST_MODULE MATCHES "awkeycache")
|
||||
set(${TEST_MODULE}_SOURCES ${${TEST_MODULE}_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awkeycache.cpp)
|
||||
elseif(TEST_MODULE MATCHES "awupdatehelper")
|
||||
elseif (TEST_MODULE MATCHES "awpatternfunctions")
|
||||
set(${TEST_MODULE}_SOURCES ${${TEST_MODULE}_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awformatterhelper.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awkeysaggregator.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awpatternfunctions.cpp)
|
||||
elseif (TEST_MODULE MATCHES "awupdatehelper")
|
||||
set(${TEST_MODULE}_SOURCES ${${TEST_MODULE}_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awupdatehelper.cpp)
|
||||
endif(TEST_MODULE MATCHES "dpplugin")
|
||||
endif (TEST_MODULE MATCHES "dpplugin")
|
||||
add_executable(${SUBPROJECT}-${TEST_MODULE} ${${TEST_MODULE}_HEADERS} ${${TEST_MODULE}_SOURCES})
|
||||
target_link_libraries(${SUBPROJECT}-${TEST_MODULE} ${LIBRARY_TEST_SET})
|
||||
add_test(NAME ${TEST_MODULE} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-${TEST_MODULE})
|
||||
|
@ -20,8 +20,8 @@
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
#include "awtestlibrary.h"
|
||||
#include "awkeycache.h"
|
||||
#include "awtestlibrary.h"
|
||||
|
||||
|
||||
void TestAWKeyCache::initTestCase()
|
||||
|
112
sources/test/testawpatternfunctions.cpp
Normal file
112
sources/test/testawpatternfunctions.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "testawpatternfunctions.h"
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
#include "awpatternfunctions.h"
|
||||
#include "awtestlibrary.h"
|
||||
|
||||
|
||||
void TestAWPatternFunctions::initTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TestAWPatternFunctions::cleanupTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TestAWPatternFunctions::test_findFunctionCalls()
|
||||
{
|
||||
QString name = QString("aw_%1").arg(AWTestLibrary::randomString(10));
|
||||
QString code = AWTestLibrary::randomString(20);
|
||||
QStringList args = AWTestLibrary::randomStringList(20);
|
||||
QString function = QString("$%1<%2>{{%3}}")
|
||||
.arg(name)
|
||||
.arg(args.join(QChar(',')))
|
||||
.arg(code);
|
||||
|
||||
QString pattern = AWTestLibrary::randomString() + function
|
||||
+ AWTestLibrary::randomString();
|
||||
|
||||
QList<AWPatternFunctions::AWFunction> found
|
||||
= AWPatternFunctions::findFunctionCalls(name, pattern);
|
||||
QCOMPARE(found.count(), 1);
|
||||
|
||||
QCOMPARE(found.at(0).args, args);
|
||||
QCOMPARE(found.at(0).body, code);
|
||||
QCOMPARE(found.at(0).what, function);
|
||||
}
|
||||
|
||||
|
||||
void TestAWPatternFunctions::test_findKeys()
|
||||
{
|
||||
QStringList keys = AWTestLibrary::randomStringList(20);
|
||||
QStringList bars = AWTestLibrary::randomStringList(20);
|
||||
std::for_each(bars.begin(), bars.end(),
|
||||
[](QString &bar) { bar.prepend(QString("bar")); });
|
||||
QStringList noise = AWTestLibrary::randomStringList(200);
|
||||
QStringList allKeys = keys + bars + noise;
|
||||
QString pattern = QString("$%1 $%2")
|
||||
.arg(keys.join(QString(" $")))
|
||||
.arg(bars.join(QString(" $")));
|
||||
|
||||
keys.sort();
|
||||
bars.sort();
|
||||
QStringList foundKeys
|
||||
= AWPatternFunctions::findKeys(pattern, allKeys, false);
|
||||
foundKeys.sort();
|
||||
QStringList foundBars
|
||||
= AWPatternFunctions::findKeys(pattern, allKeys, true);
|
||||
foundBars.sort();
|
||||
|
||||
QCOMPARE(foundKeys, keys);
|
||||
QCOMPARE(foundBars, bars);
|
||||
}
|
||||
|
||||
|
||||
void TestAWPatternFunctions::test_findLambdas()
|
||||
{
|
||||
QStringList lambdas = AWTestLibrary::randomStringList(20);
|
||||
QString pattern = AWTestLibrary::randomString()
|
||||
+ QString("${{%1}}").arg(lambdas.join(QString("}}${{")))
|
||||
+ AWTestLibrary::randomString();
|
||||
|
||||
QCOMPARE(AWPatternFunctions::findLambdas(pattern), lambdas);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
QCOMPARE(AWPatternFunctions::expandTemplates(pattern),
|
||||
QString("%1%2").arg(prefix).arg(result));
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(TestAWPatternFunctions);
|
43
sources/test/testawpatternfunctions.h
Normal file
43
sources/test/testawpatternfunctions.h
Normal file
@ -0,0 +1,43 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef TESTAWPATTERNFUNCTIONS_H
|
||||
#define TESTAWPATTERNFUNCTIONS_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class TestAWPatternFunctions : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
// initialization
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
// test
|
||||
void test_findFunctionCalls();
|
||||
void test_findKeys();
|
||||
void test_findLambdas();
|
||||
void test_expandTemplates();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif /* TESTAWPATTERNFUNCTIONS_H */
|
Reference in New Issue
Block a user