diff --git a/tests/loading_from_clipboard/clipboard_testing.cpp b/tests/loading_from_clipboard/clipboard_testing.cpp index ad8db3dbf..b2021bde5 100644 --- a/tests/loading_from_clipboard/clipboard_testing.cpp +++ b/tests/loading_from_clipboard/clipboard_testing.cpp @@ -2,17 +2,6 @@ #include -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); } diff --git a/tests/loading_from_clipboard/clipboard_testing.h b/tests/loading_from_clipboard/clipboard_testing.h index 272801126..00d73b636 100644 --- a/tests/loading_from_clipboard/clipboard_testing.h +++ b/tests/loading_from_clipboard/clipboard_testing.h @@ -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>; + 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::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);