From 5bff03f57a7bf5ed3184e0d3cae2e6a2bfc2d9d7 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Wed, 12 Apr 2023 09:51:19 +0400 Subject: [PATCH] Tests: improved verify tests for tokens data, added how-to fix hints, added new checks (disabled by default) --- .../java/mage/verify/VerifyCardDataTest.java | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java b/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java index e1cf15cd94..bf588b24f4 100644 --- a/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java +++ b/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java @@ -1283,6 +1283,8 @@ public class VerifyCardDataTest { if (token == null) { errorsList.add("Error: token must have default constructor with zero params: " + tokenClass.getName()); } else if (tokDataNamesIndex.getOrDefault(token.getName().replace(" Token", ""), "").isEmpty()) { + // how-to fix: public token must be downloadable, so tok-data must contain miss set + // (also don't forget to add new set to scryfall download) errorsList.add("Error: can't find data in card-pictures-tok.txt for token: " + tokenClass.getName() + " -> " + token.getName()); } } @@ -1312,20 +1314,45 @@ public class VerifyCardDataTest { } // set uses tokens, but tok data miss it setsWithTokens.forEach((setCode, sourceCards) -> { - if (!tokDataTokensBySetIndex.containsKey(setCode)) { + List setTokens = tokDataTokensBySetIndex.getOrDefault(setCode, null); + if (setTokens == null) { // it's not a problem -- just find set's cards without real tokens for image tests - // (most use cases: promo sets) - warningsList.add("info, set has cards with token abilities, but it haven't token data: " + // Possible reasons: + // - promo sets with cards without tokens (nothing to do with it) + // - miss set from tok-data (must add new set to tok-data and scryfall download) + warningsList.add("info, set's cards uses tokens but tok-data haven't it: " + setCode + " - " + sourceCards.stream().map(MageObject::getName).collect(Collectors.joining(", "))); + } else { + // Card can be checked on scryfall like "set:set_code oracle:token_name oracle:token" + // Possible reasons for un-used tokens: + // - normal use case: tok-data contains wrong token data and must be removed + // - normal use case: card uses wrong rules text (must contain "create" and "token" words) + // - rare use case: un-implemented card that uses a token + setTokens.forEach(token -> { + if (token.getName().contains("Plane - ")) { + // cards don't put it to the game, so no related cards + return; + } + String needTokenName = token.getName() + .replace(" Token", "") + .replace("Emblem ", ""); + // need add card name, so it will skip no name emblems like Sarkhan, the Dragonspeaker + if (sourceCards.stream() + .map(card -> card.getName() + " - " + String.join(", ", card.getRules())) + .noneMatch(s -> s.contains(needTokenName))) { + warningsList.add("info, tok-data has un-used tokens: " + + token.getSet() + " - " + token.getName()); + } + }); } }); // tok data have tokens, but cards from set are miss tokDataTokensBySetIndex.forEach((setCode, setTokens) -> { if (!setsWithTokens.containsKey(setCode)) { - // possible reasons: - // - bad: outdated set code in tokens database (must use exists set codes, see additional check with token's codes) - // - ok: promo set contains additional tokens for main set -- it's ok and must be ignored (example: Saproling in E02) - warningsList.add("warning, tok data has set with tokens, but real set haven't cards with it: " + // Possible reasons: + // - outdated set code in tokens database (must be fixed by new set code, another verify check it) + // - promo set contains additional tokens for main set (it's ok and must be ignored, example: Saproling in E02) + warningsList.add("warning, tok-data has tokens, but real set haven't cards with it: " + setCode + " - " + setTokens.stream().map(CardDownloadData::getName).collect(Collectors.joining(", "))); } });