mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-24 03:58:56 +02:00
Allow creating backups without library entries
- In case you want a backup of just settings? - Also disable backup options if dependent option is disabled (and fix being able to toggle disabled items) - Also fix crash in RestoreBackupScreen due to attempt to parcelize Uri - Make restore validation message a bit nicer
This commit is contained in:
@@ -18,3 +18,9 @@ inline fun <reified T : Any> BooleanArray.asDataClass(): T {
|
||||
require(properties.size == this.size) { "Boolean array size does not match data class property count" }
|
||||
return T::class.primaryConstructor!!.call(*this.toTypedArray())
|
||||
}
|
||||
|
||||
fun <T : Any> T.anyEnabled(): Boolean {
|
||||
return this::class.declaredMemberProperties
|
||||
.filterIsInstance<KProperty1<T, Boolean>>()
|
||||
.any { it.get(this) }
|
||||
}
|
||||
@@ -2,40 +2,55 @@ package tachiyomi.core.util.lang
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertArrayEquals
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import org.junit.jupiter.api.parallel.Execution
|
||||
import org.junit.jupiter.api.parallel.ExecutionMode
|
||||
|
||||
@Execution(ExecutionMode.CONCURRENT)
|
||||
class BooleanArrayExtensionsTest {
|
||||
class BooleanDataClassExtensionsTest {
|
||||
|
||||
@Test
|
||||
fun `converts to boolean array`() {
|
||||
fun `asBooleanArray converts data class to boolean array`() {
|
||||
assertArrayEquals(booleanArrayOf(true, false), TestClass(foo = true, bar = false).asBooleanArray())
|
||||
assertArrayEquals(booleanArrayOf(false, true), TestClass(foo = false, bar = true).asBooleanArray())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `throws error for invalid data classes`() {
|
||||
fun `asBooleanArray throws error for invalid data classes`() {
|
||||
assertThrows<ClassCastException> {
|
||||
InvalidTestClass(foo = true, bar = "").asBooleanArray()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `converts from boolean array`() {
|
||||
fun `asDataClass converts from boolean array`() {
|
||||
assertEquals(booleanArrayOf(true, false).asDataClass<TestClass>(), TestClass(foo = true, bar = false))
|
||||
assertEquals(booleanArrayOf(false, true).asDataClass<TestClass>(), TestClass(foo = false, bar = true))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `throws error for invalid boolean array`() {
|
||||
fun `asDataClass throws error for invalid boolean array`() {
|
||||
assertThrows<IllegalArgumentException> {
|
||||
booleanArrayOf(true).asDataClass<TestClass>()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `anyEnabled returns based on if any boolean property is enabled`() {
|
||||
assertTrue(TestClass(foo = false, bar = true).anyEnabled())
|
||||
assertFalse(TestClass(foo = false, bar = false).anyEnabled())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `anyEnabled throws error for invalid class`() {
|
||||
assertThrows<ClassCastException> {
|
||||
InvalidTestClass(foo = true, bar = "").anyEnabled()
|
||||
}
|
||||
}
|
||||
|
||||
data class TestClass(
|
||||
val foo: Boolean,
|
||||
val bar: Boolean,
|
||||
Reference in New Issue
Block a user