aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt12
-rw-r--r--src/test/java/at/hannibal2/skyhanni/test/RepoPatternTest.kt51
2 files changed, 60 insertions, 3 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt b/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt
index 26452e58f..09cd4f730 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt
@@ -49,16 +49,18 @@ object RepoPatternManager {
private val insideTest = Launch.blackboard == null
+ var inTestDuplicateUsage = true
+
private val config
get() = if (!insideTest) {
SkyHanniMod.feature.dev.repoPattern
} else {
RepoPatternConfig().apply {
- tolerateDuplicateUsage = true
+ tolerateDuplicateUsage = inTestDuplicateUsage
}
}
- val localLoading: Boolean get() = config.forceLocal.get() || LorenzUtils.isInDevEnvironment()
+ val localLoading: Boolean get() = config.forceLocal.get() || (!insideTest && LorenzUtils.isInDevEnvironment())
/**
* Crash if in a development environment, or if inside a guarded event handler.
@@ -86,8 +88,12 @@ object RepoPatternManager {
@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
+ loadPatternsFromDump(event.getConstant<RepoPatternDump>("regexes"))
+ }
+
+ fun loadPatternsFromDump(dump: RepoPatternDump) {
regexes = null
- regexes = event.getConstant<RepoPatternDump>("regexes")
+ regexes = dump
reloadPatterns()
}
diff --git a/src/test/java/at/hannibal2/skyhanni/test/RepoPatternTest.kt b/src/test/java/at/hannibal2/skyhanni/test/RepoPatternTest.kt
new file mode 100644
index 000000000..46c2fb619
--- /dev/null
+++ b/src/test/java/at/hannibal2/skyhanni/test/RepoPatternTest.kt
@@ -0,0 +1,51 @@
+package at.hannibal2.skyhanni.test
+
+import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
+import at.hannibal2.skyhanni.utils.repopatterns.RepoPatternDump
+import at.hannibal2.skyhanni.utils.repopatterns.RepoPatternManager
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.assertThrows
+
+object RepoPatternTest {
+
+ @Test
+ fun testRemoteLoad() {
+ val simpleLocalePattern = "I'm a test value"
+
+ val simpleRepoPattern = RepoPattern.pattern("testonly.a", simpleLocalePattern)
+ val simplePattern by simpleRepoPattern
+
+ val remoteValue = "I'm remote."
+
+ val isLocalWorking = simplePattern.pattern() == simpleLocalePattern
+
+ assert(isLocalWorking)
+
+ RepoPatternManager.loadPatternsFromDump(
+ RepoPatternDump(
+ regexes = mapOf(
+ simpleRepoPattern.key to remoteValue
+ )
+ )
+ )
+
+ val isRemoteWorking = simplePattern.pattern() == remoteValue
+
+ assert(isRemoteWorking)
+
+ }
+
+ @Test
+ fun testExclusivity() {
+ RepoPatternManager.inTestDuplicateUsage = false
+
+ assertThrows<RuntimeException> {
+ val pattern1 by RepoPattern.pattern("testonly.b", "")
+ val pattern2 by RepoPattern.pattern("testonly.b", "")
+ pattern1
+ pattern2
+ }
+
+ RepoPatternManager.inTestDuplicateUsage = true
+ }
+}