mirror of
https://github.com/ReVanced/revanced-library.git
synced 2026-01-11 13:56:17 +00:00
fix: Differentiate no package compatibility to any version compatibility
This commit is contained in:
@@ -67,6 +67,9 @@ object PatchUtils {
|
|||||||
.flatMap { it.compatiblePackages ?: emptyList() }
|
.flatMap { it.compatiblePackages ?: emptyList() }
|
||||||
.let(::filterWantedPackages)
|
.let(::filterWantedPackages)
|
||||||
.forEach { compatiblePackage ->
|
.forEach { compatiblePackage ->
|
||||||
|
if (compatiblePackage.versions?.isEmpty() == true)
|
||||||
|
return@forEach
|
||||||
|
|
||||||
val versionMap = getOrPut(compatiblePackage.name) { linkedMapOf() }
|
val versionMap = getOrPut(compatiblePackage.name) { linkedMapOf() }
|
||||||
|
|
||||||
compatiblePackage.versions?.let { versions ->
|
compatiblePackage.versions?.let { versions ->
|
||||||
|
|||||||
@@ -10,21 +10,49 @@ import kotlin.test.assertEquals
|
|||||||
internal object PatchUtilsTest {
|
internal object PatchUtilsTest {
|
||||||
private val patches =
|
private val patches =
|
||||||
arrayOf(
|
arrayOf(
|
||||||
newPatch("some.package", "a"),
|
newPatch("some.package", setOf("a")),
|
||||||
newPatch("some.package", "a", "b", use = false),
|
newPatch("some.package", setOf("a", "b"), use = false),
|
||||||
newPatch("some.package", "a", "b", "c", use = false),
|
newPatch("some.package", setOf("a", "b", "c"), use = false),
|
||||||
newPatch("some.other.package", "b", use = false),
|
newPatch("some.other.package", setOf("b"), use = false),
|
||||||
newPatch("some.other.package", "b", "c"),
|
newPatch("some.other.package", setOf("b", "c")),
|
||||||
newPatch("some.other.package", "b", "c", "d"),
|
newPatch("some.other.package", setOf("b", "c", "d")),
|
||||||
newPatch("some.other.other.package"),
|
newPatch("some.other.other.package"),
|
||||||
newPatch("some.other.other.package", "a"),
|
newPatch("some.other.other.package", setOf("a")),
|
||||||
newPatch("some.other.other.package", "b"),
|
newPatch("some.other.other.package", setOf("b")),
|
||||||
newPatch("some.other.other.other.package", use = false),
|
newPatch("some.other.other.other.package", use = false),
|
||||||
newPatch("some.other.other.other.package", use = false),
|
newPatch("some.other.other.other.package", use = false),
|
||||||
).toSet()
|
).toSet()
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `return common versions correctly ordered for each package`() {
|
fun `empty because package is incompatible with any version`() {
|
||||||
|
assertEqualsVersions(
|
||||||
|
expected = emptyMap(),
|
||||||
|
patches = setOf(newPatch("some.package", emptySet(), use = true)),
|
||||||
|
compatiblePackageNames = setOf("some.package"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `empty list of versions because package is unconstrained to any version`() {
|
||||||
|
assertEqualsVersions(
|
||||||
|
expected = mapOf("some.package" to linkedMapOf()),
|
||||||
|
patches = setOf(newPatch("some.package")),
|
||||||
|
compatiblePackageNames = setOf("some.package"),
|
||||||
|
countUnusedPatches = true,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `empty because no known package was supplied`() {
|
||||||
|
assertEqualsVersions(
|
||||||
|
expected = emptyMap(),
|
||||||
|
patches,
|
||||||
|
compatiblePackageNames = setOf("unknown.package"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `common versions correctly ordered for each package`() {
|
||||||
fun assertEqualsExpected(compatiblePackageNames: Set<String>?) = assertEqualsVersions(
|
fun assertEqualsExpected(compatiblePackageNames: Set<String>?) = assertEqualsVersions(
|
||||||
expected =
|
expected =
|
||||||
mapOf(
|
mapOf(
|
||||||
@@ -53,7 +81,7 @@ internal object PatchUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `return common versions correctly ordered for each package without counting unused patches`() {
|
fun `common versions correctly ordered for each package without counting unused patches`() {
|
||||||
assertEqualsVersions(
|
assertEqualsVersions(
|
||||||
expected =
|
expected =
|
||||||
mapOf(
|
mapOf(
|
||||||
@@ -73,30 +101,11 @@ internal object PatchUtilsTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `return an empty map because no known package was supplied`() {
|
|
||||||
assertEqualsVersions(
|
|
||||||
expected = emptyMap(),
|
|
||||||
patches,
|
|
||||||
compatiblePackageNames = setOf("unknown.package"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `return empty set of versions because no compatible package is constrained to a version`() {
|
|
||||||
assertEqualsVersions(
|
|
||||||
expected = mapOf("some.package" to linkedMapOf()),
|
|
||||||
patches = setOf(newPatch("some.package")),
|
|
||||||
compatiblePackageNames = setOf("some.package"),
|
|
||||||
countUnusedPatches = true,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `return 'a' because it is the most common version`() {
|
fun `return 'a' because it is the most common version`() {
|
||||||
val patches =
|
val patches =
|
||||||
arrayOf("a", "a", "c", "d", "a", "b", "c", "d", "a", "b", "c", "d")
|
arrayOf("a", "a", "c", "d", "a", "b", "c", "d", "a", "b", "c", "d")
|
||||||
.map { version -> newPatch("some.package", version) }
|
.map { version -> newPatch("some.package", setOf(version)) }
|
||||||
.toSet()
|
.toSet()
|
||||||
|
|
||||||
assertEqualsVersion("a", patches, "some.package")
|
assertEqualsVersion("a", patches, "some.package")
|
||||||
@@ -109,7 +118,7 @@ internal object PatchUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `return null because no patch is compatible with the supplied package name`() {
|
fun `return null because no patch is compatible with the supplied package name`() {
|
||||||
val patches = setOf(newPatch("some.package", "a"))
|
val patches = setOf(newPatch("some.package", setOf("a")))
|
||||||
|
|
||||||
assertEqualsVersion(null, patches, "other.package")
|
assertEqualsVersion(null, patches, "other.package")
|
||||||
}
|
}
|
||||||
@@ -142,6 +151,7 @@ internal object PatchUtilsTest {
|
|||||||
) {
|
) {
|
||||||
// Test both the deprecated and the new method.
|
// Test both the deprecated and the new method.
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
assertEquals(
|
assertEquals(
|
||||||
expected,
|
expected,
|
||||||
PatchUtils.getMostCommonCompatibleVersion(patches, compatiblePackageName),
|
PatchUtils.getMostCommonCompatibleVersion(patches, compatiblePackageName),
|
||||||
@@ -156,7 +166,7 @@ internal object PatchUtilsTest {
|
|||||||
|
|
||||||
private fun newPatch(
|
private fun newPatch(
|
||||||
packageName: String,
|
packageName: String,
|
||||||
vararg versions: String,
|
versions: Set<String>? = null,
|
||||||
use: Boolean = true,
|
use: Boolean = true,
|
||||||
) = object : BytecodePatch() {
|
) = object : BytecodePatch() {
|
||||||
init {
|
init {
|
||||||
@@ -165,7 +175,7 @@ internal object PatchUtilsTest {
|
|||||||
val compatiblePackagesField = Patch::class.java.getDeclaredField("compatiblePackages")
|
val compatiblePackagesField = Patch::class.java.getDeclaredField("compatiblePackages")
|
||||||
|
|
||||||
compatiblePackagesField.isAccessible = true
|
compatiblePackagesField.isAccessible = true
|
||||||
compatiblePackagesField.set(this, setOf(CompatiblePackage(packageName, versions.toSet())))
|
compatiblePackagesField.set(this, setOf(CompatiblePackage(packageName, versions?.toSet())))
|
||||||
|
|
||||||
val useField = Patch::class.java.getDeclaredField("use")
|
val useField = Patch::class.java.getDeclaredField("use")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user