Skip to content

Commit

Permalink
Backend: Add More regex tests (hannibal002#2937)
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMWolfs authored Nov 17, 2024
1 parent ab16028 commit 113349e
Show file tree
Hide file tree
Showing 77 changed files with 930 additions and 335 deletions.
4 changes: 2 additions & 2 deletions detekt/src/main/kotlin/repo/RepoPatternRegexTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RepoPatternRegexTest(config: Config) : Rule(config) {
is KtEscapeStringTemplateEntry -> entry.unescapedValue
else -> "" // Skip any other types of entries
}
}.removeSurrounding("\"")
}.removeSurrounding("\"").replace("\n", "")

if (!rawPattern.needsRegexTest()) return

Expand Down Expand Up @@ -125,6 +125,6 @@ class RepoPatternRegexTest(config: Config) : Rule(config) {
}

companion object {
val regexConstructs = Regex("""(?<!\\)[.*+(){}\[\]|?]""")
val regexConstructs = Regex("""(?<!\\)[.*+(){}\[|?]""")
}
}
20 changes: 16 additions & 4 deletions src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,36 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@SkyHanniModule
object CollectionAPI {
private val patternGroup = RepoPattern.group("data.collection.api")

/**
* REGEX-TEST: §2§l§m §f§l§m §r §e43,649§6/§e50k
*/
private val counterPattern by patternGroup.pattern(
"counter",
".* §e(?<amount>.*)§6/.*"
".* §e(?<amount>.*)§6/.*",
)

/**
* REGEX-TEST: §7Total collected: §e261,390
*/
private val singleCounterPattern by patternGroup.pattern(
"singlecounter",
"§7Total Collected: §e(?<amount>.*)"
"§7Total collected: §e(?<amount>.*)",
)

/**
* REGEX-TEST: §7Progress to Nether Wart I: §e46§6%
*/
private val collectionTier0Pattern by patternGroup.pattern(
"tierzero",
"§7Progress to .* I: .*"
"§7Progress to .* I: .*",
)

val collectionValue = mutableMapOf<NEUInternalName, Long>()

// TODO repo
private val incorrectCollectionNames = mapOf(
"Mushroom" to "RED_MUSHROOM".toInternalName()
"Mushroom" to "RED_MUSHROOM".toInternalName(),
)

@SubscribeEvent
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ object GetFromSackAPI {
val commandsWithSlash = commands.map { "/$it" }

private val patternGroup = RepoPattern.group("gfs.chat")

/**
* REGEX-TEST: §aMoved §r§e10 Wheat§r§a from your Sacks to your inventory.
*/
private val fromSacksChatPattern by patternGroup.pattern(
"from",
"§aMoved §r§e(?<amount>\\d+) (?<item>.+)§r§a from your Sacks to your inventory.",
)

/**
* REGEX-TEST: §cYou have no Compost in your Sacks!
*/
private val missingChatPattern by patternGroup.pattern(
"missing",
"§cYou have no (?<item>.+) in your Sacks!",
Expand Down
37 changes: 36 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ object BitsAPI {
private val bitsDataGroup = RepoPattern.group("data.bits")

// Scoreboard patterns
/**
* REGEX-TEST: Bits: §b140,965
*/
val bitsScoreboardPattern by bitsDataGroup.pattern(
"scoreboard",
"^Bits: §b(?<amount>[\\d,.]+).*$",
Expand All @@ -67,17 +70,28 @@ object BitsAPI {
// Chat patterns
private val bitsChatGroup = bitsDataGroup.group("chat")

/**
* REGEX-TEST: §eYou gained §317,664 Bits Available §ecompounded from all your §epreviously eaten §6cookies§e! Click here to open §6cookie menu§e!
*/
@Suppress("MaxLineLength")
private val bitsFromFameRankUpChatPattern by bitsChatGroup.pattern(
"rankup.bits",
"§eYou gained §3(?<amount>.*) Bits Available §ecompounded from all your §epreviously eaten §6cookies§e! Click here to open §6cookie menu§e!",
)

/**
* REGEX-TEST: §6 §6§lFAME RANK UP §eStatesperson
*/
private val fameRankUpPattern by bitsChatGroup.pattern(
"rankup.rank",
"\\w\\s]+FAME RANK UP (?:§.)+(?<rank>.*)",
)

/**
* REGEX-TEST: §eYou consumed a §6Booster Cookie§e! §dYummy!
* REGEX-TEST: §eYou consumed a §6Booster Cookie§e!
* REGEX-TEST: §eYou consumed a §6Booster Cookie§e! §dDivine!
*/
private val boosterCookieAte by bitsChatGroup.pattern(
"boostercookieate",
"§eYou consumed a §6Booster Cookie§e!.*",
Expand All @@ -86,6 +100,9 @@ object BitsAPI {
// GUI patterns
private val bitsGuiGroup = bitsDataGroup.group("gui")

/**
* REGEX-TEST: §7Bits Available: §b19,176
*/
private val bitsAvailableMenuPattern by bitsGuiGroup.pattern(
"availablemenu",
"§7Bits Available: §b(?<toClaim>[\\d,]+)(§3.+)?",
Expand All @@ -96,9 +113,12 @@ object BitsAPI {
*/
private val bitsPurseMenuPattern by bitsGuiGroup.pattern(
"bitsmenu",
"^§7Bits Purse: §b(?<amount>[\\d,.]+)"
"^§7Bits Purse: §b(?<amount>[\\d,.]+)",
)

/**
* REGEX-TEST: §7Your rank: §eAttaché
*/
private val fameRankSbMenuPattern by bitsGuiGroup.pattern(
"sbmenufamerank",
"§7Your rank: §e(?<rank>.*)",
Expand All @@ -117,11 +137,18 @@ object BitsAPI {
" §7Status: §cNot active!",
)

/**
* REGEX-TEST: §7§cYou do not currently have a
* REGEX-TEST: §cBooster Cookie active!
*/
private val noCookieActiveCookieMenuPattern by bitsGuiGroup.pattern(
"cookiemenucookieactive",
"(§7§cYou do not currently have a|§cBooster Cookie active!)",
)

/**
* REGEX-TEST: §7Fame Rank: §eAttaché
*/
private val fameRankCommunityShopPattern by bitsGuiGroup.pattern(
"communityshopfamerank",
"§7Fame Rank: §e(?<rank>.*)",
Expand All @@ -142,11 +169,19 @@ object BitsAPI {
"§bBits",
)

/**
* REGEX-TEST: Community Shop
* REGEX-TEST: Booster Cookie
*/
private val fameRankGuiNamePattern by bitsGuiGroup.pattern(
"famerankmenuname",
"^(Community Shop|Booster Cookie)$",
)

/**
* REGEX-TEST: §aCommunity Shop
* REGEX-TEST: §eFame Rank
*/
private val fameRankGuiStackPattern by bitsGuiGroup.pattern(
"famerankmenustack",
"^(§aCommunity Shop|§eFame Rank)$",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@SkyHanniModule
object CropAccessoryData {

/**
* REGEX-TEST: Accessory Bag (1/2)
*/
private val accessoryBagNamePattern by RepoPattern.pattern(
"data.accessory.bagname.new",
"Accessory Bag.*"
"Accessory Bag.*",
)

private var accessoryInBag = CropAccessory.NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import kotlin.time.Duration.Companion.seconds
@SkyHanniModule
object EntityMovementData {

/**
* REGEX-TEST: §7Sending a visit request...
* REGEX-TEST: §7Finding player...
* REGEX-TEST: §7Warping you to your SkyBlock island...
*/
private val warpingPattern by RepoPattern.pattern(
"data.entity.warping",
"§7(?:Warping|Warping you to your SkyBlock island|Warping using transfer token|Finding player|Sending a visit request)\\.\\.\\.",
Expand Down
35 changes: 27 additions & 8 deletions src/main/java/at/hannibal2/skyhanni/data/FriendAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,53 @@ import java.util.UUID
@SkyHanniModule
object FriendAPI {
private val patternGroup = RepoPattern.group("data.friends")

/**
* REGEX-TEST: §r§eYou removed §r§b[MVP§r§d+§r§b] Throwpo§r§e from your friends list!§r§9§m
*/
private val removedFriendPattern by patternGroup.pattern(
"remove",
".*\n§r§eYou removed §r(?<name>.*)§e from your friends list!§r§9§m\n.*"
".*\n§r§eYou removed §r(?<name>.*)§e from your friends list!§r§9§m\n.*",
)

/**
* REGEX-TEST: §aYou are now friends with §r§b[MVP§r§d+§r§b] Throwpo
*/
private val addedFriendPattern by patternGroup.pattern(
"add",
"§aYou are now friends with (?<name>.*)"
"§aYou are now friends with (?<name>.*)",
)

/**
* REGEX-TEST: §r§b[MVP§r§c+§r§b] hannibal2§r§e is no longer a best friend!§r§9§m
*/
private val noBestFriendPattern by patternGroup.pattern(
"removebest",
".*\n§r(?<name>.*)§e is no longer a best friend!§r§9§m\n.*"
".*\n§r(?<name>.*)§e is no longer a best friend!§r§9§m\n.*",
)

/**
* REGEX-TEST: §r§b[MVP§r§c+§r§b] hannibal2§r§a is now a best friend!§r§9§m
*/
private val bestFriendPattern by patternGroup.pattern(
"addbest",
".*\n(?<name>.*)§a is now a best friend!§r§9§m\n.*"
".*\n(?<name>.*)§a is now a best friend!§r§9§m\n.*",
)

/**
* REGEX-TEST:
* §eClick here to view §bAaronL_Jackson§e's profile
* REGEX-TEST: §eClick here to view §bThrowpo§e's profile
*/
private val rawNamePattern by patternGroup.pattern(
"rawname",
"\\n§eClick here to view §.(?<name>.*)§e's profile"
"\n§eClick here to view §.(?<name>.*)§e's profile",
)

/**
* REGEX-TEST: /viewprofile 503450fc-72c2-4e87-8243-94e264977437
*/
private val readFriendListPattern by patternGroup.pattern(
"readfriends",
"/viewprofile (?<uuid>.*)"
"/viewprofile (?<uuid>.*)",
)

private val tempFriends = mutableListOf<Friend>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,19 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
object GardenCropMilestones {

private val patternGroup = RepoPattern.group("data.garden.milestone")

/**
* REGEX-TEST: §7Harvest §fWheat §7on your Garden to
* REGEX-TEST: §7Harvest §fCocoa Beans §7on your
*/
private val cropPattern by patternGroup.pattern(
"crop",
"§7Harvest §f(?<name>.*) §7on .*",
)

/**
* REGEX-TEST: §7Total: §a36,967,397
*/
val totalPattern by patternGroup.pattern(
"total",
"§7Total: §a(?<name>.*)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object GardenCropMilestonesCommunityFix {

/**
* REGEX-TEST: §2§l§m §f§l§m §r §e676,985§6/§e2M
*/
private val amountPattern by RepoPattern.pattern(
"data.garden.milestonefix.amount",
".*§e(?<having>.*)§6/§e(?<max>.*)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
object GardenCropUpgrades {

private val patternGroup = RepoPattern.group("garden.cropupgrades")

/**
* REGEX-TEST: §7Current Tier: §e7§7/§a9
*/
private val tierPattern by patternGroup.pattern(
"tier",
"§7Current Tier: §.(?<level>\\d)§7/§a9",
)

/**
* REGEX-TEST: §r§6§lCROP UPGRADE §eNether Wart§7 #7
*/
private val chatUpgradePattern by patternGroup.pattern(
"chatupgrade",
"\\s+§r§6§lCROP UPGRADE §e(?<crop>[\\w ]+)§7 #(?<tier>\\d)",
Expand Down
Loading

0 comments on commit 113349e

Please sign in to comment.