From 1c48656623e03e065d21d27a8bdfe1cfcdcaa71c Mon Sep 17 00:00:00 2001 From: ebbit1q Date: Fri, 2 Apr 2021 05:35:36 +0200 Subject: [PATCH] fix #4249 (#4285) ignore "deck" at start of a list add tests add tests to clangify.sh --- clangify.sh | 3 +- common/decklist.cpp | 14 +++++++- .../loading_from_clipboard_test.cpp | 33 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/clangify.sh b/clangify.sh index 238d3233..ac1ab1be 100755 --- a/clangify.sh +++ b/clangify.sh @@ -11,7 +11,8 @@ cd "${BASH_SOURCE%/*}/" || exit 2 # could not find path, this could happen with include=("common" \ "cockatrice/src" \ "oracle/src" \ -"servatrice/src") +"servatrice/src" \ +"tests") exclude=("servatrice/src/smtp" \ "common/sfmt" \ "common/lib" \ diff --git a/common/decklist.cpp b/common/decklist.cpp index e28084de..a1463d0c 100644 --- a/common/decklist.cpp +++ b/common/decklist.cpp @@ -492,7 +492,9 @@ bool DeckList::loadFromStream_Plain(QTextStream &in) const QRegularExpression reEmpty("^\\s*$"); const QRegularExpression reComment("[\\w\\[\\(\\{].*$", QRegularExpression::UseUnicodePropertiesOption); const QRegularExpression reSBMark("^\\s*sb:\\s*(.+)", QRegularExpression::CaseInsensitiveOption); - const QRegularExpression reSBComment("sideboard", QRegularExpression::CaseInsensitiveOption); + const QRegularExpression reSBComment("^sideboard\\b.*$", QRegularExpression::CaseInsensitiveOption); + const QRegularExpression reDeckComment("^((main)?deck(list)?|mainboard)\\b", + QRegularExpression::CaseInsensitiveOption); // simplified matches const QRegularExpression reMultiplier("^[xX\\(\\[]*(\\d+)[xX\\*\\)\\]]* ?(.+)"); @@ -563,6 +565,16 @@ bool DeckList::loadFromStream_Plain(QTextStream &in) } comments.chop(1); // remove last newline + // discard empty lines + while (index < max_line && inputs.at(index).contains(reEmpty)) { + ++index; + } + + // discard line if it starts with deck or mainboard, all cards until the sideboard starts are in the mainboard + if (inputs.at(index).contains(reDeckComment)) { + ++index; + } + // parse decklist for (; index < max_line; ++index) { diff --git a/tests/loading_from_clipboard/loading_from_clipboard_test.cpp b/tests/loading_from_clipboard/loading_from_clipboard_test.cpp index 11b7a7f8..de5fb2e3 100644 --- a/tests/loading_from_clipboard/loading_from_clipboard_test.cpp +++ b/tests/loading_from_clipboard/loading_from_clipboard_test.cpp @@ -165,6 +165,39 @@ TEST(LoadingFromClipboardTest, CommentsBeforeCardsTesting) testDeck(clipboard, result); } +TEST(LoadingFromClipboardTest, mainboardAsLine) +{ + QString clipboard("// Deck Name\n" + "\n" + "MainBoard: 3 cards\n" + "3 card\n" + "\n" + "SideBoard: 2 cards\n" + "2 sidecard\n"); + + Result result("Deck Name", "", {{"card", 3}}, {{"sidecard", 2}}); + testDeck(clipboard, result); +} + +TEST(LoadingFromClipboardTest, deckAsCard) +{ + QString clipboard("6 Deck of Cards But Animated\n" + "\n" + "7 Sideboard Card\n"); + + Result result("", "", {{"Deck of Cards But Animated", 6}}, {{"Sideboard Card", 7}}); + testDeck(clipboard, result); +} + +TEST(LoadingFromClipboardTest, emptyMainBoard) +{ + QString clipboard("deck\n" + "\n" + "sideboard\n"); + + testEmpty(clipboard); +} + int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv);