From 62d5ef62f0812fc52e698e662230f79c657704c8 Mon Sep 17 00:00:00 2001 From: "Florine W. Dekker" Date: Sat, 16 Sep 2023 14:51:08 +0200 Subject: [PATCH] Finalise full test rewrite --- .config/detekt/.detekt.yml | 9 +- README.md | 2 +- .../kotlin/com/fwdekker/randomness/Bundle.kt | 15 ++- .../com/fwdekker/randomness/SchemeEditor.kt | 5 +- .../randomness/decimal/DecimalScheme.kt | 2 +- .../fwdekker/randomness/template/Template.kt | 2 +- .../template/TemplateActionLoader.kt | 62 ++++------ .../randomness/template/TemplateActions.kt | 10 +- .../randomness/template/TemplateJTree.kt | 8 +- .../randomness/template/TemplateJTreeModel.kt | 23 ++-- .../template/TemplateListConfigurable.kt | 3 +- .../randomness/template/TemplateListEditor.kt | 6 +- .../randomness/template/TemplateReference.kt | 2 +- .../fwdekker/randomness/ui/JDateTimeField.kt | 2 +- .../fwdekker/randomness/ui/JNumberSpinners.kt | 1 - .../fwdekker/randomness/ui/PreviewPanel.kt | 2 +- .../randomness/word/WordSchemeEditor.kt | 2 +- src/main/resources/META-INF/plugin.xml | 3 +- .../com/fwdekker/randomness/AssertJHelper.kt | 10 +- .../com/fwdekker/randomness/BundleTest.kt | 11 +- .../kotlin/com/fwdekker/randomness/Dummies.kt | 3 +- .../{DummiesTest.kt => DummySchemeTest.kt} | 0 .../fwdekker/randomness/EditorTestFactory.kt | 21 ++-- .../com/fwdekker/randomness/IconsTest.kt | 13 ++- .../fwdekker/randomness/InsertActionTest.kt | 4 +- .../com/fwdekker/randomness/Matchers.kt | 2 +- .../fwdekker/randomness/SchemeEditorTest.kt | 11 +- .../com/fwdekker/randomness/SchemeTest.kt | 6 +- .../affix/AffixDecoratorEditorTest.kt | 17 +++ .../array/ArrayDecoratorEditorTest.kt | 8 +- .../randomness/array/ArrayDecoratorTest.kt | 10 +- .../randomness/datetime/DateTimeSchemeTest.kt | 8 +- .../decimal/DecimalSchemeEditorTest.kt | 20 ++-- .../randomness/decimal/DecimalSchemeTest.kt | 5 +- .../fixedlength/FixedLengthDecoratorTest.kt | 2 +- .../integer/IntegerSchemeEditorTest.kt | 12 +- .../randomness/integer/IntegerSchemeTest.kt | 7 +- .../randomness/string/StringSchemeTest.kt | 4 +- .../template/TemplateActionLoaderTest.kt | 40 ++++--- .../template/TemplateActionTests.kt | 17 +-- .../randomness/template/TemplateEditorTest.kt | 51 ++------ .../template/TemplateJTreeModelTest.kt | 109 +++++++++--------- .../randomness/template/TemplateJTreeTest.kt | 83 +++++++------ .../template/TemplateReferenceEditorTest.kt | 13 ++- .../template/TemplateReferenceTest.kt | 33 +++--- .../randomness/template/TemplateTest.kt | 25 ++-- .../randomness/ui/JDateTimeFieldTest.kt | 39 ++++--- .../randomness/ui/ListenerHelperTest.kt | 45 +------- .../randomness/uuid/UuidSchemeEditorTest.kt | 29 +++-- .../randomness/word/WordSchemeEditorTest.kt | 5 +- 50 files changed, 408 insertions(+), 414 deletions(-) rename src/test/kotlin/com/fwdekker/randomness/{DummiesTest.kt => DummySchemeTest.kt} (100%) create mode 100644 src/test/kotlin/com/fwdekker/randomness/affix/AffixDecoratorEditorTest.kt diff --git a/.config/detekt/.detekt.yml b/.config/detekt/.detekt.yml index 49b6da2b0..ed3f4c87c 100644 --- a/.config/detekt/.detekt.yml +++ b/.config/detekt/.detekt.yml @@ -16,6 +16,9 @@ complexity: # [False Positive] Solved using resource bundles. All remaining duplicates are resource identifiers. StringLiteralDuplication: active: false + # [Exception] Acceptable for helper files. + TooManyFunctions: + excludes: '**/*Helper.kt' formatting: # [Disagree] Acceptable for many short arguments. @@ -39,6 +42,9 @@ formatting: # [Disagree] Consecutive blank lines are used consistently to group blocks of code. NoConsecutiveBlankLines: active: false + # [Disagree] Required for lists and varargs, but ugly when it is unlikely that the function signature will change. + TrailingCommaOnCallSite: + active: false potential-bugs: # [Exception] Initialised by scene builder. @@ -63,8 +69,7 @@ style: active: false # [Exception] Acceptable in (parameterized) tests. DestructuringDeclarationWithTooManyEntries: - excludes: - - '**/test/**' + excludes: '**/test/**' # [Bug] Fails when used as function expression body. MultilineRawStringIndentation: active: false diff --git a/README.md b/README.md index e349f9ccc..4f286dad6 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ See [Plugin Signing](https://plugins.jetbrains.com/docs/intellij/plugin-signing. ### 🧪 Quality assurance ```bash $ gradlew test # Run tests -$ gradlew test --tests X # Run tests in class X +$ gradlew test --tests X # Run tests in class X (package name optional) $ gradlew check # Run tests and static analysis $ gradlew runPluginVerifier # Check for compatibility issues ``` diff --git a/src/main/kotlin/com/fwdekker/randomness/Bundle.kt b/src/main/kotlin/com/fwdekker/randomness/Bundle.kt index 3dbede3a3..93c29a90a 100644 --- a/src/main/kotlin/com/fwdekker/randomness/Bundle.kt +++ b/src/main/kotlin/com/fwdekker/randomness/Bundle.kt @@ -42,6 +42,17 @@ object Bundle { * * @throws java.util.MissingFormatArgumentException if [args] has fewer arguments than required for [format] */ -// TODO: Simplify documentation everywhere throughout the project to remove redundant `@param` specifications fun String.matchesFormat(format: String, vararg args: String) = - Regex(format.format(*args).replace(Regex("%[0-9]+\\\$[Ss]"), ".*")).matches(this) + // TODO: Simplify documentation everywhere throughout the project to remove redundant `@param` specifications + Regex("%[0-9]+\\\$[Ss]").findAll(format) + .toList() + .reversed() + .fold(format) { acc, match -> + if (match.value.drop(1).dropLast(2).toInt() > args.size) + acc.replaceRange(match.range, ".*") + else + acc + } + .format(*args) + .let { Regex(it) } + .matches(this) diff --git a/src/main/kotlin/com/fwdekker/randomness/SchemeEditor.kt b/src/main/kotlin/com/fwdekker/randomness/SchemeEditor.kt index c9cfebf60..12b3e4302 100644 --- a/src/main/kotlin/com/fwdekker/randomness/SchemeEditor.kt +++ b/src/main/kotlin/com/fwdekker/randomness/SchemeEditor.kt @@ -11,7 +11,7 @@ import javax.swing.JComponent * An editor for a [Scheme]. * * @param S the type of scheme edited in this editor - * @param scheme the scheme edited in this editor + * @property scheme the scheme edited in this editor */ abstract class SchemeEditor(val scheme: S) : Disposable { /** @@ -70,12 +70,13 @@ abstract class SchemeEditor(val scheme: S) : Disposable { * * @param listener the function to invoke on every change in this editor */ + @Suppress("detekt:SpreadOperator") // Acceptable because this method is called rarely fun addChangeListener(listener: () -> Unit) = addChangeListenerTo(*(components + decoratorEditors).toTypedArray(), listener = listener) /** - * Disposes of this editor's resources. + * Disposes this editor's resources. */ override fun dispose() = Disposer.dispose(this) } diff --git a/src/main/kotlin/com/fwdekker/randomness/decimal/DecimalScheme.kt b/src/main/kotlin/com/fwdekker/randomness/decimal/DecimalScheme.kt index 948d9d49d..dc08601b3 100644 --- a/src/main/kotlin/com/fwdekker/randomness/decimal/DecimalScheme.kt +++ b/src/main/kotlin/com/fwdekker/randomness/decimal/DecimalScheme.kt @@ -130,7 +130,7 @@ data class DecimalScheme( /** * The default value of the [showTrailingZeroes] field. */ - const val DEFAULT_SHOW_TRAILING_ZEROES = true + const val DEFAULT_SHOW_TRAILING_ZEROES = false /** * The preset values for the [decimalSeparator] field. diff --git a/src/main/kotlin/com/fwdekker/randomness/template/Template.kt b/src/main/kotlin/com/fwdekker/randomness/template/Template.kt index cf533be33..3cf3917cc 100644 --- a/src/main/kotlin/com/fwdekker/randomness/template/Template.kt +++ b/src/main/kotlin/com/fwdekker/randomness/template/Template.kt @@ -37,7 +37,7 @@ data class Template( WordScheme::class, ] ) - val schemes: MutableList = DEFAULT_SCHEMES, + var schemes: MutableList = DEFAULT_SCHEMES, val arrayDecorator: ArrayDecorator = DEFAULT_ARRAY_DECORATOR, ) : Scheme() { override val typeIcon diff --git a/src/main/kotlin/com/fwdekker/randomness/template/TemplateActionLoader.kt b/src/main/kotlin/com/fwdekker/randomness/template/TemplateActionLoader.kt index 4e2df455d..cbbfc5e3f 100644 --- a/src/main/kotlin/com/fwdekker/randomness/template/TemplateActionLoader.kt +++ b/src/main/kotlin/com/fwdekker/randomness/template/TemplateActionLoader.kt @@ -6,22 +6,20 @@ import com.intellij.openapi.actionSystem.impl.DynamicActionConfigurationCustomiz /** - * Registers and unregisters actions for the user's [Template]s so that they can be inserted using shortcuts. + * Registers, replaces, and unregisters actions for the user's [Template]s so that they can be inserted using shortcuts. + * + * @property getTemplates shorthand to return all the user's stored [Template]s */ -class TemplateActionLoader : DynamicActionConfigurationCustomizer { - /** - * Shorthand to return all the user's stored [Template]s. - */ - private val templates: List