mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-12 15:49:28 -08:00
Refactor function structs into lambdas (#5675)
* change signature to use lambda * reuse comparator * inline structs in forEachCard * inline structs * Refactor exportDeckToDecklist * fix unit test
This commit is contained in:
@@ -2,17 +2,6 @@
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
void Result::operator()(const InnerDecklistNode *innerDecklistNode, const DecklistCardNode *card)
|
||||
{
|
||||
if (innerDecklistNode->getName() == DECK_ZONE_MAIN) {
|
||||
mainboard.append({card->getName().toStdString(), card->getNumber()});
|
||||
} else if (innerDecklistNode->getName() == DECK_ZONE_SIDE) {
|
||||
sideboard.append({card->getName().toStdString(), card->getNumber()});
|
||||
} else {
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
|
||||
void testEmpty(const QString &clipboard)
|
||||
{
|
||||
QString cp(clipboard);
|
||||
@@ -33,9 +22,22 @@ void testDeck(const QString &clipboard, const Result &result)
|
||||
ASSERT_EQ(result.name, deckList.getName().toStdString());
|
||||
ASSERT_EQ(result.comments, deckList.getComments().toStdString());
|
||||
|
||||
Result decklistBuilder;
|
||||
deckList.forEachCard(decklistBuilder);
|
||||
CardRows mainboard;
|
||||
CardRows sideboard;
|
||||
|
||||
ASSERT_EQ(result.mainboard, decklistBuilder.mainboard);
|
||||
ASSERT_EQ(result.sideboard, decklistBuilder.sideboard);
|
||||
auto extractCards = [&mainboard, &sideboard](const InnerDecklistNode *innerDecklistNode,
|
||||
const DecklistCardNode *card) {
|
||||
if (innerDecklistNode->getName() == DECK_ZONE_MAIN) {
|
||||
mainboard.append({card->getName().toStdString(), card->getNumber()});
|
||||
} else if (innerDecklistNode->getName() == DECK_ZONE_SIDE) {
|
||||
sideboard.append({card->getName().toStdString(), card->getNumber()});
|
||||
} else {
|
||||
FAIL();
|
||||
}
|
||||
};
|
||||
|
||||
deckList.forEachCard(extractCards);
|
||||
|
||||
ASSERT_EQ(result.mainboard, mainboard);
|
||||
ASSERT_EQ(result.sideboard, sideboard);
|
||||
}
|
||||
|
||||
@@ -5,25 +5,20 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// using std types because qt types aren't understood by gtest (without this you'll get less nice errors)
|
||||
using CardRows = QVector<std::pair<std::string, int>>;
|
||||
|
||||
struct Result
|
||||
{
|
||||
// using std types because qt types aren't understood by gtest (without this you'll get less nice errors)
|
||||
using CardRows = QVector<std::pair<std::string, int>>;
|
||||
std::string name;
|
||||
std::string comments;
|
||||
CardRows mainboard;
|
||||
CardRows sideboard;
|
||||
|
||||
Result()
|
||||
{
|
||||
}
|
||||
|
||||
Result(std::string _name, std::string _comments, CardRows _mainboard, CardRows _sideboard)
|
||||
: name(_name), comments(_comments), mainboard(_mainboard), sideboard(_sideboard)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(const InnerDecklistNode *innerDecklistNode, const DecklistCardNode *card);
|
||||
};
|
||||
|
||||
void testEmpty(const QString &clipboard);
|
||||
|
||||
Reference in New Issue
Block a user