Skip to content

Commit

Permalink
feat: PatchOptions#nullify to nullify an option
Browse files Browse the repository at this point in the history
  • Loading branch information
Sculas committed Aug 2, 2022
1 parent 1b42f65 commit 371f0c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/kotlin/app/revanced/patcher/patch/PatchOption.kt
Expand Up @@ -42,6 +42,14 @@ class PatchOptions(vararg val options: PatchOption<*>) : Iterable<PatchOption<*>
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()
}

Expand Down
Expand Up @@ -36,6 +36,15 @@ internal class PatchOptionsTest {
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
fun `should fail because the option does not exist`() {
assertThrows<NoSuchOptionException> {
Expand Down

0 comments on commit 371f0c4

Please sign in to comment.