From 727165dd3ada4780482d24ff123596a321db8f5d Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Mon, 14 Jan 2019 11:01:42 +0400 Subject: [PATCH] Improved verify tests (wip) and showCardInfo for realtime texts test. --- .../java/mage/verify/VerifyCardDataTest.java | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java b/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java index 6dc4d00213..6dc375d3b2 100644 --- a/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java +++ b/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java @@ -4,6 +4,7 @@ import mage.ObjectColor; import mage.abilities.keyword.MultikickerAbility; import mage.cards.*; import mage.cards.basiclands.BasicLand; +import mage.cards.repository.*; import mage.constants.CardType; import mage.constants.Rarity; import mage.constants.SubType; @@ -565,6 +566,7 @@ public class VerifyCardDataTest { //checkNumbers(card, ref); // TODO: load data from allsets.json and check it (allcards.json do not have card numbers) checkBasicLands(card, ref); checkMissingAbilities(card, ref); + //checkWrongCosts(card, ref); } private void checkColors(Card card, JsonCard ref) { @@ -656,6 +658,128 @@ public class VerifyCardDataTest { } } + private String prepareRule(String cardName, String rule) { + // remove and optimize rule text for analyze + String newRule = rule; + + // remove reminder text + newRule = newRule.replaceAll("(?i)\\(.+\\)", ""); + + // replace special text and symbols + newRule = newRule + .replace("{this}", cardName) + .replace("—", "—"); + + // remove html marks + newRule = newRule + .replace("", "") + .replace("", ""); + + return newRule; + } + + @Test + @Ignore + public void showCardInfo() throws Exception { + // debug only: show direct card info (takes it from class file, not from db repository) + String cardName = "Essence Capture"; + CardScanner.scan(); + CardSetInfo testSet = new CardSetInfo("test", "test", "123", Rarity.COMMON); + CardInfo cardInfo = CardRepository.instance.findCard(cardName); + Card card = CardImpl.createCard(cardInfo.getClassName(), testSet); + card.getRules().stream().forEach(System.out::println); + } + + private void checkWrongCosts(Card card, JsonCard ref) { + // checks missing or wrong cost + if (!card.getExpansionSetCode().equals("RNA")) { + return; + } + + String[] refRules = ref.text.split("[\\$\\\n]"); // ref card's abilities can be splited by \n or $ chars + for (int i = 0; i < refRules.length; i++) { + refRules[i] = prepareRule(card.getName(), refRules[i]); + } + + String[] cardRules = card.getRules().toArray(new String[0]); + for (int i = 0; i < cardRules.length; i++) { + cardRules[i] = prepareRule(card.getName(), cardRules[i]); + } + + for (String cardRule : cardRules) { + boolean isAbilityFounded = false; + boolean isCostOk = false; + for (String refRule : refRules) { + if (cardRule.equals(refRule)) { + isAbilityFounded = true; + isCostOk = true; + break; + } + } + + if (!isCostOk) { + fail(card, "abilities", "card ability have cost, but can't find in ref [" + "xxx" + ": " + card.getRules() + "]"); + } + } + } + + + /* + for(String rule : card.getRules()) { + rule = rule.replaceAll("(?i).+", ""); // Ignoring reminder text in italic + // TODO: add Equip {3} checks + // TODO: add Raid and other words checks + String[] sl = rule.split(":"); + if (sl.length == 2 && !sl[0].isEmpty()) { + String cardCost = sl[0] + .replace("{this}", card.getName()) + //.replace("", "") + //.replace("", "") + .replace("—", "—"); + String cardAbility = sl[1] + .trim() + .replace("{this}", card.getName()) + //.replace("", "") + //.replace("", "") + .replace("—", "—");; + + boolean found = false; + for (String refRule : refRules) { + refRule = refRule.replaceAll("(?i).+", ""); // Ignoring reminder text in italic + + // fix for ref mana: ref card have xxx instead {T}: Add {xxx}, example: W + if (refRule.length() == 1) { + refRule = "{T}: Add {" + refRule + "}"; + } + refRule = refRule + .trim() + //.replace("", "") + //.replace("", "") + .replace("—", "—"); + + // normal + if (refRule.startsWith(cardCost)) { + found = true; + break; + } + + // ref card have (xxx) instead xxx, example: ({T}: Add {G}.) + // ref card have (xxx) instead xxx, example: ({T}: Add {G}.) + // TODO: delete? + if (refRule.startsWith("(" + cardCost)) { + found = true; + break; + } + } + if (!found) { + fail(card, "abilities", "card ability have cost, but can't find in ref [" + cardCost + ": " + cardAbility + "]"); + } + } + + } + }*/ + + private void checkTypes(Card card, JsonCard ref) { if (skipListHaveName("TYPE", card.getExpansionSetCode(), card.getName())) { return;