ignore "deck" at start of a list
add tests
add tests to clangify.sh
This commit is contained in:
ebbit1q 2021-04-02 05:35:36 +02:00 committed by GitHub
parent b940e17fe7
commit 1c48656623
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 2 deletions

View file

@ -11,7 +11,8 @@ cd "${BASH_SOURCE%/*}/" || exit 2 # could not find path, this could happen with
include=("common" \ include=("common" \
"cockatrice/src" \ "cockatrice/src" \
"oracle/src" \ "oracle/src" \
"servatrice/src") "servatrice/src" \
"tests")
exclude=("servatrice/src/smtp" \ exclude=("servatrice/src/smtp" \
"common/sfmt" \ "common/sfmt" \
"common/lib" \ "common/lib" \

View file

@ -492,7 +492,9 @@ bool DeckList::loadFromStream_Plain(QTextStream &in)
const QRegularExpression reEmpty("^\\s*$"); const QRegularExpression reEmpty("^\\s*$");
const QRegularExpression reComment("[\\w\\[\\(\\{].*$", QRegularExpression::UseUnicodePropertiesOption); const QRegularExpression reComment("[\\w\\[\\(\\{].*$", QRegularExpression::UseUnicodePropertiesOption);
const QRegularExpression reSBMark("^\\s*sb:\\s*(.+)", QRegularExpression::CaseInsensitiveOption); 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 // simplified matches
const QRegularExpression reMultiplier("^[xX\\(\\[]*(\\d+)[xX\\*\\)\\]]* ?(.+)"); const QRegularExpression reMultiplier("^[xX\\(\\[]*(\\d+)[xX\\*\\)\\]]* ?(.+)");
@ -563,6 +565,16 @@ bool DeckList::loadFromStream_Plain(QTextStream &in)
} }
comments.chop(1); // remove last newline 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 // parse decklist
for (; index < max_line; ++index) { for (; index < max_line; ++index) {

View file

@ -165,6 +165,39 @@ TEST(LoadingFromClipboardTest, CommentsBeforeCardsTesting)
testDeck(clipboard, result); 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) int main(int argc, char **argv)
{ {
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);