From e960a9d0da3e50cd34dff31a6f07f73e516fb82e Mon Sep 17 00:00:00 2001 From: "Florine W. Dekker" Date: Fri, 20 Oct 2023 00:02:50 +0200 Subject: [PATCH] Use val/var consistently in schemes, rewrite trees The goal was actually only to fix the usages of `val`s and `var`s across the `Scheme`s (cf. #476), but this ended up in being a major overhaul of how the various `Tree`-related classes work together. I found quite a few pieces of code that were, by themselves, neat, but for which much better solutions existed. With these changes, I feel more confident in the stability of the code, and plenty of docs and tests have been added as well. I am aware that #473 will be another overhaul of the `Tree`s, but that won't be until v3.1.x, and I don't want to wait for that. Also, depending on the solution for that issue, the code here might be retained completely anyway. --- README.md | 13 +- build.gradle.kts | 5 +- .../kotlin/com/fwdekker/randomness/Bundle.kt | 2 +- .../com/fwdekker/randomness/SchemeEditor.kt | 2 +- .../com/fwdekker/randomness/Settings.kt | 42 +- .../kotlin/com/fwdekker/randomness/State.kt | 40 +- .../fwdekker/randomness/template/Template.kt | 2 +- .../template/TemplateActionLoader.kt | 3 +- .../randomness/template/TemplateActions.kt | 24 +- .../randomness/template/TemplateJTree.kt | 282 ++++---- .../randomness/template/TemplateJTreeModel.kt | 287 ++++----- .../randomness/template/TemplateList.kt | 9 +- .../template/TemplateListConfigurable.kt | 23 +- .../randomness/template/TemplateListEditor.kt | 124 ++-- .../randomness/template/TemplateReference.kt | 5 + .../fwdekker/randomness/ui/PreviewPanel.kt | 4 +- .../randomness/word/WordSchemeEditor.kt | 13 +- src/main/resources/randomness.properties | 23 +- .../com/fwdekker/randomness/SettingsTest.kt | 27 +- .../com/fwdekker/randomness/StateTest.kt | 42 -- .../template/TemplateJTreeModelTest.kt | 594 ++++++++--------- .../randomness/template/TemplateJTreeTest.kt | 604 +++++++++++------- .../template/TemplateListEditorTest.kt | 48 +- .../randomness/testhelpers/Dummies.kt | 2 +- .../randomness/ui/PreviewPanelTest.kt | 3 +- .../randomness/word/WordSchemeEditorTest.kt | 3 +- 26 files changed, 1166 insertions(+), 1060 deletions(-) diff --git a/README.md b/README.md index 0574d9651..f6cc4c228 100644 --- a/README.md +++ b/README.md @@ -100,11 +100,22 @@ See [Plugin Signing](https://plugins.jetbrains.com/docs/intellij/plugin-signing. ```bash $ gradlew test # Run tests $ gradlew test --tests X # Run tests in class X (package name optional) -$ gradlew test --kotest.tags="X" # Run tests with `NamedTag` X (also supports not (!), and (&), or (|)) +$ gradlew test -Pkotest.tags="X" # Run tests with `NamedTag` X (also supports not (!), and (&), or (|)) $ gradlew check # Run tests and static analysis $ gradlew runPluginVerifier # Check for compatibility issues ``` +#### 🏷️ Filtering tests +[Kotest tests can be tagged](https://kotest.io/docs/framework/tags.html) to allow selectively running tests. +Tag an entire test class by adding `tags(...)` to the class definition, or tag an individual test `context` by +writing `context("foo").config(tags = setOf(...)) {`. +It is not possible to tag an individual `test` due to limitations in Kotest. + +To run only one `context` in some test class `X`, prefix the `context`'s name with `f:` and run with `--tests X`. +The prefix `f:` filters out other `context`s in that test class, and `--tests X` filters out other test classes. +Alternatively, tag the desired `context` with the `Focus` tag and run with `-Pkotest.tags="Focus"` to filter by that +tag. + ### 📚 Documentation ```bash $ gradlew dokkaHtml # Generate documentation diff --git a/build.gradle.kts b/build.gradle.kts index 645a27793..13360b49c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -105,7 +105,10 @@ tasks { if (project.hasProperty("kotest.tags")) systemProperty("kotest.tags", project.findProperty("kotest.tags")!!) useJUnitPlatform { - includeEngines("junit-vintage", "kotest") + if (!project.hasProperty("kotest.tags")) + includeEngines("junit-vintage") + + includeEngines("kotest") } testLogging { diff --git a/src/main/kotlin/com/fwdekker/randomness/Bundle.kt b/src/main/kotlin/com/fwdekker/randomness/Bundle.kt index 20f263aa2..5fac53f29 100644 --- a/src/main/kotlin/com/fwdekker/randomness/Bundle.kt +++ b/src/main/kotlin/com/fwdekker/randomness/Bundle.kt @@ -38,7 +38,7 @@ object Bundle { * @throws java.util.MissingFormatArgumentException if [args] has fewer arguments than required for [format] */ fun String.matchesFormat(format: String, vararg args: String) = - Regex("%[0-9]+\\\$[Ss]").findAll(format) + Regex("%[0-9]+\\\$[Ssd]").findAll(format) .toList() .reversed() .fold(format) { acc, match -> diff --git a/src/main/kotlin/com/fwdekker/randomness/SchemeEditor.kt b/src/main/kotlin/com/fwdekker/randomness/SchemeEditor.kt index 73af73a92..7f0f421e1 100644 --- a/src/main/kotlin/com/fwdekker/randomness/SchemeEditor.kt +++ b/src/main/kotlin/com/fwdekker/randomness/SchemeEditor.kt @@ -76,5 +76,5 @@ abstract class SchemeEditor(val scheme: S) : Disposable { /** * Disposes this editor's resources. */ - override fun dispose() = Disposer.dispose(this) + override fun dispose() = decoratorEditors.forEach { Disposer.dispose(it) } } diff --git a/src/main/kotlin/com/fwdekker/randomness/Settings.kt b/src/main/kotlin/com/fwdekker/randomness/Settings.kt index 420bfb784..74785bfc0 100644 --- a/src/main/kotlin/com/fwdekker/randomness/Settings.kt +++ b/src/main/kotlin/com/fwdekker/randomness/Settings.kt @@ -8,6 +8,7 @@ import com.intellij.openapi.components.SettingsCategory import com.intellij.openapi.components.Storage import com.intellij.openapi.components.service import com.intellij.util.xmlb.XmlSerializer +import com.intellij.util.xmlb.annotations.OptionTag import com.intellij.util.xmlb.annotations.Transient import org.jdom.Element import java.lang.module.ModuleDescriptor @@ -22,7 +23,8 @@ import com.intellij.openapi.components.State as JBState */ data class Settings( var version: String = CURRENT_VERSION, - var templateList: TemplateList = TemplateList(), + @OptionTag + val templateList: TemplateList = TemplateList(), ) : State() { /** * @see TemplateList.templates @@ -31,19 +33,25 @@ data class Settings( val templates: MutableList