mirror of
https://github.com/correl/mage.git
synced 2024-11-14 11:09:31 +00:00
Text import will automatically start sideboard after a single blank line. Added a JUnit test for TxtDeckImporter.
This commit is contained in:
parent
2d4ba24dd9
commit
95e4e3ea29
3 changed files with 60 additions and 10 deletions
6
Mage.Tests/JustLands.txt
Normal file
6
Mage.Tests/JustLands.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
1 Forest
|
||||
1 Plains
|
||||
1 Island
|
||||
|
||||
1 Swamp
|
||||
1 Mountain
|
|
@ -0,0 +1,43 @@
|
|||
package org.mage.test.decks.importer;
|
||||
|
||||
import mage.cards.decks.DeckCardInfo;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.cards.decks.importer.TxtDeckImporter;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TxtDeckImporterTest {
|
||||
|
||||
@Test
|
||||
public void testImportWithBlankLineAboveSideboard() {
|
||||
TxtDeckImporter importer = new TxtDeckImporter();
|
||||
|
||||
CardInfo card;
|
||||
DeckCardLists deck = new DeckCardLists();
|
||||
|
||||
String[] cards = {"Plains", "Forest", "Island"};
|
||||
String[] sideboard = {"Swamp", "Mountain"};
|
||||
|
||||
for (String c : cards) {
|
||||
card = CardRepository.instance.findPreferedCoreExpansionCard(c, true);
|
||||
assert card != null;
|
||||
deck.getCards().add(new DeckCardInfo(card.getName(), card.getCardNumber(), card.getSetCode()));
|
||||
}
|
||||
|
||||
for (String s : sideboard) {
|
||||
card = CardRepository.instance.findPreferedCoreExpansionCard(s, true);
|
||||
assert card != null;
|
||||
deck.getSideboard().add(new DeckCardInfo(card.getName(), card.getCardNumber(), card.getSetCode()));
|
||||
}
|
||||
|
||||
Assert.assertEquals("Deck does not contain 3 cards, found " + deck.getCards().size(), 3, deck.getCards().size());
|
||||
Assert.assertEquals("Sideboard does not contain 2 cards, found " + deck.getSideboard().size(), 2, deck.getSideboard().size());
|
||||
|
||||
DeckCardLists imported = importer.importDeck("JustLands.txt");
|
||||
|
||||
Assert.assertEquals("Imported deck does not contain 3 cards, found " + imported.getCards().size(), 3, imported.getCards().size());
|
||||
Assert.assertEquals("Imported sideboard does not contain 2 cards, found " + imported.getSideboard().size(), 2, imported.getSideboard().size());
|
||||
}
|
||||
}
|
|
@ -27,14 +27,15 @@
|
|||
*/
|
||||
package mage.cards.decks.importer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import mage.cards.decks.DeckCardInfo;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -46,7 +47,7 @@ public class TxtDeckImporter extends DeckImporter {
|
|||
public static final Set<String> IGNORE_NAMES = new HashSet<>(Arrays.asList(SET_VALUES));
|
||||
|
||||
private boolean sideboard = false;
|
||||
private int emptyLinesInARow = 0;
|
||||
private int nonEmptyLinesTotal = 0;
|
||||
|
||||
@Override
|
||||
protected void readLine(String line, DeckCardLists deckList) {
|
||||
|
@ -57,14 +58,14 @@ public class TxtDeckImporter extends DeckImporter {
|
|||
if (line.startsWith("//")) {
|
||||
return;
|
||||
}
|
||||
if (line.length() == 0) {
|
||||
emptyLinesInARow++;
|
||||
if (emptyLinesInARow > 1) {
|
||||
|
||||
// Start the sideboard on empty line that follows
|
||||
// at least 1 non-empty line
|
||||
if (line.length() == 0 && nonEmptyLinesTotal > 0) {
|
||||
sideboard = true;
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
emptyLinesInARow = 0;
|
||||
nonEmptyLinesTotal++;
|
||||
}
|
||||
|
||||
line = line.replace("\t", " "); // changing tabs to blanks as delimiter
|
||||
|
|
Loading…
Reference in a new issue