From: Manuel Nickschas Date: Mon, 24 Sep 2018 18:42:51 +0000 (+0200) Subject: tests: Convert ExpressionMatchTests into a GTest-based test case X-Git-Tag: test-travis-01~120 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=ed5b2ff32158ae72c011eb1228f373cec05cbfeb;hp=8f2ee00f4edef1693628d3af0bdee84d725eb754 tests: Convert ExpressionMatchTests into a GTest-based test case As first contender for the newly introduced test framework, use the recently added ExpressionMatchTests class. Convert to use GTest, and move into the new home for Quassel unit tests (the tests// directory). With this, "make test" (or "ninja test") actually does something if Quassel is configured with -DBUILD_TESTING=ON. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 413c46d0..c0e89bab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -530,3 +530,8 @@ feature_summary(WHAT ALL ##################################################################### add_subdirectory(src) + +# Build tests if so desired +if (BUILD_TESTING) + add_subdirectory(tests) +endif() diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 90f64e9a..e7d72644 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -17,7 +17,6 @@ target_sources(${TARGET} PRIVATE event.cpp eventmanager.cpp expressionmatch.cpp - # expressionmatchtests.cpp funchelpers.h highlightrulemanager.cpp identity.cpp diff --git a/src/common/expressionmatchtests.h b/src/common/expressionmatchtests.h deleted file mode 100644 index 59639147..00000000 --- a/src/common/expressionmatchtests.h +++ /dev/null @@ -1,87 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * - * devel@quassel-irc.org * - * * - * This program 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 2 of the License, or * - * (at your option) version 3. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#pragma once - -#include -#include - -/** - * Expression matcher test runner (temporary measure until switching to a real test framework) - */ -class ExpressionMatchTests -{ - -public: - /** - * Runs the ExpressionMatch tests - * - * Q_ASSERT will deliberately halt execution if an issue is found. This should not be called - * outside of a development environment. - * - * Recommended development usage until a testing framework exists: - * 1. Include "expressionmatchtests.h" in quassel.cpp - * 2. Call this function near the end of Quassel::init() - */ - static void runTests(); - -private: - // Disallow creating an instance of this static object - /** - * Construct a ExpressionMatchTests instance - */ - ExpressionMatchTests() {} - - /** - * Tests ExpressionMatch empty pattern handling - */ - static void runTestsEmptyPattern(); - - /** - * Tests ExpressionMatch MatchMode::Phrase - */ - static void runTestsMatchPhrase(); - - /** - * Tests ExpressionMatch MatchMode::MultiPhrase - */ - static void runTestsMatchMultiPhrase(); - - /** - * Tests ExpressionMatch MatchMode::Wildcard - */ - static void runTestsMatchWildcard(); - - /** - * Tests ExpressionMatch MatchMode::MultiWildcard - */ - static void runTestsMatchMultiWildcard(); - - /** - * Tests ExpressionMatch MatchMode::RegEx - */ - static void runTestsMatchRegEx(); - - /** - * Tests ExpressionMatch MultiWildcard whitespace trimming - */ - static void runTestsTrimMultiWildcardWhitespace(); - -}; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..e4717b2d --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(common) diff --git a/tests/common/CMakeLists.txt b/tests/common/CMakeLists.txt new file mode 100644 index 00000000..f3069371 --- /dev/null +++ b/tests/common/CMakeLists.txt @@ -0,0 +1 @@ +quassel_add_test(ExpressionMatchTest) diff --git a/src/common/expressionmatchtests.cpp b/tests/common/expressionmatchtest.cpp similarity index 55% rename from src/common/expressionmatchtests.cpp rename to tests/common/expressionmatchtest.cpp index e2287b29..a63b4dde 100644 --- a/src/common/expressionmatchtests.cpp +++ b/tests/common/expressionmatchtest.cpp @@ -18,56 +18,32 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include "expressionmatchtests.h" +#include -#include #include #include -#include +#include "testglobal.h" #include "expressionmatch.h" -void ExpressionMatchTests::runTests() +TEST(ExpressionMatchTest, emptyPattern) { - // Run all tests - qDebug() << "Running all ExpressionMatch tests"; - runTestsEmptyPattern(); - runTestsMatchPhrase(); - runTestsMatchMultiPhrase(); - runTestsMatchWildcard(); - runTestsMatchMultiWildcard(); - runTestsMatchRegEx(); - runTestsTrimMultiWildcardWhitespace(); - - qDebug() << "Passed all ExpressionMatch tests"; -} - - -void ExpressionMatchTests::runTestsEmptyPattern() -{ - qDebug() << "> Testing ExpressionMatch empty pattern handling"; - // Empty pattern ExpressionMatch emptyMatch = ExpressionMatch("", ExpressionMatch::MatchMode::MatchPhrase, false); + // Assert empty is valid + ASSERT_TRUE(emptyMatch.isValid()); // Assert empty - Q_ASSERT(emptyMatch.isEmpty()); + EXPECT_TRUE(emptyMatch.isEmpty()); // Assert default match fails (same as setting match empty to false) - Q_ASSERT(!emptyMatch.match("something")); + EXPECT_FALSE(emptyMatch.match("something")); // Assert match empty succeeds - Q_ASSERT(emptyMatch.match("something", true)); - // Assert empty is valid - Q_ASSERT(emptyMatch.isValid()); - - qDebug() << "* Passed ExpressionMatch empty pattern handling"; + EXPECT_TRUE(emptyMatch.match("something", true)); } - -void ExpressionMatchTests::runTestsMatchPhrase() +TEST(ExpressionMatchTest, matchPhrase) { - qDebug() << "> Testing ExpressionMatch phrase matching"; - // Simple phrase, case-insensitive ExpressionMatch simpleMatch = ExpressionMatch("test", ExpressionMatch::MatchMode::MatchPhrase, false); @@ -84,45 +60,40 @@ void ExpressionMatchTests::runTestsMatchPhrase() ExpressionMatch complexMatch = ExpressionMatch(complexMatchFull, ExpressionMatch::MatchMode::MatchPhrase, false); - // Assert valid and not empty - Q_ASSERT(!simpleMatch.isEmpty()); - Q_ASSERT(simpleMatch.isValid()); - Q_ASSERT(!simpleMatchCS.isEmpty()); - Q_ASSERT(simpleMatchCS.isValid()); - Q_ASSERT(!simpleMatchSpace.isEmpty()); - Q_ASSERT(simpleMatchSpace.isValid()); - Q_ASSERT(!complexMatch.isEmpty()); - Q_ASSERT(complexMatch.isValid()); + ASSERT_TRUE(simpleMatch.isValid()); + EXPECT_FALSE(simpleMatch.isEmpty()); + ASSERT_TRUE(simpleMatchCS.isValid()); + EXPECT_FALSE(simpleMatchCS.isEmpty()); + ASSERT_TRUE(simpleMatchSpace.isValid()); + EXPECT_FALSE(simpleMatchSpace.isEmpty()); + ASSERT_TRUE(complexMatch.isValid()); + EXPECT_FALSE(complexMatch.isEmpty()); // Assert match succeeds - Q_ASSERT(simpleMatch.match("test")); - Q_ASSERT(simpleMatch.match("other test;")); - Q_ASSERT(simpleMatchSpace.match(" space ")); + EXPECT_TRUE(simpleMatch.match("test")); + EXPECT_TRUE(simpleMatch.match("other test;")); + EXPECT_TRUE(simpleMatchSpace.match(" space ")); // Assert partial match fails - Q_ASSERT(!simpleMatch.match("testing")); - Q_ASSERT(!simpleMatchSpace.match("space")); + EXPECT_FALSE(simpleMatch.match("testing")); + EXPECT_FALSE(simpleMatchSpace.match("space")); // Assert unrelated fails - Q_ASSERT(!simpleMatch.match("not above")); + EXPECT_FALSE(simpleMatch.match("not above")); // Assert case sensitivity followed - Q_ASSERT(!simpleMatch.sourceCaseSensitive()); - Q_ASSERT(simpleMatch.match("TeSt")); - Q_ASSERT(simpleMatchCS.sourceCaseSensitive()); - Q_ASSERT(!simpleMatchCS.match("TeSt")); + EXPECT_FALSE(simpleMatch.sourceCaseSensitive()); + EXPECT_TRUE(simpleMatch.match("TeSt")); + EXPECT_TRUE(simpleMatchCS.sourceCaseSensitive()); + EXPECT_FALSE(simpleMatchCS.match("TeSt")); // Assert complex phrases are escaped properly - Q_ASSERT(complexMatch.match(complexMatchFull)); - Q_ASSERT(!complexMatch.match("norm")); - - qDebug() << "* Passed ExpressionMatch phrase matching"; + EXPECT_TRUE(complexMatch.match(complexMatchFull)); + EXPECT_FALSE(complexMatch.match("norm")); } -void ExpressionMatchTests::runTestsMatchMultiPhrase() +TEST(ExpressionMatchTest, matchMultiPhrase) { - qDebug() << "> Testing ExpressionMatch multiple phrase matching"; - // Simple phrases, case-insensitive ExpressionMatch simpleMatch = ExpressionMatch("test\nOther ", ExpressionMatch::MatchMode::MatchMultiPhrase, false); @@ -138,47 +109,42 @@ void ExpressionMatchTests::runTestsMatchMultiPhrase() ExpressionMatch(complexMatchFullA + "\n" + complexMatchFullB, ExpressionMatch::MatchMode::MatchMultiPhrase, false); - // Assert valid and not empty - Q_ASSERT(!simpleMatch.isEmpty()); - Q_ASSERT(simpleMatch.isValid()); - Q_ASSERT(!simpleMatchCS.isEmpty()); - Q_ASSERT(simpleMatchCS.isValid()); - Q_ASSERT(!complexMatch.isEmpty()); - Q_ASSERT(complexMatch.isValid()); + ASSERT_TRUE(simpleMatch.isValid()); + EXPECT_FALSE(simpleMatch.isEmpty()); + ASSERT_TRUE(simpleMatchCS.isValid()); + EXPECT_FALSE(simpleMatchCS.isEmpty()); + ASSERT_TRUE(complexMatch.isValid()); + EXPECT_FALSE(complexMatch.isEmpty()); // Assert match succeeds - Q_ASSERT(simpleMatch.match("test")); - Q_ASSERT(simpleMatch.match("test[suffix]")); - Q_ASSERT(simpleMatch.match("other test;")); - Q_ASSERT(simpleMatch.match("Other ")); - Q_ASSERT(simpleMatch.match(".Other !")); + EXPECT_TRUE(simpleMatch.match("test")); + EXPECT_TRUE(simpleMatch.match("test[suffix]")); + EXPECT_TRUE(simpleMatch.match("other test;")); + EXPECT_TRUE(simpleMatch.match("Other ")); + EXPECT_TRUE(simpleMatch.match(".Other !")); // Assert partial match fails - Q_ASSERT(!simpleMatch.match("testing")); - Q_ASSERT(!simpleMatch.match("Other!")); + EXPECT_FALSE(simpleMatch.match("testing")); + EXPECT_FALSE(simpleMatch.match("Other!")); // Assert unrelated fails - Q_ASSERT(!simpleMatch.match("not above")); + EXPECT_FALSE(simpleMatch.match("not above")); // Assert case sensitivity followed - Q_ASSERT(!simpleMatch.sourceCaseSensitive()); - Q_ASSERT(simpleMatch.match("TeSt")); - Q_ASSERT(simpleMatchCS.sourceCaseSensitive()); - Q_ASSERT(!simpleMatchCS.match("TeSt")); + EXPECT_FALSE(simpleMatch.sourceCaseSensitive()); + EXPECT_TRUE(simpleMatch.match("TeSt")); + EXPECT_TRUE(simpleMatchCS.sourceCaseSensitive()); + EXPECT_FALSE(simpleMatchCS.match("TeSt")); // Assert complex phrases are escaped properly - Q_ASSERT(complexMatch.match(complexMatchFullA)); - Q_ASSERT(complexMatch.match(complexMatchFullB)); - Q_ASSERT(!complexMatch.match("norm")); - Q_ASSERT(!complexMatch.match("invert")); - - qDebug() << "* Passed ExpressionMatch multiple phrase matching"; + EXPECT_TRUE(complexMatch.match(complexMatchFullA)); + EXPECT_TRUE(complexMatch.match(complexMatchFullB)); + EXPECT_FALSE(complexMatch.match("norm")); + EXPECT_FALSE(complexMatch.match("invert")); } -void ExpressionMatchTests::runTestsMatchWildcard() +TEST(ExpressionMatchTest, matchWildcard) { - qDebug() << "> Testing ExpressionMatch wildcard matching"; - // Simple wildcard, case-insensitive ExpressionMatch simpleMatch = ExpressionMatch("?test*", ExpressionMatch::MatchMode::MatchWildcard, false); @@ -202,66 +168,61 @@ void ExpressionMatchTests::runTestsMatchWildcard() ExpressionMatch(R"(never?gonna*give\*you\?up\\test|y\yeah\\1\\\\2\\\1inval)", ExpressionMatch::MatchMode::MatchWildcard, false); - // Assert valid and not empty - Q_ASSERT(!simpleMatch.isEmpty()); - Q_ASSERT(simpleMatch.isValid()); - Q_ASSERT(!simpleMatchCS.isEmpty()); - Q_ASSERT(simpleMatchCS.isValid()); - Q_ASSERT(!simpleMatchEscape.isEmpty()); - Q_ASSERT(simpleMatchEscape.isValid()); - Q_ASSERT(!simpleMatchInvert.isEmpty()); - Q_ASSERT(simpleMatchInvert.isValid()); - Q_ASSERT(!simpleMatchNoInvert.isEmpty()); - Q_ASSERT(simpleMatchNoInvert.isValid()); - Q_ASSERT(!simpleMatchNoInvertSlash.isEmpty()); - Q_ASSERT(simpleMatchNoInvertSlash.isValid()); - Q_ASSERT(!complexMatch.isEmpty()); - Q_ASSERT(complexMatch.isValid()); + ASSERT_TRUE(simpleMatch.isValid()); + EXPECT_FALSE(simpleMatch.isEmpty()); + ASSERT_TRUE(simpleMatchCS.isValid()); + EXPECT_FALSE(simpleMatchCS.isEmpty()); + ASSERT_TRUE(simpleMatchEscape.isValid()); + EXPECT_FALSE(simpleMatchEscape.isEmpty()); + ASSERT_TRUE(simpleMatchInvert.isValid()); + EXPECT_FALSE(simpleMatchInvert.isEmpty()); + ASSERT_TRUE(simpleMatchNoInvert.isValid()); + EXPECT_FALSE(simpleMatchNoInvert.isEmpty()); + ASSERT_TRUE(simpleMatchNoInvertSlash.isValid()); + EXPECT_FALSE(simpleMatchNoInvertSlash.isEmpty()); + ASSERT_TRUE(complexMatch.isValid()); + EXPECT_FALSE(complexMatch.isEmpty()); // Assert match succeeds - Q_ASSERT(simpleMatch.match("@test")); - Q_ASSERT(simpleMatch.match("@testing")); - Q_ASSERT(simpleMatch.match("!test")); - Q_ASSERT(simpleMatchEscape.match("?test*")); - Q_ASSERT(simpleMatchInvert.match("atest")); - Q_ASSERT(simpleMatchNoInvert.match("!test")); - Q_ASSERT(simpleMatchNoInvertSlash.match(R"(\!test)")); + EXPECT_TRUE(simpleMatch.match("@test")); + EXPECT_TRUE(simpleMatch.match("@testing")); + EXPECT_TRUE(simpleMatch.match("!test")); + EXPECT_TRUE(simpleMatchEscape.match("?test*")); + EXPECT_TRUE(simpleMatchInvert.match("atest")); + EXPECT_TRUE(simpleMatchNoInvert.match("!test")); + EXPECT_TRUE(simpleMatchNoInvertSlash.match(R"(\!test)")); // Assert partial match fails - Q_ASSERT(!simpleMatch.match("test")); + EXPECT_FALSE(simpleMatch.match("test")); // Assert unrelated fails - Q_ASSERT(!simpleMatch.match("not above")); + EXPECT_FALSE(simpleMatch.match("not above")); // Assert escaped wildcard fails - Q_ASSERT(!simpleMatchEscape.match("@testing")); - Q_ASSERT(!simpleMatchNoInvert.match("test")); - Q_ASSERT(!simpleMatchNoInvert.match("anything")); - Q_ASSERT(!simpleMatchNoInvertSlash.match("!test")); - Q_ASSERT(!simpleMatchNoInvertSlash.match("test")); - Q_ASSERT(!simpleMatchNoInvertSlash.match("anything")); + EXPECT_FALSE(simpleMatchEscape.match("@testing")); + EXPECT_FALSE(simpleMatchNoInvert.match("test")); + EXPECT_FALSE(simpleMatchNoInvert.match("anything")); + EXPECT_FALSE(simpleMatchNoInvertSlash.match("!test")); + EXPECT_FALSE(simpleMatchNoInvertSlash.match("test")); + EXPECT_FALSE(simpleMatchNoInvertSlash.match("anything")); // Assert non-inverted fails - Q_ASSERT(!simpleMatchInvert.match("testing")); + EXPECT_FALSE(simpleMatchInvert.match("testing")); // Assert case sensitivity followed - Q_ASSERT(!simpleMatch.sourceCaseSensitive()); - Q_ASSERT(simpleMatch.match("@TeSt")); - Q_ASSERT(simpleMatchCS.sourceCaseSensitive()); - Q_ASSERT(!simpleMatchCS.match("@TeSt")); + EXPECT_FALSE(simpleMatch.sourceCaseSensitive()); + EXPECT_TRUE(simpleMatch.match("@TeSt")); + EXPECT_TRUE(simpleMatchCS.sourceCaseSensitive()); + EXPECT_FALSE(simpleMatchCS.match("@TeSt")); // Assert complex match - Q_ASSERT(complexMatch.match(R"(neverAgonnaBBBgive*you?up\test|yyeah\1\\2\1inval)")); + EXPECT_TRUE(complexMatch.match(R"(neverAgonnaBBBgive*you?up\test|yyeah\1\\2\1inval)")); // Assert complex not literal match - Q_ASSERT(!complexMatch.match(R"(never?gonna*give\*you\?up\\test|y\yeah\\1\\\\2\\\1inval)")); + EXPECT_FALSE(complexMatch.match(R"(never?gonna*give\*you\?up\\test|y\yeah\\1\\\\2\\\1inval)")); // Assert complex unrelated not match - Q_ASSERT(!complexMatch.match("other")); - - qDebug() << "* Passed ExpressionMatch wildcard matching"; + EXPECT_FALSE(complexMatch.match("other")); } -void ExpressionMatchTests::runTestsMatchMultiWildcard() +TEST(ExpressionMatchTest, matchMultiWildcard) { - qDebug() << "> Testing ExpressionMatch multiple wildcard matching"; - // Simple wildcards, case-insensitive ExpressionMatch simpleMatch = ExpressionMatch("?test*;another?", @@ -311,74 +272,69 @@ void ExpressionMatchTests::runTestsMatchMultiWildcard() ExpressionMatch(complexMatchFull, ExpressionMatch::MatchMode::MatchMultiWildcard, false); - // Assert valid and not empty - Q_ASSERT(!simpleMatch.isEmpty()); - Q_ASSERT(simpleMatch.isValid()); - Q_ASSERT(!simpleMatchCS.isEmpty()); - Q_ASSERT(simpleMatchCS.isValid()); - Q_ASSERT(!simpleMatchEscape.isEmpty()); - Q_ASSERT(simpleMatchEscape.isValid()); - Q_ASSERT(!simpleMatchInvert.isEmpty()); - Q_ASSERT(simpleMatchInvert.isValid()); - Q_ASSERT(!simpleMatchImplicit.isEmpty()); - Q_ASSERT(simpleMatchImplicit.isValid()); - Q_ASSERT(!complexMatch.isEmpty()); - Q_ASSERT(complexMatch.isValid()); + ASSERT_TRUE(simpleMatch.isValid()); + EXPECT_FALSE(simpleMatch.isEmpty()); + ASSERT_TRUE(simpleMatchCS.isValid()); + EXPECT_FALSE(simpleMatchCS.isEmpty()); + ASSERT_TRUE(simpleMatchEscape.isValid()); + EXPECT_FALSE(simpleMatchEscape.isEmpty()); + ASSERT_TRUE(simpleMatchInvert.isValid()); + EXPECT_FALSE(simpleMatchInvert.isEmpty()); + ASSERT_TRUE(simpleMatchImplicit.isValid()); + EXPECT_FALSE(simpleMatchImplicit.isEmpty()); + ASSERT_TRUE(complexMatch.isValid()); + EXPECT_FALSE(complexMatch.isEmpty()); // Assert match succeeds - Q_ASSERT(simpleMatch.match("@test")); - Q_ASSERT(simpleMatch.match("@testing")); - Q_ASSERT(simpleMatch.match("!test")); - Q_ASSERT(simpleMatch.match("anotherA")); - Q_ASSERT(simpleMatchEscape.match("?test*;thing*")); - Q_ASSERT(simpleMatchEscape.match("?test*;AAAAAthing*")); - Q_ASSERT(simpleMatchInvert.match("test")); - Q_ASSERT(simpleMatchInvert.match("testing things")); + EXPECT_TRUE(simpleMatch.match("@test")); + EXPECT_TRUE(simpleMatch.match("@testing")); + EXPECT_TRUE(simpleMatch.match("!test")); + EXPECT_TRUE(simpleMatch.match("anotherA")); + EXPECT_TRUE(simpleMatchEscape.match("?test*;thing*")); + EXPECT_TRUE(simpleMatchEscape.match("?test*;AAAAAthing*")); + EXPECT_TRUE(simpleMatchInvert.match("test")); + EXPECT_TRUE(simpleMatchInvert.match("testing things")); // Assert implicit wildcard succeeds - Q_ASSERT(simpleMatchImplicit.match("AAAAAA")); + EXPECT_TRUE(simpleMatchImplicit.match("AAAAAA")); // Assert partial match fails - Q_ASSERT(!simpleMatch.match("test")); - Q_ASSERT(!simpleMatch.match("another")); - Q_ASSERT(!simpleMatch.match("anotherBB")); + EXPECT_FALSE(simpleMatch.match("test")); + EXPECT_FALSE(simpleMatch.match("another")); + EXPECT_FALSE(simpleMatch.match("anotherBB")); // Assert unrelated fails - Q_ASSERT(!simpleMatch.match("not above")); + EXPECT_FALSE(simpleMatch.match("not above")); // Assert escaped wildcard fails - Q_ASSERT(!simpleMatchEscape.match("@testing")); + EXPECT_FALSE(simpleMatchEscape.match("@testing")); // Assert inverted match fails - Q_ASSERT(!simpleMatchInvert.match("testing")); - Q_ASSERT(!simpleMatchImplicit.match("testing")); + EXPECT_FALSE(simpleMatchInvert.match("testing")); + EXPECT_FALSE(simpleMatchImplicit.match("testing")); // Assert case sensitivity followed - Q_ASSERT(!simpleMatch.sourceCaseSensitive()); - Q_ASSERT(simpleMatch.match("@TeSt")); - Q_ASSERT(simpleMatchCS.sourceCaseSensitive()); - Q_ASSERT(!simpleMatchCS.match("@TeSt")); + EXPECT_FALSE(simpleMatch.sourceCaseSensitive()); + EXPECT_TRUE(simpleMatch.match("@TeSt")); + EXPECT_TRUE(simpleMatchCS.sourceCaseSensitive()); + EXPECT_FALSE(simpleMatchCS.match("@TeSt")); // Assert complex match for (auto&& normMatch : complexMatchNormal) { // Each normal component should match - Q_ASSERT(complexMatch.match(normMatch)); + EXPECT_TRUE(complexMatch.match(normMatch)); } for (auto&& invertMatch : complexMatchInvert) { // Each invert component should not match - Q_ASSERT(!complexMatch.match(invertMatch)); + EXPECT_FALSE(complexMatch.match(invertMatch)); } // Assert complex not literal match - Q_ASSERT(!complexMatch.match(complexMatchFull)); + EXPECT_FALSE(complexMatch.match(complexMatchFull)); // Assert complex unrelated not match - Q_ASSERT(!complexMatch.match("other")); - - qDebug() << "* Passed ExpressionMatch multiple wildcard matching"; + EXPECT_FALSE(complexMatch.match("other")); } -void ExpressionMatchTests::runTestsMatchRegEx() +TEST(ExpressionMatchTest, matchRegEx) { - qDebug() << "> Testing ExpressionMatch regex matching"; - // Simple regex, case-insensitive ExpressionMatch simpleMatch = ExpressionMatch(R"(simple.\*escape-match.*)", @@ -401,52 +357,48 @@ void ExpressionMatchTests::runTestsMatchRegEx() ExpressionMatch::MatchMode::MatchRegEx, false); // Assert valid and not empty - Q_ASSERT(!simpleMatch.isEmpty()); - Q_ASSERT(simpleMatch.isValid()); - Q_ASSERT(!simpleMatchCS.isEmpty()); - Q_ASSERT(simpleMatchCS.isValid()); - Q_ASSERT(!simpleMatchInvert.isEmpty()); - Q_ASSERT(simpleMatchInvert.isValid()); - Q_ASSERT(!simpleMatchNoInvert.isEmpty()); - Q_ASSERT(simpleMatchNoInvert.isValid()); - Q_ASSERT(!simpleMatchNoInvertSlash.isEmpty()); - Q_ASSERT(simpleMatchNoInvertSlash.isValid()); + ASSERT_TRUE(simpleMatch.isValid()); + EXPECT_FALSE(simpleMatch.isEmpty()); + ASSERT_TRUE(simpleMatchCS.isValid()); + EXPECT_FALSE(simpleMatchCS.isEmpty()); + ASSERT_TRUE(simpleMatchInvert.isValid()); + EXPECT_FALSE(simpleMatchInvert.isEmpty()); + ASSERT_TRUE(simpleMatchNoInvert.isValid()); + EXPECT_FALSE(simpleMatchNoInvert.isEmpty()); + ASSERT_TRUE(simpleMatchNoInvertSlash.isValid()); + EXPECT_FALSE(simpleMatchNoInvertSlash.isEmpty()); // Assert match succeeds - Q_ASSERT(simpleMatch.match("simpleA*escape-match")); - Q_ASSERT(simpleMatch.match("simpleA*escape-matchBBBB")); - Q_ASSERT(simpleMatchInvert.match("not above")); - Q_ASSERT(simpleMatchNoInvert.match("!simpleA*escape-matchBBBB")); - Q_ASSERT(simpleMatchNoInvertSlash.match(R"(\!simpleA*escape-matchBBBB)")); + EXPECT_TRUE(simpleMatch.match("simpleA*escape-match")); + EXPECT_TRUE(simpleMatch.match("simpleA*escape-matchBBBB")); + EXPECT_TRUE(simpleMatchInvert.match("not above")); + EXPECT_TRUE(simpleMatchNoInvert.match("!simpleA*escape-matchBBBB")); + EXPECT_TRUE(simpleMatchNoInvertSlash.match(R"(\!simpleA*escape-matchBBBB)")); // Assert partial match fails - Q_ASSERT(!simpleMatch.match("simpleA*escape-mat")); - Q_ASSERT(!simpleMatch.match("simple*escape-match")); + EXPECT_FALSE(simpleMatch.match("simpleA*escape-mat")); + EXPECT_FALSE(simpleMatch.match("simple*escape-match")); // Assert unrelated fails - Q_ASSERT(!simpleMatch.match("not above")); + EXPECT_FALSE(simpleMatch.match("not above")); // Assert escaped wildcard fails - Q_ASSERT(!simpleMatch.match("simpleABBBBescape-matchBBBB")); + EXPECT_FALSE(simpleMatch.match("simpleABBBBescape-matchBBBB")); // Assert inverted fails - Q_ASSERT(!simpleMatchInvert.match("invertA*escape-match")); - Q_ASSERT(!simpleMatchInvert.match("invertA*escape-matchBBBB")); - Q_ASSERT(!simpleMatchNoInvert.match("simpleA*escape-matchBBBB")); - Q_ASSERT(!simpleMatchNoInvert.match("anything")); - Q_ASSERT(!simpleMatchNoInvertSlash.match("!simpleA*escape-matchBBBB")); - Q_ASSERT(!simpleMatchNoInvertSlash.match("anything")); + EXPECT_FALSE(simpleMatchInvert.match("invertA*escape-match")); + EXPECT_FALSE(simpleMatchInvert.match("invertA*escape-matchBBBB")); + EXPECT_FALSE(simpleMatchNoInvert.match("simpleA*escape-matchBBBB")); + EXPECT_FALSE(simpleMatchNoInvert.match("anything")); + EXPECT_FALSE(simpleMatchNoInvertSlash.match("!simpleA*escape-matchBBBB")); + EXPECT_FALSE(simpleMatchNoInvertSlash.match("anything")); // Assert case sensitivity followed - Q_ASSERT(!simpleMatch.sourceCaseSensitive()); - Q_ASSERT(simpleMatch.match("SiMpLEA*escape-MATCH")); - Q_ASSERT(simpleMatchCS.sourceCaseSensitive()); - Q_ASSERT(!simpleMatchCS.match("SiMpLEA*escape-MATCH")); - - qDebug() << "* Passed ExpressionMatch regex matching"; + EXPECT_FALSE(simpleMatch.sourceCaseSensitive()); + EXPECT_TRUE(simpleMatch.match("SiMpLEA*escape-MATCH")); + EXPECT_TRUE(simpleMatchCS.sourceCaseSensitive()); + EXPECT_FALSE(simpleMatchCS.match("SiMpLEA*escape-MATCH")); } -void ExpressionMatchTests::runTestsTrimMultiWildcardWhitespace() +TEST(ExpressionMatchTest, trimMultiWildcardWhitespace) { - qDebug() << "> Testing ExpressionMatch multiple wildcard whitespace trimming"; - // Patterns static constexpr uint PATTERN_SOURCE = 0; static constexpr uint PATTERN_RESULT = 1; @@ -473,14 +425,12 @@ void ExpressionMatchTests::runTestsTrimMultiWildcardWhitespace() QString result; for (auto&& patternPair : patterns) { // Make sure data is valid - Q_ASSERT(patternPair.size() == 2); + EXPECT_TRUE(patternPair.size() == 2); // Run transformation result = ExpressionMatch::trimMultiWildcardWhitespace(patternPair[PATTERN_SOURCE]); // Assert that source trims into expected pattern - Q_ASSERT(result == patternPair[PATTERN_RESULT]); + EXPECT_EQ(patternPair[PATTERN_RESULT], result); // Assert that re-trimming expected pattern gives the same result - Q_ASSERT(result == ExpressionMatch::trimMultiWildcardWhitespace(result)); + EXPECT_EQ(ExpressionMatch::trimMultiWildcardWhitespace(result), result); } - - qDebug() << "* Passed ExpressionMatch multiple wildcard whitespace trimming"; }