* improve loading from plain text Fixes the loadFromStream_Plain function that is used to load plain text decklists. The rewritten function uses more regexes and is a bit cleaner. This fixes multiple bugs with loading the various sources of decklists. Note that the new function still has a few issues that are shared with the original version like creating duplicate cards. * clang format comments apparently clang-format even complains about the spacing in your comments * refactor loading_from_clipboard tests Remove all heap allocation and use references. Use std::pair and std::string so gtest will show the cardnames in error messages. (note that using QPair or QString does not work with gtest) Improve the last two testcases to include weird names; and name and comments testing. Remove empty header file. * fix compatibility with more formats skip "sideboard" line include everything in mainboard when there are multiple empty lines add removal of the mwdeck cardversion selector in round braces add replacal of lowercase ae combination that should never occur Set cardname to lowercase as apparently our checks are hardcoded to only accept lowercase. * remove bugged test The current load from plain is simply broken, removed checking the comments for correct contents. * rework load_from_clipboard tests again rework the test to have less code duplication add more tests and more special cases note that text is still all lowercase * improve loading from plain text Fixes the loadFromStream_Plain function that is used to load plain text decklists. The rewritten function uses more regexes and is a bit cleaner. This fixes multiple bugs with loading the various sources of decklists. Note that the new function still has a few issues that are shared with the original version like creating duplicate cards. * clang format comments apparently clang-format even complains about the spacing in your comments * refactor loading_from_clipboard tests Remove all heap allocation and use references. Use std::pair and std::string so gtest will show the cardnames in error messages. (note that using QPair or QString does not work with gtest) Improve the last two testcases to include weird names; and name and comments testing. Remove empty header file. * fix compatibility with more formats skip "sideboard" line include everything in mainboard when there are multiple empty lines add removal of the mwdeck cardversion selector in round braces add replacal of lowercase ae combination that should never occur Set cardname to lowercase as apparently our checks are hardcoded to only accept lowercase. * remove bugged test The current load from plain is simply broken, removed checking the comments for correct contents. * rework load_from_clipboard tests again rework the test to have less code duplication add more tests and more special cases note that text is still all lowercase * remove forcing of lowercase cardnames Cardnames in DeckList::loadFromStream_Plain will no longer be forced lowercase if they aren't found in the database. Empty lines in the comments of plaintext decklists will not be skipped. The loading_from_clipboard_test gets its functions declared in a separate header "clipboard_testing.h". Add more edgecase tests. Refactor code. * add old QHash version support QT 5.5 does not support using initializer lists for QHash. Implement a preprocessor version check for conditionally using inserts instead of a const with initializer list. * add old QHash version support QT 5.5 does not support using initializer lists for QHash. Implement a preprocessor version check for conditionally using [] access instead of a const with initializer list. * add qHash on QRegularExpression below QT 5.6 Apparently QRegularExpression can't be hashed in lower QT versions, so we add our own hash function, and everyone lived happily ever after, and none the wiser. * add header guards to clipboard_testing.h
172 lines
5.1 KiB
C++
172 lines
5.1 KiB
C++
#include "clipboard_testing.h"
|
||
|
||
// Testing is done by using the DeckList::loadFromString_Plain function in common/decklist.h
|
||
// It does not check if cards are in the database at all, so no comparisons to the database will be made.
|
||
|
||
TEST(LoadingFromClipboardTest, EmptyDeck)
|
||
{
|
||
testEmpty("");
|
||
}
|
||
|
||
TEST(LoadingFromClipboardTest, EmptySideboard)
|
||
{
|
||
testEmpty("Sideboard");
|
||
}
|
||
|
||
TEST(LoadingFromClipboardTest, QuantityPrefixed)
|
||
{
|
||
QString clipboard("1 Mountain\n"
|
||
"2x Island\n"
|
||
"3x Forest\n");
|
||
Result result("", "", {{"Mountain", 1}, {"Island", 2}, {"Forest", 3}}, {});
|
||
testDeck(clipboard, result);
|
||
}
|
||
|
||
TEST(LoadingFromClipboardTest, CommentsAreIgnored)
|
||
{
|
||
QString clipboard("//1 Mountain\n"
|
||
"//2x Island\n"
|
||
"//SB:2x Island\n");
|
||
testEmpty(clipboard);
|
||
}
|
||
|
||
TEST(LoadingFromClipboardTest, SideboardPrefix)
|
||
{
|
||
QString clipboard("1 Mountain\n"
|
||
"SB: 1 Mountain\n"
|
||
"sb: 2x Island\n"
|
||
"2 Swamp\n"
|
||
"\n"
|
||
"3 Plains\n");
|
||
Result result("", "", {{"Mountain", 1}, {"Swamp", 2}, {"Plains", 3}}, {{"Mountain", 1}, {"Island", 2}});
|
||
testDeck(clipboard, result);
|
||
}
|
||
|
||
TEST(LoadingFromClipboardTest, SideboardLine)
|
||
{
|
||
QString clipboard("1 Mountain\n"
|
||
"2 Swamp\n"
|
||
"\n"
|
||
"3 Plains\n"
|
||
"sideboard\n"
|
||
"1 Mountain\n"
|
||
"2x Island\n");
|
||
Result result("", "", {{"Mountain", 1}, {"Swamp", 2}, {"Plains", 3}}, {{"Mountain", 1}, {"Island", 2}});
|
||
testDeck(clipboard, result);
|
||
}
|
||
|
||
TEST(LoadingFromClipboardTest, UnknownCardsAreNotDiscarded)
|
||
{
|
||
QString clipboard("1 CardThatDoesNotExistInCardsXml\n");
|
||
Result result("", "", {{"CardThatDoesNotExistInCardsXml", 1}}, {});
|
||
testDeck(clipboard, result);
|
||
}
|
||
|
||
TEST(LoadingFromClipboardTest, WeirdWhitespaceIsIgnored)
|
||
{
|
||
QString clipboard(
|
||
"\t\tSb:\t1\tOur Market Research Shows That Players Like Really Long Card Names So We Made "
|
||
" This Card to Have\tthe Absolute \t Longest Card Name \tEver Elemental\t\n\t");
|
||
Result result("", "", {},
|
||
{{"Our Market Research Shows That Players Like Really Long Card Names So We Made This Card to Have "
|
||
"the Absolute Longest Card Name Ever Elemental",
|
||
1}});
|
||
testDeck(clipboard, result);
|
||
}
|
||
|
||
TEST(LoadingFromClipboardTest, RemoveBlankEntriesFromBeginningAndEnd)
|
||
{
|
||
QString clipboard("\n"
|
||
"\n"
|
||
"\n"
|
||
"1x Algae Gharial\n"
|
||
"3x CardThatDoesNotExistInCardsXml\n"
|
||
"2x Phelddagrif\n"
|
||
"\n"
|
||
"\n");
|
||
|
||
Result result("", "", {{"Algae Gharial", 1}, {"CardThatDoesNotExistInCardsXml", 3}, {"Phelddagrif", 2}}, {});
|
||
testDeck(clipboard, result);
|
||
}
|
||
|
||
TEST(LoadingFromClipboardTest, UseFirstBlankIfOnlyOneBlankToSplitSideboard)
|
||
{
|
||
QString clipboard("1x Algae Gharial\n"
|
||
"3x CardThatDoesNotExistInCardsXml\n"
|
||
"\n"
|
||
"2x Phelddagrif\n");
|
||
|
||
Result result("", "", {{"Algae Gharial", 1}, {"CardThatDoesNotExistInCardsXml", 3}}, {{"Phelddagrif", 2}});
|
||
testDeck(clipboard, result);
|
||
}
|
||
|
||
TEST(LoadingFromClipboardTest, IfMultipleScatteredBlanksAllMainBoard)
|
||
{
|
||
QString clipboard("1x Algae Gharial\n"
|
||
"3x CardThatDoesNotExistInCardsXml\n"
|
||
"\n"
|
||
"2x Phelddagrif\n"
|
||
"\n"
|
||
"3 Giant Growth\n");
|
||
|
||
Result result(
|
||
"", "", {{"Algae Gharial", 1}, {"CardThatDoesNotExistInCardsXml", 3}, {"Phelddagrif", 2}, {"Giant Growth", 3}},
|
||
{});
|
||
testDeck(clipboard, result);
|
||
}
|
||
|
||
TEST(LoadingFromClipboardTest, EdgeCaseTesting)
|
||
{
|
||
QString clipboard(R"(
|
||
// DeckName
|
||
|
||
// Comment 1
|
||
|
||
//
|
||
//Comment [two]
|
||
//(test) Æ ’ | / (3)
|
||
|
||
|
||
// Mainboard (10 cards)
|
||
Æther Adept
|
||
2x Fire & Ice
|
||
3 Pain/Suffering
|
||
4X [B] Forest (3)
|
||
|
||
|
||
// Sideboard (11 cards)
|
||
|
||
5x [WTH] Nature’s Resurgence
|
||
6X Gaea's Skyfolk
|
||
7 B.F.M. (Big Furry Monster)
|
||
|
||
|
||
|
||
)");
|
||
|
||
Result result("DeckName", "Comment 1\n\nComment [two]\n(test) Æ ’ | / (3)",
|
||
{{"Aether Adept", 1}, {"Fire // Ice", 2}, {"Pain // Suffering", 3}, {"Forest", 4}},
|
||
{{"Nature's Resurgence", 5}, {"Gaea's Skyfolk", 6}, {"B.F.M. (Big Furry Monster)", 7}});
|
||
testDeck(clipboard, result);
|
||
}
|
||
|
||
TEST(LoadingFromClipboardTest, CommentsBeforeCardsTesting)
|
||
{
|
||
QString clipboard("// Title from website.com\n"
|
||
"// A nice deck\n"
|
||
"// With nice cards\n"
|
||
"\n"
|
||
"// Mainboard\n"
|
||
"1 test1\n"
|
||
"Sideboard\n"
|
||
"2 test2\n");
|
||
|
||
Result result("Title from website.com", "A nice deck\nWith nice cards", {{"test1", 1}}, {{"test2", 2}});
|
||
testDeck(clipboard, result);
|
||
}
|
||
|
||
int main(int argc, char **argv)
|
||
{
|
||
::testing::InitGoogleTest(&argc, argv);
|
||
return RUN_ALL_TESTS();
|
||
}
|