Fix blank line between comments issue (#3407)

* Added failing test to demonstrate issue with dec loading

* Prevents empty lines between comments from being interpreted as the start of the sideboard
This commit is contained in:
Dane Johnson 2018-10-08 10:26:08 -05:00 committed by Zach H
parent cf9fdcd09e
commit bc2cb59c50
2 changed files with 18 additions and 2 deletions

View file

@ -542,10 +542,11 @@ bool DeckList::loadFromStream_Plain(QTextStream &in)
} }
// If we have a blank line and it's the _ONLY_ blank line in the paste // If we have a blank line and it's the _ONLY_ blank line in the paste
// and it follows at least one valid card
// Then we assume it means to start the sideboard section of the paste. // Then we assume it means to start the sideboard section of the paste.
// If we have the word "Sideboard" appear on any line, then that will // If we have the word "Sideboard" appear on any line, then that will
// also indicate the start of the sideboard. // also indicate the start of the sideboard.
if ((line.isEmpty() && blankLines == 1) || line.startsWith("sideboard")) { if ((line.isEmpty() && blankLines == 1 && okRows > 0) || line.startsWith("sideboard")) {
inSideboard = true; inSideboard = true;
continue; // The line isn't actually a card continue; // The line isn't actually a card
} }

View file

@ -228,10 +228,25 @@ TEST(LoadingFromClipboardTest, LotsOfStuffInBulkTesting)
ASSERT_EQ(expectedMainboard, decklistBuilder.mainboard()); ASSERT_EQ(expectedMainboard, decklistBuilder.mainboard());
ASSERT_EQ(expectedSideboard, decklistBuilder.sideboard()); ASSERT_EQ(expectedSideboard, decklistBuilder.sideboard());
} }
TEST(LoadingFromClipboardTest, CommentsBeforeCardsTesting)
{
QString *clipboard = new QString("//NAME: Title from Website.com\n"
"\n"
"//Main\n"
"1 test1\n");
DeckList *decklist = fromClipboard(clipboard);
DecklistBuilder decklistBuilder = DecklistBuilder();
decklist->forEachCard(decklistBuilder);
CardRows expectedMainboard = CardRows({{"test1", 1}});
CardRows expectedSideboard = CardRows({});
ASSERT_EQ(expectedMainboard, decklistBuilder.mainboard());
ASSERT_EQ(expectedSideboard, decklistBuilder.sideboard());
}
} // namespace } // namespace
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }