mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-05-01 13:44:25 +02:00
feat: PatchOptions#nullify to nullify an option
This commit is contained in:
parent
1b42f65d95
commit
371f0c4d0b
@ -42,6 +42,14 @@ class PatchOptions(vararg val options: PatchOption<*>) : Iterable<PatchOption<*>
|
|||||||
opt.value = value
|
opt.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of a [PatchOption] to `null`.
|
||||||
|
* @param key The key of the [PatchOption].
|
||||||
|
*/
|
||||||
|
fun nullify(key: String) {
|
||||||
|
get(key).value = null
|
||||||
|
}
|
||||||
|
|
||||||
override fun iterator() = options.iterator()
|
override fun iterator() = options.iterator()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,15 @@ internal class PatchOptionsTest {
|
|||||||
println(options["key1"].value)
|
println(options["key1"].value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should be able to set value to null`() {
|
||||||
|
// Sadly, doing:
|
||||||
|
// > options["key1"] = null
|
||||||
|
// is not possible because Kotlin
|
||||||
|
// cannot reify the type "Nothing?".
|
||||||
|
options.nullify("key1")
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `should fail because the option does not exist`() {
|
fun `should fail because the option does not exist`() {
|
||||||
assertThrows<NoSuchOptionException> {
|
assertThrows<NoSuchOptionException> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user