Add unit test for regex parsing comments in SQL query (#826)

This commit is contained in:
Vlad
2016-10-14 14:23:27 +03:00
committed by Martin Kleusberg
parent 1592b7d2c3
commit c25119ed4e
5 changed files with 129 additions and 1 deletions

42
src/tests/TestRegex.cpp Normal file
View File

@@ -0,0 +1,42 @@
#include "TestRegex.h"
#include "../sqlitetablemodel.h"
#include <QtTest/QTest>
QTEST_APPLESS_MAIN(TestRegex)
void TestRegex::sqlQueryComments_data()
{
QTest::addColumn<QString>("dirtyQuery");
QTest::addColumn<QString>("clearQuery");
QTest::newRow("test1")
<< // dirtyQuery
"SELECT * -- asd ffdsf\n"
"-- saf ewf sf\n"
"-- dsaf fd\n"
"FROM \t-- sfsdf\n"
"qwfwqf -- asdasd"
<< // clearQuery
"SELECT *\nFROM\nqwfwqf";
QTest::newRow("test2")
<< // dirtyQuery
"SELECT *-- comment\n"
"FROM\n\n"
"-- something\n"
"qwfqwf"
<< // cleanQuery
"SELECT *\nFROM\nqwfqwf";
}
void TestRegex::sqlQueryComments()
{
SqliteTableModel model;
QFETCH(QString, dirtyQuery);
QFETCH(QString, clearQuery);
model.removeCommentsFromQuery(dirtyQuery);
QCOMPARE(dirtyQuery, clearQuery);
}