mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 00:24:47 -07:00
Filter Strings for Deck Editor search (#3582)
* Add MagicCards.info like fitler parser. * Use FilterString whenever one of [:=<>] is in the edit box. * Opts * Opt * - Capture errors - Allow querying any property by full name * clang format * Update cockatrice/src/filter_string.cpp Co-Authored-By: basicer <basicer@basicer.com> * - Some refactoring for clarity - More filters - Add filter help * Clangify * Add icon * Fix test name * Remove stay debug * - Add Rarity filter - Make " trigger filter string mode * You have to pass both filter types * clangify * - Allow filtering by legality - Import legality into card.xml * Add format filter to filtertree * More color search options * RIP extended * More fixes * Fix c:m * set syntax help parent * Fix warning * add additional explanations to syntax help * Allow multiple ands/ors to be chained * Cleanup and refactor Signed-off-by: Zach Halpern <ZaHalpern+github@gmail.com> * Move utility into guards Signed-off-by: Zach Halpern <ZaHalpern+github@gmail.com> * I heard you like refactors so I put a refactor inside your refactor (#3594) * I heard you like refactors so I put a refactor inside your refactor so you can refactor while you refactor * clangify * Update tab_deck_editor.h
This commit is contained in:
parent
4427ad1451
commit
eb60fec8e2
24 changed files with 780 additions and 122 deletions
|
|
@ -1,6 +1,18 @@
|
|||
ADD_DEFINITIONS("-DCARDDB_DATADIR=\"${CMAKE_CURRENT_SOURCE_DIR}/data/\"")
|
||||
add_executable(carddatabase_test
|
||||
carddatabase_test.cpp
|
||||
mocks.cpp
|
||||
../../cockatrice/src/carddatabase.cpp
|
||||
../../cockatrice/src/carddbparser/carddatabaseparser.cpp
|
||||
../../cockatrice/src/carddbparser/cockatricexml3.cpp
|
||||
../../cockatrice/src/carddbparser/cockatricexml4.cpp
|
||||
)
|
||||
add_executable(filter_string_test
|
||||
filter_string_test.cpp
|
||||
mocks.cpp
|
||||
../../cockatrice/src/filter_string.cpp
|
||||
../../cockatrice/src/cardfilter.cpp
|
||||
../../cockatrice/src/filtertree.cpp
|
||||
../../cockatrice/src/carddatabase.cpp
|
||||
../../cockatrice/src/carddbparser/carddatabaseparser.cpp
|
||||
../../cockatrice/src/carddbparser/cockatricexml3.cpp
|
||||
|
|
@ -8,10 +20,15 @@ add_executable(carddatabase_test
|
|||
)
|
||||
if(NOT GTEST_FOUND)
|
||||
add_dependencies(carddatabase_test gtest)
|
||||
add_dependencies(filter_string_test gtest)
|
||||
endif()
|
||||
|
||||
find_package(Qt5 COMPONENTS Concurrent Network Widgets REQUIRED)
|
||||
set(TEST_QT_MODULES Qt5::Concurrent Qt5::Network Qt5::Widgets)
|
||||
find_package(Qt5 COMPONENTS Concurrent Network Widgets Svg REQUIRED)
|
||||
set(TEST_QT_MODULES Qt5::Concurrent Qt5::Network Qt5::Widgets Qt5::Svg)
|
||||
|
||||
target_link_libraries(carddatabase_test ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES})
|
||||
add_test(NAME carddatabase_test COMMAND carddatabase_test)
|
||||
target_link_libraries(filter_string_test ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES})
|
||||
|
||||
|
||||
add_test(NAME carddatabase_test COMMAND carddatabase_test)
|
||||
add_test(NAME filter_string_test COMMAND filter_string_test)
|
||||
|
|
@ -1,57 +1,6 @@
|
|||
#include "gtest/gtest.h"
|
||||
|
||||
#include "carddatabase_test.h"
|
||||
|
||||
void CardDatabaseSettings::setSortKey(QString /* shortName */, unsigned int /* sortKey */){};
|
||||
void CardDatabaseSettings::setEnabled(QString /* shortName */, bool /* enabled */){};
|
||||
void CardDatabaseSettings::setIsKnown(QString /* shortName */, bool /* isknown */){};
|
||||
unsigned int CardDatabaseSettings::getSortKey(QString /* shortName */)
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
bool CardDatabaseSettings::isEnabled(QString /* shortName */)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
bool CardDatabaseSettings::isKnown(QString /* shortName */)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
SettingsCache::SettingsCache()
|
||||
{
|
||||
cardDatabaseSettings = new CardDatabaseSettings();
|
||||
};
|
||||
SettingsCache::~SettingsCache()
|
||||
{
|
||||
delete cardDatabaseSettings;
|
||||
};
|
||||
QString SettingsCache::getCustomCardDatabasePath() const
|
||||
{
|
||||
return QString("%1/customsets/").arg(CARDDB_DATADIR);
|
||||
}
|
||||
QString SettingsCache::getCardDatabasePath() const
|
||||
{
|
||||
return QString("%1/cards.xml").arg(CARDDB_DATADIR);
|
||||
}
|
||||
QString SettingsCache::getTokenDatabasePath() const
|
||||
{
|
||||
return QString("%1/tokens.xml").arg(CARDDB_DATADIR);
|
||||
}
|
||||
QString SettingsCache::getSpoilerCardDatabasePath() const
|
||||
{
|
||||
return QString("%1/spoiler.xml").arg(CARDDB_DATADIR);
|
||||
}
|
||||
CardDatabaseSettings &SettingsCache::cardDatabase() const
|
||||
{
|
||||
return *cardDatabaseSettings;
|
||||
}
|
||||
|
||||
SettingsCache *settingsCache;
|
||||
|
||||
void PictureLoader::clearPixmapCache(CardInfoPtr /* card */)
|
||||
{
|
||||
}
|
||||
#include "mocks.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
|
|
|||
66
tests/carddatabase/filter_string_test.cpp
Normal file
66
tests/carddatabase/filter_string_test.cpp
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include "../cockatrice/src/filter_string.h"
|
||||
#include "mocks.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
CardDatabase *db;
|
||||
|
||||
#define Query(name, card, query, match) \
|
||||
TEST_F(CardQuery, name) {\
|
||||
ASSERT_EQ(FilterString(query).check(card), match);\
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
class CardQuery : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
cat = db->getCardBySimpleName("Cat");
|
||||
}
|
||||
|
||||
// void TearDown() override {}
|
||||
|
||||
CardData cat;
|
||||
};
|
||||
|
||||
Query(Empty, cat, "", true)
|
||||
Query(Typing, cat, "t", true)
|
||||
|
||||
Query(NonMatchingType, cat, "t:kithkin", false)
|
||||
Query(MatchingType, cat, "t:creature", true)
|
||||
Query(Not1, cat, "not t:kithkin", true)
|
||||
Query(Not2, cat, "not t:creature", false)
|
||||
Query(Case, cat, "t:cReAtUrE", true)
|
||||
|
||||
Query(And, cat, "t:creature t:creature", true)
|
||||
Query(And2, cat, "t:creature t:sorcery", false)
|
||||
|
||||
Query(Or, cat, "t:bat or t:creature", true)
|
||||
|
||||
Query(Cmc1, cat, "cmc=2", true)
|
||||
Query(Cmc2, cat, "cmc>3", false)
|
||||
Query(Cmc3, cat, "cmc>1", true)
|
||||
|
||||
Query(Quotes, cat, "t:\"creature\"", true);
|
||||
|
||||
Query(Field, cat, "pt:\"3/3\"", true)
|
||||
|
||||
Query(Color1, cat, "c:g", true);
|
||||
Query(Color2, cat, "c:gw", true);
|
||||
Query(Color3, cat, "c!g", true);
|
||||
Query(Color4, cat, "c!gw", false);
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
settingsCache = new SettingsCache;
|
||||
db = new CardDatabase;
|
||||
db->loadCardDatabases();
|
||||
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
54
tests/carddatabase/mocks.cpp
Normal file
54
tests/carddatabase/mocks.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
|
||||
#include "mocks.h"
|
||||
|
||||
void CardDatabaseSettings::setSortKey(QString /* shortName */, unsigned int /* sortKey */){};
|
||||
void CardDatabaseSettings::setEnabled(QString /* shortName */, bool /* enabled */){};
|
||||
void CardDatabaseSettings::setIsKnown(QString /* shortName */, bool /* isknown */){};
|
||||
unsigned int CardDatabaseSettings::getSortKey(QString /* shortName */)
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
bool CardDatabaseSettings::isEnabled(QString /* shortName */)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
bool CardDatabaseSettings::isKnown(QString /* shortName */)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
SettingsCache::SettingsCache()
|
||||
{
|
||||
cardDatabaseSettings = new CardDatabaseSettings();
|
||||
};
|
||||
SettingsCache::~SettingsCache()
|
||||
{
|
||||
delete cardDatabaseSettings;
|
||||
};
|
||||
QString SettingsCache::getCustomCardDatabasePath() const
|
||||
{
|
||||
return QString("%1/customsets/").arg(CARDDB_DATADIR);
|
||||
}
|
||||
QString SettingsCache::getCardDatabasePath() const
|
||||
{
|
||||
return QString("%1/cards.xml").arg(CARDDB_DATADIR);
|
||||
}
|
||||
QString SettingsCache::getTokenDatabasePath() const
|
||||
{
|
||||
return QString("%1/tokens.xml").arg(CARDDB_DATADIR);
|
||||
}
|
||||
QString SettingsCache::getSpoilerCardDatabasePath() const
|
||||
{
|
||||
return QString("%1/spoiler.xml").arg(CARDDB_DATADIR);
|
||||
}
|
||||
CardDatabaseSettings &SettingsCache::cardDatabase() const
|
||||
{
|
||||
return *cardDatabaseSettings;
|
||||
}
|
||||
|
||||
|
||||
void PictureLoader::clearPixmapCache(CardInfoPtr /* card */)
|
||||
{
|
||||
}
|
||||
|
||||
SettingsCache *settingsCache;
|
||||
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#define SETTINGSCACHE_H
|
||||
|
||||
|
||||
class CardDatabaseSettings
|
||||
{
|
||||
public:
|
||||
|
|
@ -40,6 +41,8 @@ signals:
|
|||
void cardDatabasePathChanged();
|
||||
};
|
||||
|
||||
extern SettingsCache *settingsCache;
|
||||
|
||||
#define PICTURELOADER_H
|
||||
|
||||
class PictureLoader
|
||||
Loading…
Add table
Add a link
Reference in a new issue