Cheats: improved cheat and test commands to use same set_code-card_name notation, added additional tests (related to #10139, cheat command example: battlefield:Human:XLN-Island:1)

This commit is contained in:
Oleg Agafonov 2023-04-04 22:05:22 +04:00
parent 00b6113244
commit a6337fd28a
6 changed files with 84 additions and 28 deletions

View file

@ -15,7 +15,7 @@ public class TokenImagesTest extends CardTestPlayerBase {
@Test
public void test_TokenMustGetSameSetCodeAsSourceCard() {
//{3}{W}, {T}, Sacrifice Memorial to Glory: Create two 1/1 white Soldier creature tokens.
addCard(Zone.BATTLEFIELD, playerA, "40K:Memorial to Glory");
addCard(Zone.BATTLEFIELD, playerA, "40K-Memorial to Glory");
addCard(Zone.BATTLEFIELD, playerA, "Plains", 4);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{3}{W}, {T}, Sacrifice");

View file

@ -600,7 +600,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
* @param gameZone {@link mage.constants.Zone} to add cards to.
* @param player {@link Player} to add cards for. Use either playerA or
* playerB.
* @param cardName Card name or set:card
* @param cardName Card name or set-card
* @param count Amount of cards to be added.
* @param tapped In case gameZone is Battlefield, determines whether
* permanent should be tapped. In case gameZone is other
@ -624,11 +624,9 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
// set code for card
String setCode = "";
String setLookup = CardUtil.substring(cardName, CardUtil.TESTS_SET_CODE_LOOKUP_LENGTH);
if (setLookup.contains(":")) {
setCode = setLookup.substring(0, setLookup.indexOf(":"));
cardName = cardName.substring(setCode.length() + 1);
}
List<String> cardCommand = SystemUtil.parseSetAndCardNameCommand(cardName);
setCode = cardCommand.get(0);
cardName = cardCommand.get(1);
CardInfo cardInfo;
if (setCode.isEmpty()) {

View file

@ -2,15 +2,55 @@ package org.mage.test.testapi;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.server.util.SystemUtil;
import org.junit.Assert;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
import java.util.List;
/**
* @author JayDi85
*/
public class AddCardApiTest extends CardTestPlayerBase {
@Test
public void test_CardParsing() {
List<String> info;
info = SystemUtil.parseSetAndCardNameCommand("");
Assert.assertEquals(2, info.size());
Assert.assertEquals("", info.get(0));
Assert.assertEquals("", info.get(1));
info = SystemUtil.parseSetAndCardNameCommand("single name");
Assert.assertEquals(2, info.size());
Assert.assertEquals("", info.get(0));
Assert.assertEquals("single name", info.get(1));
info = SystemUtil.parseSetAndCardNameCommand("SET-name");
Assert.assertEquals(2, info.size());
Assert.assertEquals("SET", info.get(0));
Assert.assertEquals("name", info.get(1));
// only upper case set codes can be used
info = SystemUtil.parseSetAndCardNameCommand("non-set-code-name");
Assert.assertEquals(2, info.size());
Assert.assertEquals("", info.get(0));
Assert.assertEquals("non-set-code-name", info.get(1));
info = SystemUtil.parseSetAndCardNameCommand("SET-card-name");
Assert.assertEquals(2, info.size());
Assert.assertEquals("SET", info.get(0));
Assert.assertEquals("card-name", info.get(1));
// must find first symbols before delimeter, e.g. TOO
info = SystemUtil.parseSetAndCardNameCommand("TOO-LONG-SET-card-name");
Assert.assertEquals(2, info.size());
Assert.assertEquals("TOO", info.get(0));
Assert.assertEquals("LONG-SET-card-name", info.get(1));
}
@Test
public void test_CardName_Normal() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 3);
@ -30,8 +70,8 @@ public class AddCardApiTest extends CardTestPlayerBase {
@Test
public void test_CardNameWithSetCode_Normal() {
addCard(Zone.BATTLEFIELD, playerA, "40K:Memorial to Glory", 2);
addCard(Zone.BATTLEFIELD, playerA, "PANA:Plains", 2);
addCard(Zone.BATTLEFIELD, playerA, "40K-Memorial to Glory", 2);
addCard(Zone.BATTLEFIELD, playerA, "PANA-Plains", 2);
setStrictChooseMode(true);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
@ -50,6 +90,6 @@ public class AddCardApiTest extends CardTestPlayerBase {
@Test(expected = org.junit.ComparisonFailure.class)
public void test_CardNameWithSetCode_RaiseErrorOnUnknownSet() {
addCard(Zone.BATTLEFIELD, playerA, "SS4:Plains", 1);
addCard(Zone.BATTLEFIELD, playerA, "SS4-Plains", 1);
}
}