This commit is contained in:
1 parent
8b17ba9d74
commit
17821cff4e
4 files changed
+39
-2
No files matched your search
@@ -121,6 +121,26 @@ private fun Rule.withoutDoubleNegation(): Rule = when (this) {
|
||||
is Rule.InList, is Rule.HasTag, is Rule.MinPriority, is Rule.Due -> this
|
||||
}
|
||||
|
||||
/** Whether every task passes this rule by its shape alone, as an empty all-of group does. */
|
||||
val Rule.admitsEverything: Boolean
|
||||
get() = when (this) {
|
||||
is Rule.AllOf -> children.all { it.admitsEverything }
|
||||
is Rule.AnyOf -> children.any { it.admitsEverything }
|
||||
is Rule.Not -> child.matchesNothing
|
||||
is Rule.MinPriority -> priority == Priority.NONE
|
||||
is Rule.InList, is Rule.HasTag, is Rule.Due -> false
|
||||
}
|
||||
|
||||
/** Whether no task passes this rule by its shape alone, as an empty any-of group or a list condition naming no list. */
|
||||
val Rule.matchesNothing: Boolean
|
||||
get() = when (this) {
|
||||
is Rule.AllOf -> children.any { it.matchesNothing }
|
||||
is Rule.AnyOf -> children.all { it.matchesNothing }
|
||||
is Rule.Not -> child.admitsEverything
|
||||
is Rule.InList -> listIds.isEmpty() && elsewhere.isEmpty()
|
||||
is Rule.HasTag, is Rule.MinPriority, is Rule.Due -> false
|
||||
}
|
||||
|
||||
/** The values a due condition offers, besides "next N days". */
|
||||
val DUE_CHOICES: List<DueSpec> = DueWindow.entries.map(DueSpec::Window) + listOf(DueSpec.ThisWeek, DueSpec.ThisMonth)
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import de.jeanlucmakiola.agendula.domain.Rule
|
||||
import de.jeanlucmakiola.agendula.domain.View
|
||||
import de.jeanlucmakiola.agendula.domain.ViewIcon
|
||||
import de.jeanlucmakiola.agendula.domain.newView
|
||||
import de.jeanlucmakiola.agendula.ui.filters.admitsEverything
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
@@ -95,8 +96,8 @@ class EditViewViewModel @Inject constructor(
|
||||
|
||||
fun setQuickAdd(on: Boolean) = _draft.update { it?.copy(quickAdd = on) }
|
||||
|
||||
/** Sets the scope; one that admits every task is none. */
|
||||
fun setScope(scope: Rule?) = _draft.update { it?.copy(scope = scope?.takeIf { s -> s != Rule.Everything }) }
|
||||
/** Sets the scope; one that admits every task, however it is written, is none. */
|
||||
fun setScope(scope: Rule?) = _draft.update { it?.copy(scope = scope?.takeUnless { s -> s.admitsEverything }) }
|
||||
|
||||
/**
|
||||
* Stores the name, icon, scope and quick-add switch over the view as it is
|
||||
|
||||
@@ -128,6 +128,20 @@ class RuleDraftTest {
|
||||
.isEqualTo(SimpleRule(match = Match.ANY, tags = setOf("nextAction")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a rule that admits every task by its shape is told apart from one that narrows`() {
|
||||
val empty = Rule.AllOf(emptyList())
|
||||
val nothing = Rule.AnyOf(emptyList())
|
||||
assertThat(Rule.AllOf(listOf(empty)).admitsEverything).isTrue()
|
||||
assertThat(Rule.AllOf(listOf(Rule.Not(nothing))).admitsEverything).isTrue()
|
||||
assertThat(Rule.Not(Rule.InList(emptySet())).admitsEverything).isTrue()
|
||||
assertThat(Rule.MinPriority(Priority.NONE).admitsEverything).isTrue()
|
||||
assertThat(Rule.AnyOf(listOf(work, empty)).admitsEverything).isTrue()
|
||||
assertThat(Rule.AllOf(listOf(work, empty)).admitsEverything).isFalse()
|
||||
assertThat(Rule.Not(Rule.InList(emptySet(), setOf("EXTERNAL:1"))).admitsEverything).isFalse()
|
||||
assertThat(nothing.admitsEverything).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a result survives the trip between screens`() {
|
||||
val rule = Rule.AllOf(listOf(Rule.InList(setOf(3L), setOf("EXTERNAL:9")), Rule.Not(Rule.HasTag("a,b(c)")), Rule.Due(DueSpec.NextDays(5))))
|
||||
|
||||
@@ -75,6 +75,8 @@ class EditViewScopeTest {
|
||||
prefs.saveView(newView(0, "Work").copy(scope = Rule.HasTag("x")))!!
|
||||
}
|
||||
val vm = editing(id)
|
||||
vm.setScope(Rule.AllOf(listOf(Rule.AllOf(emptyList()))))
|
||||
assertThat(vm.draft.value!!.scope).isNull()
|
||||
vm.setScope(Rule.Everything)
|
||||
assertThat(vm.draft.value!!.scope).isNull()
|
||||
vm.saveNow()
|
||||
|
||||
Reference in new issue
Block a user