diff --git a/build.gradle.kts b/build.gradle.kts index 38f831241..50e9196ca 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,6 @@ import dev.detekt.gradle.Detekt import dev.detekt.gradle.extensions.DetektExtension import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent -import org.gradle.kotlin.dsl.withType plugins { alias(libs.plugins.kotlin.jvm) @@ -46,12 +45,13 @@ dependencies { kover(project(kotestModule)) } -dokka { - moduleName.set("ReadingBat") - pluginsConfiguration.html { - homepageLink.set(repoUrl) - footerMessage.set(projectName) - } +// Dokka config is root-level (aggregate docs); the plugin is applied via the plugins {} block +// above. It can't go in allprojects {} — subprojects don't have the Dokka plugin applied until +// the subprojects {} block below runs, so the `dokka` extension wouldn't exist yet there. +configureDokka() + +allprojects { + configureVersions() } subprojects { @@ -68,7 +68,6 @@ subprojects { configureKotlinter() configureDetekt() configureSecrets() - configureVersions() } fun Project.configureKotlin() { @@ -83,6 +82,15 @@ fun Project.configureKotlin() { kotlin { jvmToolchain(jvmTargetVersion.toInt()) + // Collection literals (`val x: List = [1, 2, 3]`) are an experimental Kotlin 2.4 + // feature gated behind this flag. Removing it breaks every `[...]` literal in the + // sources. Note this flag applies to project sources only -- it is NOT in effect for + // the JSR-223 script engine that evaluates the content DSL at runtime, so DSL content + // files must keep using listOf()/mutableListOf(). + compilerOptions { + freeCompilerArgs.add("-Xcollection-literals") + } + sourceSets.all { listOf( "kotlin.ExperimentalStdlibApi", @@ -202,6 +210,16 @@ fun Project.configureTesting() { } } +fun Project.configureDokka() { + dokka { + moduleName.set("ReadingBat") + pluginsConfiguration.html { + homepageLink.set(repoUrl) + footerMessage.set(projectName) + } + } +} + fun Project.configureVersions() { // A pre-release qualifier is a `.` or `-` delimiter followed by a known unstable // keyword. `m\d` matches milestones (`-M1`/`.M2`) without catching stable classifiers diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 23057f0f4..0697cb738 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,24 +6,24 @@ jvm = "17" # Plugin versions buildconfig = "6.0.10" detekt = "2.0.0-alpha.5" -kotlin = "2.4.0" -kotlinter = "5.5.0" -kover = "0.9.8" +kotlin = "2.4.10" +kotlinter = "5.6.0" +kover = "0.9.9" dokka = "2.2.0" maven-publish = "0.37.0" versions = "0.54.0" # Library versions -cloud = "1.28.6" +cloud = "1.29.0" commons = "1.15.0" exposed = "1.3.1" flexmark = "0.64.8" -flyway = "12.11.0" +flyway = "13.0.0" github-api = "1.330" hikari = "7.1.0" java-scriptengine = "2.0.0" khealth = "3.0.1" -kotest = "6.2.2" +kotest = "6.2.3" ktor = "3.5.1" logback = "1.5.38" logging = "7.0.12" @@ -31,12 +31,12 @@ pgjdbc = "0.8.9" playwright = "1.61.0" postgres = "42.7.13" prometheus = "0.16.0" -prometheus-proxy = "3.2.0" +prometheus-proxy = "4.0.0" python = "2.7.4" resend = "4.13.0" serialization = "1.11.0" testcontainers = "1.21.4" -utils = "3.1.0" +utils = "3.2.1" [libraries] # Serialization diff --git a/readingbat-core/src/main/kotlin/com/readingbat/common/FunctionInfo.kt b/readingbat-core/src/main/kotlin/com/readingbat/common/FunctionInfo.kt index ceab37503..b498c4678 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/common/FunctionInfo.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/common/FunctionInfo.kt @@ -289,7 +289,7 @@ class FunctionInfo( */ internal fun splitTopLevelCommas(csv: String): List { if (csv.isBlank()) return emptyList() - val elements = mutableListOf() + val elements: MutableList = [] val current = StringBuilder() var quoteChar: Char? = null for (c in csv) { diff --git a/readingbat-core/src/main/kotlin/com/readingbat/common/Metrics.kt b/readingbat-core/src/main/kotlin/com/readingbat/common/Metrics.kt index 5d4da0dab..cc4b7dac5 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/common/Metrics.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/common/Metrics.kt @@ -199,80 +199,80 @@ class Metrics { SamplerGaugeCollector( "request_timing_map_size", "Request timing map size", - labelNames = listOf(AGENT_ID), - labelValues = listOf(agentLaunchId()), + labelNames = [AGENT_ID], + labelValues = [agentLaunchId()], data = { requestTimingMap.size.toDouble() }, ) SamplerGaugeCollector( "geo_map_size", "IP Geo map size", - labelNames = listOf(AGENT_ID), - labelValues = listOf(agentLaunchId()), + labelNames = [AGENT_ID], + labelValues = [agentLaunchId()], data = { geoInfoMap.size.toDouble() }, ) SamplerGaugeCollector( "content_map_size", "Content map size", - labelNames = listOf(AGENT_ID), - labelValues = listOf(agentLaunchId()), + labelNames = [AGENT_ID], + labelValues = [agentLaunchId()], data = { contentSource().contentMap.size.toDouble() }, ) SamplerGaugeCollector( "user_id_cache_size", "User ID cache size", - labelNames = listOf(AGENT_ID), - labelValues = listOf(agentLaunchId()), + labelNames = [AGENT_ID], + labelValues = [agentLaunchId()], data = { userIdCache.size.toDouble() }, ) SamplerGaugeCollector( "user_email_cache_size", "User email cache size size", - labelNames = listOf(AGENT_ID), - labelValues = listOf(agentLaunchId()), + labelNames = [AGENT_ID], + labelValues = [agentLaunchId()], data = { emailCache.size.toDouble() }, ) SamplerGaugeCollector( "sources_cache_size", "Sources cache size", - labelNames = listOf(AGENT_ID), - labelValues = listOf(agentLaunchId()), + labelNames = [AGENT_ID], + labelValues = [agentLaunchId()], data = { contentSource().functionInfoMap.size.toDouble() }, ) SamplerGaugeCollector( "websocket_connection_list_size", "Websocket connection list size", - labelNames = listOf(AGENT_ID), - labelValues = listOf(agentLaunchId()), + labelNames = [AGENT_ID], + labelValues = [agentLaunchId()], data = { answerWsConnections.size.toDouble() }, ) SamplerGaugeCollector( "active_users_1min_count", "Active users in last 1 min count", - labelNames = listOf(AGENT_ID), - labelValues = listOf(agentLaunchId()), + labelNames = [AGENT_ID], + labelValues = [agentLaunchId()], data = { activeSessions(1.minutes).toDouble() }, ) SamplerGaugeCollector( "active_users_15mins_count", "Active users in last 15 mins count", - labelNames = listOf(AGENT_ID), - labelValues = listOf(agentLaunchId()), + labelNames = [AGENT_ID], + labelValues = [agentLaunchId()], data = { activeSessions(15.minutes).toDouble() }, ) SamplerGaugeCollector( "active_users_60mins_count", "Active users in last 60 mins count", - labelNames = listOf(AGENT_ID), - labelValues = listOf(agentLaunchId()), + labelNames = [AGENT_ID], + labelValues = [agentLaunchId()], data = { activeSessions(1.hours).toDouble() }, ) } diff --git a/readingbat-core/src/main/kotlin/com/readingbat/common/Property.kt b/readingbat-core/src/main/kotlin/com/readingbat/common/Property.kt index 3cd589afa..376cfe39d 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/common/Property.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/common/Property.kt @@ -133,7 +133,7 @@ open class KtorProperty( companion object { private val logger = KotlinLogging.logger {} private val initialized = AtomicBoolean(false) - private val instances = mutableListOf() + private val instances: MutableList = [] internal val configStore = java.util.concurrent.ConcurrentHashMap() // Names of properties that have individually had a value assigned via setProperty. Lets the @@ -466,7 +466,7 @@ sealed class Property( /** Returns the ordered list of properties that should be initialized at application startup. */ fun initProperties() = - listOf( + [ DSL_FILE_NAME, DSL_VARIABLE_NAME, PROXY_HOSTNAME, @@ -503,6 +503,6 @@ sealed class Property( GOOGLE_OAUTH_CLIENT_ID, GOOGLE_OAUTH_CLIENT_SECRET, SESSION_SECRET, - ) + ] } } diff --git a/readingbat-core/src/main/kotlin/com/readingbat/dsl/ChallengeGroup.kt b/readingbat-core/src/main/kotlin/com/readingbat/dsl/ChallengeGroup.kt index 62aeec4c0..0e1c911e3 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/dsl/ChallengeGroup.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/dsl/ChallengeGroup.kt @@ -67,7 +67,7 @@ class ChallengeGroup( internal val groupNameSuffix: GroupName, ) { /** The ordered list of challenges in this group. */ - val challenges = mutableListOf() + val challenges: MutableList = [] private val groupPrefix by lazy { pathOf(languageName, groupName) } private val srcPath get() = languageGroup.srcPath @@ -149,7 +149,7 @@ class ChallengeGroup( var includeFilesWithType by IncludeFilesWithType(this, languageType) private class IncludeFiles(val group: ChallengeGroup, val languageType: LanguageType) { - val includeList = mutableListOf() + val includeList: MutableList = [] operator fun getValue(thisRef: Any?, property: KProperty<*>) = includeList.toString() @@ -166,7 +166,7 @@ class ChallengeGroup( } private class IncludeFilesWithType(val group: ChallengeGroup, val languageType: LanguageType) { - val includeList = mutableListOf() + val includeList: MutableList = [] operator fun getValue(thisRef: Any?, property: KProperty<*>): PatternReturnType = PatternReturnType("", Runtime) diff --git a/readingbat-core/src/main/kotlin/com/readingbat/dsl/ContentDsl.kt b/readingbat-core/src/main/kotlin/com/readingbat/dsl/ContentDsl.kt index 36696f675..1cddc6f49 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/dsl/ContentDsl.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/dsl/ContentDsl.kt @@ -198,7 +198,7 @@ internal fun evalContentDsl( */ internal fun addImports(code: String, variableName: String): String { val classImports = - listOf(ReadingBatServer::class, GitHubContent::class) + [ReadingBatServer::class, GitHubContent::class] // .onEach { println("Checking for ${it.javaObjectType.name}") } .filter { code.contains("${it.javaObjectType.simpleName}(") } // See if the class is referenced .map { "import ${it.javaObjectType.name}" } // Convert to import stmt @@ -206,14 +206,14 @@ internal fun addImports(code: String, variableName: String): String { .joinToString("\n") // Turn into String val funcImports = - listOf(::readingBatContent) + [::readingBatContent] // .onEach { println("Checking for ${it.name}") } .filter { code.contains("${it.name}(") } // See if the function is referenced .map { "import ${it.fqMethodName}" } // Convert to import stmt .filterNot { code.contains(it) } // Do not include is import already present .joinToString("\n") // Turn into String - val imports = listOf(classImports, funcImports).filter { it.isNotBlank() }.joinToString("\n") + val imports = [classImports, funcImports].filter { it.isNotBlank() }.joinToString("\n") return """ $imports${if (imports.isBlank()) "" else "\n\n"}$code $variableName diff --git a/readingbat-core/src/main/kotlin/com/readingbat/dsl/LanguageGroup.kt b/readingbat-core/src/main/kotlin/com/readingbat/dsl/LanguageGroup.kt index f202c4726..b7adf80b7 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/dsl/LanguageGroup.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/dsl/LanguageGroup.kt @@ -48,7 +48,7 @@ class LanguageGroup( val contentRoot get() = languageType.contentRoot /** The ordered list of challenge groups in this language. */ - val challengeGroups = mutableListOf>() + val challengeGroups: MutableList> = [] /** * The content source for this language's challenge files. Inherits the parent diff --git a/readingbat-core/src/main/kotlin/com/readingbat/dsl/LanguageType.kt b/readingbat-core/src/main/kotlin/com/readingbat/dsl/LanguageType.kt index d27f15865..1efead6c1 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/dsl/LanguageType.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/dsl/LanguageType.kt @@ -47,7 +47,7 @@ enum class LanguageType(val useDoubleQuotes: Boolean, val suffix: String, val sr companion object { val defaultLanguageType = Java - val languageTypeList = listOf(Java, Python, Kotlin) + val languageTypeList = [Java, Python, Kotlin] /** Returns all language types, optionally reordered to put [defaultLanguage] first. */ fun languageTypes(defaultLanguage: LanguageType? = null): List = diff --git a/readingbat-core/src/main/kotlin/com/readingbat/dsl/ReadingBatContent.kt b/readingbat-core/src/main/kotlin/com/readingbat/dsl/ReadingBatContent.kt index a5dc884c7..e2312d59c 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/dsl/ReadingBatContent.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/dsl/ReadingBatContent.kt @@ -77,7 +77,7 @@ import kotlin.time.measureTimedValue @ReadingBatDslMarker class ReadingBatContent { internal val timeStamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("M/d/y H:m:ss")) - private val languageList by lazy { listOf(java, python, kotlin) } + private val languageList by lazy { [java, python, kotlin] } private val languageMap by lazy { languageList.associateBy { it.languageType } } // contentMap will prevent reading the same content multiple times @@ -96,7 +96,7 @@ class ReadingBatContent { /** Language group for Kotlin challenges. Accessible in the DSL as a property or block receiver. */ val kotlin by lazy { LanguageGroup(this, Kotlin) } - val languages by lazy { listOf(python, java, kotlin) } + val languages by lazy { [python, java, kotlin] } val cacheChallenges get() = isProduction() || isTesting() diff --git a/readingbat-core/src/main/kotlin/com/readingbat/dsl/challenge/Challenge.kt b/readingbat-core/src/main/kotlin/com/readingbat/dsl/challenge/Challenge.kt index 46cda8ba6..9e43773df 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/dsl/challenge/Challenge.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/dsl/challenge/Challenge.kt @@ -95,7 +95,6 @@ sealed class Challenge( // Allow description updates only if not found in the Content.kt decl private val isDescriptionSetInDsl by lazy { description.isNotBlank() } - internal val gitpodUrl by lazy { pathOf(repo.sourcePrefix, "blob/$branchName", srcPath, fqName) } internal val parsedDescription by lazy { MarkdownParser.toHtml(description) } internal val path by lazy { pathOf(languageName, groupName, challengeName) } @@ -308,7 +307,7 @@ class KotlinChallenge( val funcCode = "\n${extractKotlinFunction(lines)}\n\n" val invocations = extractKotlinInvocations(lines, KotlinParse.funMainRegex, KotlinParse.kotlinEndRegex) val script = convertToKotlinScript(lines).also { logger.debug { "Kotlin: $it" } } - val correctAnswers = mutableListOf() + val correctAnswers: MutableList = [] logger.debug { "$challengeName return type: $returnType script: \n${script.withLineNumbers()}" } @@ -360,7 +359,7 @@ class PythonChallenge( val funcCode = extractPythonFunction(lines) val invocations = extractPythonInvocations(lines, PythonParse.defMainRegex, PythonParse.ifMainEndRegex) val script = convertToPythonScript(lines) - val correctAnswers = mutableListOf() + val correctAnswers: MutableList = [] logger.debug { "$challengeName return type: $returnType script: \n${script.withLineNumbers()}" } diff --git a/readingbat-core/src/main/kotlin/com/readingbat/dsl/parse/JavaParse.kt b/readingbat-core/src/main/kotlin/com/readingbat/dsl/parse/JavaParse.kt index 1231b91ea..c4aa8a918 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/dsl/parse/JavaParse.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/dsl/parse/JavaParse.kt @@ -48,15 +48,15 @@ internal object JavaParse { internal val svmRegex = Regex("""\s*static\s+void\s+main\(""") private val prefixRegex = - listOf( + [ Regex("""System\.out\.println\("""), Regex("""ArrayUtils\.arrayPrint\("""), Regex("""ListUtils\.listPrint\("""), Regex("""arrayPrint\("""), Regex("""listPrint\("""), - ) + ] private val prefixes = - listOf("System.out.println", "ArrayUtils.arrayPrint", "ListUtils.listPrint", "arrayPrint", "listPrint") + ["System.out.println", "ArrayUtils.arrayPrint", "ListUtils.listPrint", "arrayPrint", "listPrint"] /** * Derives the return type of a Java challenge function by locating the first `static` method diff --git a/readingbat-core/src/main/kotlin/com/readingbat/pages/ChallengePage.kt b/readingbat-core/src/main/kotlin/com/readingbat/pages/ChallengePage.kt index 12cd8a7a0..50c9f8407 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/pages/ChallengePage.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/pages/ChallengePage.kt @@ -706,11 +706,9 @@ internal object ChallengePage { val groupName = challenge.groupName val challengeName = challenge.challengeName - p(classes = TwClasses.EXPERIMENT) { - +"Experiment with this code on " - this@otherLinks.addLink("Gitpod.io", "https://gitpod.io/#${challenge.gitpodUrl}", true) - if (languageType.isKotlin) { - +" or as a " + if (languageType.isKotlin) { + p(classes = TwClasses.EXPERIMENT) { + +"Experiment with this code as a " this@otherLinks.addLink("Kotlin Playground", pathOf(PLAYGROUND_ROOT, groupName, challengeName), false) } } diff --git a/readingbat-core/src/main/kotlin/com/readingbat/pages/HelpAndLogin.kt b/readingbat-core/src/main/kotlin/com/readingbat/pages/HelpAndLogin.kt index 8cc3843c2..ea3fa0d3a 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/pages/HelpAndLogin.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/pages/HelpAndLogin.kt @@ -56,7 +56,7 @@ import kotlinx.html.tr * (about, help, admin, prefs), teacher/student mode toggle, and the OAuth sign-in modal. */ internal object HelpAndLogin { - private val rootVals = listOf("", "/") + private val rootVals = ["", "/"] // Google "G" logo — official colors, 18x18 @Suppress("ktlint:standard:max-line-length") diff --git a/readingbat-core/src/main/kotlin/com/readingbat/pages/LanguageGroupPage.kt b/readingbat-core/src/main/kotlin/com/readingbat/pages/LanguageGroupPage.kt index 098e020fe..a9f43fb52 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/pages/LanguageGroupPage.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/pages/LanguageGroupPage.kt @@ -124,7 +124,7 @@ internal object LanguageGroupPage { head { headDefault() } body { - val oauthError = queryParam(OAUTH_ERROR).takeIf { it in listOf("github", "google") } ?: "" + val oauthError = queryParam(OAUTH_ERROR).takeIf { it in ["github", "google"] } ?: "" val msg = if (oauthError.isNotBlank()) Message("Sign-in with ${oauthError.toCapitalized()} failed. Please try again.", isError = true) diff --git a/readingbat-core/src/main/kotlin/com/readingbat/pages/PageUtils.kt b/readingbat-core/src/main/kotlin/com/readingbat/pages/PageUtils.kt index 8b123687c..56c946d3e 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/pages/PageUtils.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/pages/PageUtils.kt @@ -324,7 +324,7 @@ internal object PageUtils { fun BODY.displayMessage(msg: Message) = if (msg.isNotBlank) +(msg.toString()) else rawHtml(nbsp.text) - private val rootVals = listOf("", "/", Java.contentRoot, Python.contentRoot, Kotlin.contentRoot) + private val rootVals = ["", "/", Java.contentRoot, Python.contentRoot, Kotlin.contentRoot] fun BODY.backLink(vararg pathElems: String = arrayOf("/")) { if (pathElems.size == 1 && pathElems[0] in rootVals) diff --git a/readingbat-core/src/main/kotlin/com/readingbat/pages/SessionsPage.kt b/readingbat-core/src/main/kotlin/com/readingbat/pages/SessionsPage.kt index effaf361e..dbbe483a4 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/pages/SessionsPage.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/pages/SessionsPage.kt @@ -72,13 +72,13 @@ internal object SessionsPage { h2 { +"ReadingBat Sessions" } val activeUserCounts = - listOf( + [ 1.minutes to "minute", 15.minutes to "15 minutes", 1.hours to "hour", 24.hours to "24 hours", 7.days to "week", - ) + ] .map { (duration, label) -> label to activeSessions(duration) } h3 { +"Active Users" } diff --git a/readingbat-core/src/main/kotlin/com/readingbat/pages/SystemConfigurationPage.kt b/readingbat-core/src/main/kotlin/com/readingbat/pages/SystemConfigurationPage.kt index 58c805660..5f9aa4c3c 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/pages/SystemConfigurationPage.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/pages/SystemConfigurationPage.kt @@ -166,13 +166,13 @@ internal object SystemConfigurationPage { h3 { +"System Maps" } div(classes = TwClasses.INDENT_1EM) { table { - listOf( + [ "Request timing map size" to requestTimingMap, "IP Geo map size" to geoInfoMap, "Content map size" to content.contentMap, "User ID cache size" to userIdCache, "User email cache size" to emailCache, - ) + ] .forEach { tr { td { +it.first } diff --git a/readingbat-core/src/main/kotlin/com/readingbat/posts/ChallengePost.kt b/readingbat-core/src/main/kotlin/com/readingbat/posts/ChallengePost.kt index 70a02db43..7f9e9d0bc 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/posts/ChallengePost.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/posts/ChallengePost.kt @@ -130,7 +130,7 @@ data class ChallengeHistory( var invocation: Invocation, var correct: Boolean = false, var incorrectAttempts: Int = 0, - @Required val answers: MutableList = mutableListOf(), + @Required val answers: MutableList = [], ) { fun markCorrect(userResponse: String) { correct = true diff --git a/readingbat-core/src/main/kotlin/com/readingbat/server/ConfigureOAuth.kt b/readingbat-core/src/main/kotlin/com/readingbat/server/ConfigureOAuth.kt index 73d443bb4..afd83d312 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/server/ConfigureOAuth.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/server/ConfigureOAuth.kt @@ -82,7 +82,7 @@ internal object ConfigureOAuth { requestMethod = HttpMethod.Post, clientId = clientId, clientSecret = clientSecret, - defaultScopes = listOf("user:email"), + defaultScopes = ["user:email"], ) } client = httpClient @@ -115,7 +115,7 @@ internal object ConfigureOAuth { requestMethod = HttpMethod.Post, clientId = clientId, clientSecret = clientSecret, - defaultScopes = listOf("openid", "profile", "email"), + defaultScopes = ["openid", "profile", "email"], ) } client = httpClient diff --git a/readingbat-core/src/main/kotlin/com/readingbat/server/GeoInfo.kt b/readingbat-core/src/main/kotlin/com/readingbat/server/GeoInfo.kt index 8ba0b09fb..ebf3061b1 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/server/GeoInfo.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/server/GeoInfo.kt @@ -91,7 +91,7 @@ class GeoInfo(val requireDbmsLookUp: Boolean, val dbmsId: Long, val remoteHost: fun summary() = if (valid) try { - listOf(city, state_prov, country_name, organization).joinToString(", ") + [city, state_prov, country_name, organization].joinToString(", ") } catch (_: NoSuchElementException) { "Missing Geo data" } diff --git a/readingbat-core/src/main/kotlin/com/readingbat/server/Installs.kt b/readingbat-core/src/main/kotlin/com/readingbat/server/Installs.kt index 57734b8ed..9f8bc4c9b 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/server/Installs.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/server/Installs.kt @@ -87,7 +87,7 @@ import kotlin.time.Duration.Companion.seconds */ object Installs { private val logger = KotlinLogging.logger {} - private val excludedEndpoints = listOf("/$STATIC/", "$WS_ROOT/") + private val excludedEndpoints = ["/$STATIC/", "$WS_ROOT/"] /** * Paths excluded from rate limiting: static assets, WebSocket upgrades, and health pings. diff --git a/readingbat-core/src/main/kotlin/com/readingbat/server/Intercepts.kt b/readingbat-core/src/main/kotlin/com/readingbat/server/Intercepts.kt index ab088b408..daf929575 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/server/Intercepts.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/server/Intercepts.kt @@ -123,10 +123,10 @@ internal object Intercepts { ) val publicPrefixes = - listOf( + [ "$OAUTH_PREFIX/", "/$STATIC/", - ) + ] // Paths that must remain available before the DSL content has finished loading. // Anything else gets a 503 + ContentLoadingPage until ReadingBatServer.isContentReady is true. @@ -139,9 +139,9 @@ internal object Intercepts { ) val readinessAllowedPrefixes = - listOf( + [ "/$STATIC/", - ) + ] @Suppress("unused") val timer = diff --git a/readingbat-core/src/main/kotlin/com/readingbat/server/Locations.kt b/readingbat-core/src/main/kotlin/com/readingbat/server/Locations.kt index c881402fb..748407fe3 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/server/Locations.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/server/Locations.kt @@ -174,7 +174,7 @@ class PlaygroundRequest(val groupName: String, val challengeName: String) /** Inline value class wrapping a language name string (e.g., "java", "python", "kotlin"). */ @JvmInline value class LanguageName(val value: String) { - val isJvm get() = value in listOf("kotlin", "java") // jmvLanguages + val isJvm get() = value in ["kotlin", "java"] // jmvLanguages fun toLanguageType() = try { diff --git a/readingbat-core/src/main/kotlin/com/readingbat/server/PostgresTables.kt b/readingbat-core/src/main/kotlin/com/readingbat/server/PostgresTables.kt index 64b2c9637..4a9d4c39f 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/server/PostgresTables.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/server/PostgresTables.kt @@ -29,22 +29,22 @@ import org.jetbrains.exposed.v1.datetime.timestamp /** Unique index on (session_ref, user_ref) for the user_sessions table. */ val userSessionIndex = - Index(listOf(UserSessionsTable.sessionRef, UserSessionsTable.userRef), true, "user_sessions_unique") + Index([UserSessionsTable.sessionRef, UserSessionsTable.userRef], true, "user_sessions_unique") val userChallengeInfoIndex = - Index(listOf(UserChallengeInfoTable.userRef, UserChallengeInfoTable.md5), true, "user_challenge_info_unique") + Index([UserChallengeInfoTable.userRef, UserChallengeInfoTable.md5], true, "user_challenge_info_unique") val userAnswerHistoryIndex = Index( - listOf(UserAnswerHistoryTable.userRef, UserAnswerHistoryTable.md5, UserAnswerHistoryTable.invocation), + [UserAnswerHistoryTable.userRef, UserAnswerHistoryTable.md5, UserAnswerHistoryTable.invocation], true, "user_answer_history_unique", ) val oauthLinksProviderIndex = - Index(listOf(OAuthLinksTable.provider, OAuthLinksTable.providerId), true, "oauth_links_provider_unique") + Index([OAuthLinksTable.provider, OAuthLinksTable.providerId], true, "oauth_links_provider_unique") -val geoInfosUnique = Index(listOf(GeoInfosTable.ip), true, "geo_info_unique") +val geoInfosUnique = Index([GeoInfosTable.ip], true, "geo_info_unique") /** Tracks anonymous browser sessions identified by a random session ID cookie. */ object BrowserSessionsTable : LongIdTable("browser_sessions") { diff --git a/readingbat-core/src/main/kotlin/com/readingbat/server/routes/SysAdminRoutes.kt b/readingbat-core/src/main/kotlin/com/readingbat/server/routes/SysAdminRoutes.kt index 12ff7bcb6..2cf36f07b 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/server/routes/SysAdminRoutes.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/server/routes/SysAdminRoutes.kt @@ -98,11 +98,11 @@ fun Routing.sysAdminRoutes(metrics: Metrics, resetContentFunc: (String) -> Unit) } } - return listOf( + return [ deleteContentDslCache(), deleteSourceCodeCache(), deleteDirContentsCache(), - ).joinToString(", ") + ].joinToString(", ") } post(RESET_CONTENT_DSL_ENDPOINT, metrics) { diff --git a/readingbat-core/src/main/kotlin/com/readingbat/server/ws/ChallengeGroupWs.kt b/readingbat-core/src/main/kotlin/com/readingbat/server/ws/ChallengeGroupWs.kt index 12ac19a4f..9a8a8eb3f 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/server/ws/ChallengeGroupWs.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/server/ws/ChallengeGroupWs.kt @@ -106,7 +106,7 @@ internal object ChallengeGroupWs { if (enrollees.isNotEmpty()) { // Reorder challenges to return values left to right - val ltor = mutableListOf() + val ltor: MutableList = [] val rows = challenges.size.rows(Constants.COLUMN_CNT) repeat(rows) { i -> challenges diff --git a/readingbat-core/src/main/kotlin/com/readingbat/server/ws/ClassSummaryWs.kt b/readingbat-core/src/main/kotlin/com/readingbat/server/ws/ClassSummaryWs.kt index 0dbedea91..340da8aac 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/server/ws/ClassSummaryWs.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/server/ws/ClassSummaryWs.kt @@ -108,7 +108,7 @@ internal object ClassSummaryWs { for (enrollee in enrollees) { var incorrectAttempts = 0 - val results = mutableListOf() + val results: MutableList = [] for (invocation in funcInfo.invocations) { val historyMd5 = md5Of(langName, groupName, challengeName, invocation) if (enrollee.historyExists(historyMd5, invocation)) { diff --git a/readingbat-core/src/main/kotlin/com/readingbat/server/ws/PubSubCommandsWs.kt b/readingbat-core/src/main/kotlin/com/readingbat/server/ws/PubSubCommandsWs.kt index ebd6072f6..e98732a3a 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/server/ws/PubSubCommandsWs.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/server/ws/PubSubCommandsWs.kt @@ -62,10 +62,10 @@ internal object PubSubCommandsWs { @Transient val endPoint: String, val languageTypes: List, ) { - LOAD_JAVA(LOAD_JAVA_ENDPOINT, listOf(Java)), - LOAD_PYTHON(LOAD_PYTHON_ENDPOINT, listOf(Python)), - LOAD_KOTLIN(LOAD_KOTLIN_ENDPOINT, listOf(Kotlin)), - LOAD_ALL(LOAD_ALL_ENDPOINT, listOf(Java, Python, Kotlin)), + LOAD_JAVA(LOAD_JAVA_ENDPOINT, [Java]), + LOAD_PYTHON(LOAD_PYTHON_ENDPOINT, [Python]), + LOAD_KOTLIN(LOAD_KOTLIN_ENDPOINT, [Kotlin]), + LOAD_ALL(LOAD_ALL_ENDPOINT, [Java, Python, Kotlin]), ; fun toJson() = Json.encodeToString(serializer(), this) diff --git a/readingbat-core/src/main/kotlin/com/readingbat/server/ws/StudentSummaryWs.kt b/readingbat-core/src/main/kotlin/com/readingbat/server/ws/StudentSummaryWs.kt index 5e319b760..6233107e2 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/server/ws/StudentSummaryWs.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/server/ws/StudentSummaryWs.kt @@ -106,7 +106,7 @@ internal object StudentSummaryWs { var incorrectAttempts = 0 var attempted = 0 - val results = mutableListOf() + val results: MutableList = [] for (invocation in funcInfo.invocations) { val historyMd5 = md5Of(languageName, groupName, challengeName, invocation) if (student.historyExists(historyMd5, invocation)) { diff --git a/readingbat-core/src/main/kotlin/com/readingbat/utils/ScriptTest.kt b/readingbat-core/src/main/kotlin/com/readingbat/utils/ScriptTest.kt index ad922fd0e..0a7458309 100644 --- a/readingbat-core/src/main/kotlin/com/readingbat/utils/ScriptTest.kt +++ b/readingbat-core/src/main/kotlin/com/readingbat/utils/ScriptTest.kt @@ -52,7 +52,7 @@ fun main() { @Suppress("unused") fun javaTest() { - val correctAnswers = mutableListOf() + val correctAnswers: MutableList = [] val script = """ public class LessThan { @@ -97,7 +97,7 @@ fun javaTest() { @Suppress("unused") fun pythonTest() { - val correctAnswers = mutableListOf() + val correctAnswers: MutableList = [] val script = """ diff --git a/readingbat-core/src/test/kotlin/com/readingbat/common/AnswerHistoryBulkEquivalenceTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/common/AnswerHistoryBulkEquivalenceTest.kt index 844f5a13e..b1dabfcda 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/common/AnswerHistoryBulkEquivalenceTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/common/AnswerHistoryBulkEquivalenceTest.kt @@ -70,7 +70,7 @@ class AnswerHistoryBulkEquivalenceTest : StringSpec() { } } - val bulk = user.answerHistoryBulk(listOf("md5-a", "md5-b", "md5-c")) + val bulk = user.answerHistoryBulk(["md5-a", "md5-b", "md5-c"]) // Present for exactly the md5s with stored history (== historyExists), absent otherwise. bulk.keys shouldBe setOf("md5-a", "md5-b") diff --git a/readingbat-core/src/test/kotlin/com/readingbat/common/AnswerPublisherTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/common/AnswerPublisherTest.kt index f8b3384f1..1f5f4118e 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/common/AnswerPublisherTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/common/AnswerPublisherTest.kt @@ -30,11 +30,11 @@ class AnswerPublisherTest : StringSpec() { // The teacher dashboard renders this string via innerHTML over a WebSocket, so student // answers must be HTML-escaped to prevent stored XSS, while the
separators stay literal. "formatDashboardAnswers reverses, limits, and joins answers with
" { - AnswerPublisher.formatDashboardAnswers(listOf("a", "b", "c"), 2) shouldBe "c
b" + AnswerPublisher.formatDashboardAnswers(["a", "b", "c"], 2) shouldBe "c
b" } "formatDashboardAnswers leaves a plain answer unchanged" { - AnswerPublisher.formatDashboardAnswers(listOf("42"), 10) shouldBe "42" + AnswerPublisher.formatDashboardAnswers(["42"], 10) shouldBe "42" } "formatDashboardAnswers returns empty string for no answers" { @@ -42,13 +42,13 @@ class AnswerPublisherTest : StringSpec() { } "formatDashboardAnswers HTML-escapes a script-injection answer" { - val result = AnswerPublisher.formatDashboardAnswers(listOf(""), 10) + val result = AnswerPublisher.formatDashboardAnswers([""], 10) result shouldNotContainSubstring " separator literal between escaped answers" { - val result = AnswerPublisher.formatDashboardAnswers(listOf("x", "y"), 10) + val result = AnswerPublisher.formatDashboardAnswers(["x", "y"], 10) result shouldBe "<b>y
<b>x" } diff --git a/readingbat-core/src/test/kotlin/com/readingbat/common/PythonListTokenizerTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/common/PythonListTokenizerTest.kt index ff7611d56..4e1c1325b 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/common/PythonListTokenizerTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/common/PythonListTokenizerTest.kt @@ -30,15 +30,15 @@ import io.kotest.matchers.shouldBe class PythonListTokenizerTest : StringSpec() { init { "splitTopLevelCommas keeps commas inside single-quoted elements together" { - splitTopLevelCommas("'a,b', 'c'").map { it.trim() } shouldBe listOf("'a,b'", "'c'") + splitTopLevelCommas("'a,b', 'c'").map { it.trim() } shouldBe ["'a,b'", "'c'"] } "splitTopLevelCommas keeps commas inside double-quoted elements together" { - splitTopLevelCommas(""""a,b", "c"""").map { it.trim() } shouldBe listOf("\"a,b\"", "\"c\"") + splitTopLevelCommas(""""a,b", "c"""").map { it.trim() } shouldBe ["\"a,b\"", "\"c\""] } "splitTopLevelCommas splits unquoted top-level elements" { - splitTopLevelCommas("1, 2, 3").map { it.trim() } shouldBe listOf("1", "2", "3") + splitTopLevelCommas("1, 2, 3").map { it.trim() } shouldBe ["1", "2", "3"] } "splitTopLevelCommas returns an empty list for blank input" { diff --git a/readingbat-core/src/test/kotlin/com/readingbat/dsl/DirCacheTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/dsl/DirCacheTest.kt index e5c164496..fa7600e1f 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/dsl/DirCacheTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/dsl/DirCacheTest.kt @@ -30,14 +30,14 @@ import io.kotest.matchers.shouldBe class DirCacheTest : StringSpec() { init { "readDirCache returns what writeDirCache stored under a consistent key" { - ChallengeGroup.writeDirCache("java/Warmup-1", listOf("a.java", "b.java")) - ChallengeGroup.readDirCache("java/Warmup-1") shouldBe listOf("a.java", "b.java") + ChallengeGroup.writeDirCache("java/Warmup-1", ["a.java", "b.java"]) + ChallengeGroup.readDirCache("java/Warmup-1") shouldBe ["a.java", "b.java"] } "rewriting the dir cache overwrites instead of accumulating duplicates" { - ChallengeGroup.writeDirCache("python/Group-2", listOf("a.py")) - ChallengeGroup.writeDirCache("python/Group-2", listOf("a.py", "b.py")) - ChallengeGroup.readDirCache("python/Group-2") shouldBe listOf("a.py", "b.py") + ChallengeGroup.writeDirCache("python/Group-2", ["a.py"]) + ChallengeGroup.writeDirCache("python/Group-2", ["a.py", "b.py"]) + ChallengeGroup.readDirCache("python/Group-2") shouldBe ["a.py", "b.py"] } } } diff --git a/readingbat-core/src/test/kotlin/com/readingbat/dsl/IndicesFilterTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/dsl/IndicesFilterTest.kt index 9bb6718dd..5a04af5e0 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/dsl/IndicesFilterTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/dsl/IndicesFilterTest.kt @@ -29,7 +29,7 @@ class IndicesFilterTest : StringSpec() { init { "extractJavaFunction should find static method body" { val code = - listOf( + [ "import java.util.*;", "", "public class Warmup {", @@ -41,7 +41,7 @@ class IndicesFilterTest : StringSpec() { " System.out.println(sleepIn(false, false));", " }", "}", - ) + ] val result = extractJavaFunction(ChallengeName("sleepIn"), code) result shouldContain "sleepIn" result shouldContain "return !weekday || vacation" @@ -50,13 +50,13 @@ class IndicesFilterTest : StringSpec() { "extractPythonFunction should find def function body" { val code = - listOf( + [ "def sleep_in(weekday, vacation):", " return not weekday or vacation", "", "def main():", " print(sleep_in(False, False))", - ) + ] val result = extractPythonFunction(code) result shouldContain "sleep_in" result shouldContain "return not weekday or vacation" @@ -64,7 +64,7 @@ class IndicesFilterTest : StringSpec() { } "indices.filter produces same results as mapIndexed for index extraction" { - val items = listOf("apple", "banana", "avocado", "cherry", "apricot") + val items = ["apple", "banana", "avocado", "cherry", "apricot"] val pattern = Regex("^a") val viaMapIndexed = @@ -75,7 +75,7 @@ class IndicesFilterTest : StringSpec() { val viaIndicesFilter = items.indices.filter { items[it].contains(pattern) } viaIndicesFilter shouldBe viaMapIndexed - viaIndicesFilter shouldBe listOf(0, 2, 4) + viaIndicesFilter shouldBe [0, 2, 4] } } } diff --git a/readingbat-core/src/test/kotlin/com/readingbat/dsl/InvokesTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/dsl/InvokesTest.kt index c0d65cfe1..896e268cf 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/dsl/InvokesTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/dsl/InvokesTest.kt @@ -50,7 +50,7 @@ class InvokesTest : StringSpec() { """.trimIndent() extractPythonInvocations(s, defMainRegex, ifMainEndRegex).map { it.toString() } shouldBe - listOf("simple_choice2(True, True)", "simple_choice2(True, False)") + ["simple_choice2(True, True)", "simple_choice2(True, False)"] } "javaInvokesTest" { @@ -78,10 +78,10 @@ class InvokesTest : StringSpec() { """.trimIndent() extractJavaInvocations(s, psvmRegex, javaEndRegex).map { it.toString() } shouldBe - listOf( + [ """joinEnds("Blue zebra")""", """joinEnds("Tree")""", - ) + ] } "kotlinInvokesTest" { @@ -98,10 +98,10 @@ class InvokesTest : StringSpec() { """.trimIndent() extractKotlinInvocations(s, funMainRegex, kotlinEndRegex).map { it.toString() } shouldBe - listOf( + [ """listOf("a").combine2()""", """listOf("a", "b", "c", "d").combine2()""", - ) + ] } "classImportTest" { diff --git a/readingbat-core/src/test/kotlin/com/readingbat/dsl/JavaInvocationOrderTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/dsl/JavaInvocationOrderTest.kt index ce60c8c23..b8a2d5f0f 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/dsl/JavaInvocationOrderTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/dsl/JavaInvocationOrderTest.kt @@ -44,7 +44,7 @@ class JavaInvocationOrderTest : StringSpec() { """.trimIndent() extractJavaInvocations(code, psvmRegex, javaEndRegex).map { it.toString() } shouldBe - listOf("a(1)", "b(2)", "c(3)") + ["a(1)", "b(2)", "c(3)"] } } } diff --git a/readingbat-core/src/test/kotlin/com/readingbat/dsl/StripLeadingCommentsTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/dsl/StripLeadingCommentsTest.kt index 4be60b18b..cd8befc5c 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/dsl/StripLeadingCommentsTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/dsl/StripLeadingCommentsTest.kt @@ -25,88 +25,88 @@ class StripLeadingCommentsTest : StringSpec() { init { "strips multi-line copyright block comment" { val lines = - listOf( + [ "/*", " * Copyright © 2023 Paul Ambrose", " */", "", "fun hello() = 1", - ) - stripLeadingComments(lines) shouldBe listOf("fun hello() = 1") + ] + stripLeadingComments(lines) shouldBe ["fun hello() = 1"] } "keeps non-copyright multi-line block comment" { val lines = - listOf( + [ "/* This is a regular comment */", "fun hello() = 1", - ) + ] stripLeadingComments(lines) shouldBe lines } "strips single-line copyright block comment" { val lines = - listOf( + [ "/* Copyright 2023 */", "fun hello() = 1", - ) - stripLeadingComments(lines) shouldBe listOf("fun hello() = 1") + ] + stripLeadingComments(lines) shouldBe ["fun hello() = 1"] } "strips copyright line comment" { val lines = - listOf( + [ "// Copyright 2023", "fun hello() = 1", - ) - stripLeadingComments(lines) shouldBe listOf("fun hello() = 1") + ] + stripLeadingComments(lines) shouldBe ["fun hello() = 1"] } "keeps non-copyright line comment" { val lines = - listOf( + [ "// This is a regular comment", "fun hello() = 1", - ) + ] stripLeadingComments(lines) shouldBe lines } "strips leading blank lines before code" { val lines = - listOf( + [ "", "", "fun hello() = 1", - ) - stripLeadingComments(lines) shouldBe listOf("fun hello() = 1") + ] + stripLeadingComments(lines) shouldBe ["fun hello() = 1"] } "strips copyright block followed by blank lines" { val lines = - listOf( + [ "/*", " * Copyright © 2023", " */", "", "", "fun hello() = 1", - ) - stripLeadingComments(lines) shouldBe listOf("fun hello() = 1") + ] + stripLeadingComments(lines) shouldBe ["fun hello() = 1"] } "keeps non-copyright block comment after copyright block" { val lines = - listOf( + [ "/* Copyright 2023 */", "", "/* This describes the function */", "fun hello() = 1", - ) + ] stripLeadingComments(lines) shouldBe - listOf( + [ "/* This describes the function */", "fun hello() = 1", - ) + ] } "handles empty input" { @@ -114,45 +114,45 @@ class StripLeadingCommentsTest : StringSpec() { } "handles all-blank input" { - stripLeadingComments(listOf("", " ", "")) shouldBe emptyList() + stripLeadingComments(["", " ", ""]) shouldBe emptyList() } "copyright check is case-insensitive" { val lines = - listOf( + [ "/* cOpYrIgHt 2023 */", "fun hello() = 1", - ) - stripLeadingComments(lines) shouldBe listOf("fun hello() = 1") + ] + stripLeadingComments(lines) shouldBe ["fun hello() = 1"] } "keeps multi-line non-copyright block comment" { val lines = - listOf( + [ "/*", " * This is a doc comment", " */", "fun hello() = 1", - ) + ] stripLeadingComments(lines) shouldBe lines } "handles unclosed multi-line copyright block at end of input" { val lines = - listOf( + [ "/*", " * Copyright 2023", - ) + ] // The block never closes, but all lines contain copyright — should strip them stripLeadingComments(lines) shouldBe emptyList() } "handles code with no leading comments" { val lines = - listOf( + [ "fun hello() = 1", "fun world() = 2", - ) + ] stripLeadingComments(lines) shouldBe lines } } diff --git a/readingbat-core/src/test/kotlin/com/readingbat/posts/AnswerHistoryPersistenceTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/posts/AnswerHistoryPersistenceTest.kt index 3de209f24..73283618d 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/posts/AnswerHistoryPersistenceTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/posts/AnswerHistoryPersistenceTest.kt @@ -79,7 +79,7 @@ class AnswerHistoryPersistenceTest : StringSpec() { row[UserAnswerHistoryTable.invocation] = invocation.value row[correct] = true row[incorrectAttempts] = 2 - row[historyJson] = Json.encodeToString(listOf("wrong1", "wrong2", "right")) + row[historyJson] = Json.encodeToString(["wrong1", "wrong2", "right"]) } } } @@ -88,7 +88,7 @@ class AnswerHistoryPersistenceTest : StringSpec() { val history = user.answerHistory(md5, invocation) history.correct shouldBe true history.incorrectAttempts shouldBe 2 - history.answers shouldContainExactly listOf("wrong1", "wrong2", "right") + history.answers shouldContainExactly ["wrong1", "wrong2", "right"] } } @@ -149,7 +149,7 @@ class AnswerHistoryPersistenceTest : StringSpec() { row[invocation] = "invokeA()" row[correct] = true row[incorrectAttempts] = 0 - row[historyJson] = Json.encodeToString(listOf("answerA")) + row[historyJson] = Json.encodeToString(["answerA"]) } upsert(conflictIndex = userAnswerHistoryIndex) { row -> row[userRef] = user.userDbmsId @@ -158,12 +158,12 @@ class AnswerHistoryPersistenceTest : StringSpec() { row[invocation] = "invokeB()" row[correct] = false row[incorrectAttempts] = 3 - row[historyJson] = Json.encodeToString(listOf("wrong1", "wrong2", "wrong3")) + row[historyJson] = Json.encodeToString(["wrong1", "wrong2", "wrong3"]) } } } - val bulk = user.answerHistoryBulk(listOf(md5A, md5B, md5Missing)) + val bulk = user.answerHistoryBulk([md5A, md5B, md5Missing]) bulk.size shouldBe 2 bulk[md5A]!!.correct shouldBe true bulk[md5B]!!.incorrectAttempts shouldBe 3 @@ -195,7 +195,7 @@ class AnswerHistoryPersistenceTest : StringSpec() { row[UserAnswerHistoryTable.invocation] = invocation.value row[correct] = false row[incorrectAttempts] = 1 - row[historyJson] = Json.encodeToString(listOf("wrong")) + row[historyJson] = Json.encodeToString(["wrong"]) } } } @@ -212,7 +212,7 @@ class AnswerHistoryPersistenceTest : StringSpec() { row[UserAnswerHistoryTable.invocation] = invocation.value row[correct] = true row[incorrectAttempts] = 1 - row[historyJson] = Json.encodeToString(listOf("wrong", "right")) + row[historyJson] = Json.encodeToString(["wrong", "right"]) } } } @@ -220,7 +220,7 @@ class AnswerHistoryPersistenceTest : StringSpec() { val updated = user.answerHistory(md5, invocation) updated.correct shouldBe true updated.incorrectAttempts shouldBe 1 - updated.answers shouldContainExactly listOf("wrong", "right") + updated.answers shouldContainExactly ["wrong", "right"] } } diff --git a/readingbat-core/src/test/kotlin/com/readingbat/posts/BoundedResponsesTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/posts/BoundedResponsesTest.kt index dc9dc7b7d..b49abfb8b 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/posts/BoundedResponsesTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/posts/BoundedResponsesTest.kt @@ -31,24 +31,24 @@ class BoundedResponsesTest : StringSpec() { init { "boundedResponses returns one trimmed response per invocation" { ChallengePost.boundedResponses(2, mapOf("response0" to " a ", "response1" to "b")) shouldBe - listOf("a", "b") + ["a", "b"] } "boundedResponses ignores extra response params instead of throwing" { ChallengePost.boundedResponses( 2, mapOf("response0" to "a", "response1" to "b", "response2" to "c", "response3" to "d"), - ) shouldBe listOf("a", "b") + ) shouldBe ["a", "b"] } "boundedResponses treats a missing response as blank (unanswered)" { ChallengePost.boundedResponses(3, mapOf("response0" to "a", "response2" to "c")) shouldBe - listOf("a", "", "c") + ["a", "", "c"] } "boundedResponses ignores non-numeric response keys" { ChallengePost.boundedResponses(1, mapOf("response0" to "a", "responseFoo" to "x")) shouldBe - listOf("a") + ["a"] } } } diff --git a/readingbat-core/src/test/kotlin/com/readingbat/posts/BulkAnswerHistoryTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/posts/BulkAnswerHistoryTest.kt index 75491055b..b09412d10 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/posts/BulkAnswerHistoryTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/posts/BulkAnswerHistoryTest.kt @@ -34,7 +34,7 @@ class BulkAnswerHistoryTest : StringSpec() { } "ChallengeHistory with data preserves all fields" { - val answers = mutableListOf("wrong1", "wrong2", "correct") + val answers: MutableList = ["wrong1", "wrong2", "correct"] val history = ChallengeHistory( invocation = Invocation("foo(2)"), @@ -44,7 +44,7 @@ class BulkAnswerHistoryTest : StringSpec() { ) history.correct shouldBe true history.incorrectAttempts shouldBe 2 - history.answers shouldContainExactly listOf("wrong1", "wrong2", "correct") + history.answers shouldContainExactly ["wrong1", "wrong2", "correct"] } "Bulk result map lookup falls back to default for missing md5" { @@ -55,13 +55,13 @@ class BulkAnswerHistoryTest : StringSpec() { invocation = Invocation("test(1)"), correct = true, incorrectAttempts = 0, - answers = mutableListOf("42"), + answers = ["42"], ), ) val found = historyMap["abc123"] ?: ChallengeHistory(Invocation("test(1)")) found.correct shouldBe true - found.answers shouldContainExactly listOf("42") + found.answers shouldContainExactly ["42"] val missing = historyMap["xyz789"] ?: ChallengeHistory(Invocation("test(2)")) missing.correct shouldBe false @@ -72,17 +72,17 @@ class BulkAnswerHistoryTest : StringSpec() { "Multiple invocations map to distinct entries" { val historyMap = mapOf( - "md5_1" to ChallengeHistory(Invocation("foo(1)"), true, 0, mutableListOf("1")), - "md5_2" to ChallengeHistory(Invocation("foo(2)"), false, 3, mutableListOf("a", "b", "c")), - "md5_3" to ChallengeHistory(Invocation("foo(3)"), true, 1, mutableListOf("x", "3")), + "md5_1" to ChallengeHistory(Invocation("foo(1)"), true, 0, ["1"]), + "md5_2" to ChallengeHistory(Invocation("foo(2)"), false, 3, ["a", "b", "c"]), + "md5_3" to ChallengeHistory(Invocation("foo(3)"), true, 1, ["x", "3"]), ) val invocations = - listOf( + [ Invocation("foo(1)") to "md5_1", Invocation("foo(2)") to "md5_2", Invocation("foo(3)") to "md5_3", - ) + ] var numCorrect = 0 val results = @@ -96,12 +96,12 @@ class BulkAnswerHistoryTest : StringSpec() { results.size shouldBe 3 results[0].second.correct shouldBe true results[1].second.incorrectAttempts shouldBe 3 - results[2].second.answers shouldContainExactly listOf("x", "3") + results[2].second.answers shouldContainExactly ["x", "3"] } "Empty history map returns defaults for all invocations" { val emptyMap = emptyMap() - val invocations = listOf("md5_a", "md5_b", "md5_c") + val invocations = ["md5_a", "md5_b", "md5_c"] val results = invocations.map { md5 -> diff --git a/readingbat-core/src/test/kotlin/com/readingbat/posts/ChallengeHistoryTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/posts/ChallengeHistoryTest.kt index 51b7a28e2..ed5a55f8f 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/posts/ChallengeHistoryTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/posts/ChallengeHistoryTest.kt @@ -32,7 +32,7 @@ class ChallengeHistoryTest : StringSpec() { history.markCorrect("42") history.correct shouldBe true - history.answers shouldContainExactly listOf("42") + history.answers shouldContainExactly ["42"] history.incorrectAttempts shouldBe 0 } @@ -43,7 +43,7 @@ class ChallengeHistoryTest : StringSpec() { history.correct shouldBe false history.incorrectAttempts shouldBe 1 - history.answers shouldContainExactly listOf("wrong") + history.answers shouldContainExactly ["wrong"] } "markUnanswered sets correct to false" { @@ -61,7 +61,7 @@ class ChallengeHistoryTest : StringSpec() { history.markIncorrect("wrong") history.markIncorrect("wrong") - history.answers shouldContainExactly listOf("wrong") + history.answers shouldContainExactly ["wrong"] history.incorrectAttempts shouldBe 1 } @@ -72,7 +72,7 @@ class ChallengeHistoryTest : StringSpec() { history.markIncorrect("second") history.markCorrect("correct") - history.answers shouldContainExactly listOf("first", "second", "correct") + history.answers shouldContainExactly ["first", "second", "correct"] history.incorrectAttempts shouldBe 2 history.correct shouldBe true } @@ -93,17 +93,17 @@ class ChallengeHistoryTest : StringSpec() { "pre-fetched histories produce correct marking results" { // Simulate the pre-fetch pattern: create histories first, then mark them val invocations = - listOf( + [ Invocation("test(1)"), Invocation("test(2)"), Invocation("test(3)"), - ) + ] val results = - listOf( + [ ChallengeResults(invocations[0], userResponse = "42", answered = true, correct = true), ChallengeResults(invocations[1], userResponse = "wrong", answered = true, correct = false), ChallengeResults(invocations[2], userResponse = "", answered = false, correct = false), - ) + ] // Pre-fetch: create histories before processing (simulates reading from DB before write tx) val histories = invocations.map { ChallengeHistory(it) } @@ -119,11 +119,11 @@ class ChallengeHistoryTest : StringSpec() { // Verify results histories[0].correct shouldBe true - histories[0].answers shouldContainExactly listOf("42") + histories[0].answers shouldContainExactly ["42"] histories[0].incorrectAttempts shouldBe 0 histories[1].correct shouldBe false - histories[1].answers shouldContainExactly listOf("wrong") + histories[1].answers shouldContainExactly ["wrong"] histories[1].incorrectAttempts shouldBe 1 histories[2].correct shouldBe false @@ -137,7 +137,7 @@ class ChallengeHistoryTest : StringSpec() { invocation = Invocation("test(1)"), correct = false, incorrectAttempts = 2, - answers = mutableListOf("attempt1", "attempt2"), + answers = ["attempt1", "attempt2"], ) // User now submits the correct answer @@ -145,7 +145,7 @@ class ChallengeHistoryTest : StringSpec() { history.correct shouldBe true history.incorrectAttempts shouldBe 2 // unchanged - history.answers shouldContainExactly listOf("attempt1", "attempt2", "correct_answer") + history.answers shouldContainExactly ["attempt1", "attempt2", "correct_answer"] } } } diff --git a/readingbat-core/src/test/kotlin/com/readingbat/posts/UserAnswerQueueTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/posts/UserAnswerQueueTest.kt index 026a2db25..1b3d394ea 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/posts/UserAnswerQueueTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/posts/UserAnswerQueueTest.kt @@ -45,7 +45,7 @@ class UserAnswerQueueTest : StringSpec() { } "workerIndex handles negative ids without going out of range" { - listOf(-1L, -17L, -1234L).forEach { id -> + [-1L, -17L, -1234L].forEach { id -> workerIndex(id) shouldBeGreaterThanOrEqual 0 workerIndex(id) shouldBeLessThan WORKER_COUNT } diff --git a/readingbat-core/src/test/kotlin/com/readingbat/server/AuthorizationCheckTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/server/AuthorizationCheckTest.kt index 1a8e56b68..4db450afc 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/server/AuthorizationCheckTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/server/AuthorizationCheckTest.kt @@ -62,13 +62,13 @@ class AuthorizationCheckTest : StringSpec() { .post(CLEAR_CHALLENGE_ANSWERS_ENDPOINT) { header(ContentType, FormUrlEncoded.toString()) setBody( - listOf( + [ LANGUAGE_NAME_PARAM to "Java", GROUP_NAME_PARAM to TestData.GROUP_NAME, CHALLENGE_NAME_PARAM to "StringArrayTest1", CORRECT_ANSWERS_PARAM to spoofedKey, CHALLENGE_ANSWERS_PARAM to "", - ).formUrlEncode(), + ].formUrlEncode(), ) } // Should redirect (not crash) — the spoofed key is silently ignored @@ -92,12 +92,12 @@ class AuthorizationCheckTest : StringSpec() { .post(CLEAR_GROUP_ANSWERS_ENDPOINT) { header(ContentType, FormUrlEncoded.toString()) setBody( - listOf( + [ LANGUAGE_NAME_PARAM to "Java", GROUP_NAME_PARAM to TestData.GROUP_NAME, CORRECT_ANSWERS_PARAM to "[\"$spoofedKey\"]", CHALLENGE_ANSWERS_PARAM to "[]", - ).formUrlEncode(), + ].formUrlEncode(), ) } // Should redirect (not crash) — the spoofed keys are silently ignored diff --git a/readingbat-core/src/test/kotlin/com/readingbat/server/DeleteFromTableTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/server/DeleteFromTableTest.kt index 4dff5c1dd..cbaaf97c7 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/server/DeleteFromTableTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/server/DeleteFromTableTest.kt @@ -63,13 +63,13 @@ class DeleteFromTableTest : StringSpec() { .post(CLEAR_CHALLENGE_ANSWERS_ENDPOINT) { header(ContentType, FormUrlEncoded.toString()) setBody( - listOf( + [ LANGUAGE_NAME_PARAM to "Java", GROUP_NAME_PARAM to TestData.GROUP_NAME, CHALLENGE_NAME_PARAM to "StringArrayTest1", CORRECT_ANSWERS_PARAM to correctKey, CHALLENGE_ANSWERS_PARAM to challengeKey, - ).formUrlEncode(), + ].formUrlEncode(), ) } response shouldHaveStatus Found @@ -90,13 +90,13 @@ class DeleteFromTableTest : StringSpec() { .post(CLEAR_CHALLENGE_ANSWERS_ENDPOINT) { header(ContentType, FormUrlEncoded.toString()) setBody( - listOf( + [ LANGUAGE_NAME_PARAM to "Java", GROUP_NAME_PARAM to TestData.GROUP_NAME, CHALLENGE_NAME_PARAM to "StringArrayTest1", CORRECT_ANSWERS_PARAM to "", CHALLENGE_ANSWERS_PARAM to "", - ).formUrlEncode(), + ].formUrlEncode(), ) } response shouldHaveStatus Found @@ -117,13 +117,13 @@ class DeleteFromTableTest : StringSpec() { .post(CLEAR_CHALLENGE_ANSWERS_ENDPOINT) { header(ContentType, FormUrlEncoded.toString()) setBody( - listOf( + [ LANGUAGE_NAME_PARAM to "Java", GROUP_NAME_PARAM to TestData.GROUP_NAME, CHALLENGE_NAME_PARAM to "StringArrayTest1", CORRECT_ANSWERS_PARAM to "malformed-key-no-separators", CHALLENGE_ANSWERS_PARAM to "also-malformed", - ).formUrlEncode(), + ].formUrlEncode(), ) } response shouldHaveStatus Found diff --git a/readingbat-core/src/test/kotlin/com/readingbat/server/SerializableTransactionTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/server/SerializableTransactionTest.kt index 0c4fa64c4..ef1f9da01 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/server/SerializableTransactionTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/server/SerializableTransactionTest.kt @@ -40,7 +40,7 @@ class SerializableTransactionTest : StringSpec() { invocation = Invocation("test()"), correct = false, incorrectAttempts = 3, - answers = mutableListOf("wrong1", "wrong2", "wrong3"), + answers = ["wrong1", "wrong2", "wrong3"], ) history.markCorrect("right") @@ -55,13 +55,13 @@ class SerializableTransactionTest : StringSpec() { invocation = Invocation("test()"), correct = false, incorrectAttempts = 2, - answers = mutableListOf("wrong1", "wrong2"), + answers = ["wrong1", "wrong2"], ) history.markIncorrect("wrong3") history.correct shouldBe false history.incorrectAttempts shouldBe 3 - history.answers shouldBe mutableListOf("wrong1", "wrong2", "wrong3") + history.answers shouldBe ["wrong1", "wrong2", "wrong3"] } "ChallengeHistory markIncorrect does not increment for duplicate answer" { @@ -70,12 +70,12 @@ class SerializableTransactionTest : StringSpec() { invocation = Invocation("test()"), correct = false, incorrectAttempts = 1, - answers = mutableListOf("wrong1"), + answers = ["wrong1"], ) history.markIncorrect("wrong1") history.incorrectAttempts shouldBe 1 - history.answers shouldBe mutableListOf("wrong1") + history.answers shouldBe ["wrong1"] } "ChallengeHistory concurrent mutation scenario shows why isolation matters" { diff --git a/readingbat-core/src/test/kotlin/com/readingbat/server/routes/OAuthGitHubEmailTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/server/routes/OAuthGitHubEmailTest.kt index c01834cc5..a2915fbd8 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/server/routes/OAuthGitHubEmailTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/server/routes/OAuthGitHubEmailTest.kt @@ -33,24 +33,24 @@ class OAuthGitHubEmailTest : StringSpec() { "resolveGitHubEmail prefers a primary verified email when the profile email is blank" { val emails = - listOf( + [ GitHubEmail("secondary@example.com", primary = false, verified = true), GitHubEmail("primary@example.com", primary = true, verified = true), - ) + ] resolveGitHubEmail(null, emails) shouldBe "primary@example.com" } "resolveGitHubEmail falls back to any verified email" { val emails = - listOf( + [ GitHubEmail("unverified@example.com", primary = true, verified = false), GitHubEmail("verified@example.com", primary = false, verified = true), - ) + ] resolveGitHubEmail(null, emails) shouldBe "verified@example.com" } "resolveGitHubEmail returns null when only unverified emails exist" { - resolveGitHubEmail(null, listOf(GitHubEmail("x@example.com", primary = true, verified = false))) shouldBe null + resolveGitHubEmail(null, [GitHubEmail("x@example.com", primary = true, verified = false)]) shouldBe null } "resolveGitHubEmail returns null when there is no email at all" { diff --git a/readingbat-core/src/test/kotlin/com/readingbat/server/ws/WsConnectionSnapshotTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/server/ws/WsConnectionSnapshotTest.kt index ed053703d..192e73166 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/server/ws/WsConnectionSnapshotTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/server/ws/WsConnectionSnapshotTest.kt @@ -47,11 +47,11 @@ class WsConnectionSnapshotTest : StringSpec() { } "snapshotUnderMonitor returns a decoupled copy" { - val set = Collections.synchronizedSet(LinkedHashSet()).apply { addAll(listOf(1, 2, 3)) } + val set = Collections.synchronizedSet(LinkedHashSet()).apply { addAll([1, 2, 3]) } val snapshot = set.snapshotUnderMonitor() set.add(4) set.remove(1) - snapshot shouldBe listOf(1, 2, 3) + snapshot shouldBe [1, 2, 3] } } } diff --git a/readingbat-core/src/test/kotlin/com/readingbat/server/ws/WsProtocolConstantsTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/server/ws/WsProtocolConstantsTest.kt index 0bc5fc9c1..d65f38dc9 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/server/ws/WsProtocolConstantsTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/server/ws/WsProtocolConstantsTest.kt @@ -83,7 +83,7 @@ class WsProtocolConstantsTest : StringSpec() { ClassSummary( userId = "user1", challengeName = "hello", - results = listOf("Y", "N"), + results = ["Y", "N"], stats = "1/2", likeDislike = "", ) @@ -102,7 +102,7 @@ class WsProtocolConstantsTest : StringSpec() { StudentSummary( groupName = "Warmup-1", challengeName = "hello", - results = listOf("Y"), + results = ["Y"], stats = "1/1", likeDislike = "", ) diff --git a/readingbat-core/src/test/kotlin/com/readingbat/testcontent/StringListKtTest1.kt b/readingbat-core/src/test/kotlin/com/readingbat/testcontent/StringListKtTest1.kt index d1b0ca174..8610e5834 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/testcontent/StringListKtTest1.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/testcontent/StringListKtTest1.kt @@ -17,7 +17,7 @@ package com.readingbat.testcontent -fun combinel(s1: String, s2: String): List = listOf(s1, s2) +fun combinel(s1: String, s2: String): List = [s1, s2] fun main() { println(combinel("Car", "wash")) diff --git a/readingbat-core/src/test/kotlin/com/readingbat/utils/ChanceSelectionTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/utils/ChanceSelectionTest.kt index 442265801..c7916ab2c 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/utils/ChanceSelectionTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/utils/ChanceSelectionTest.kt @@ -58,7 +58,7 @@ class ChanceSelectionTest : StringSpec() { val size = 5 val current = 2 val candidates = (0 until size).filter { it != current } - candidates shouldBe listOf(0, 1, 3, 4) + candidates shouldBe [0, 1, 3, 4] } } } diff --git a/readingbat-core/src/test/kotlin/com/readingbat/utils/ForEachConsistencyTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/utils/ForEachConsistencyTest.kt index 184b5ad74..136bbead8 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/utils/ForEachConsistencyTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/utils/ForEachConsistencyTest.kt @@ -23,12 +23,12 @@ import io.kotest.matchers.shouldBe class ForEachConsistencyTest : StringSpec() { init { "forEach with destructuring should process all pairs" { - val pairs = listOf("a" to 1, "b" to 2, "c" to 3) - val collected = mutableListOf() + val pairs = ["a" to 1, "b" to 2, "c" to 3] + val collected: MutableList = [] pairs.forEach { (key, value) -> collected += "$key=$value" } - collected shouldBe listOf("a=1", "b=2", "c=3") + collected shouldBe ["a=1", "b=2", "c=3"] } "forEach with destructuring on empty list should be no-op" { @@ -42,7 +42,7 @@ class ForEachConsistencyTest : StringSpec() { "forEach with destructuring should maintain order" { val pairs = (1..100).map { "key$it" to it } - val indices = mutableListOf() + val indices: MutableList = [] pairs.forEach { (_, value) -> indices += value } diff --git a/readingbat-core/src/test/kotlin/com/readingbat/utils/JsonUtilsTest.kt b/readingbat-core/src/test/kotlin/com/readingbat/utils/JsonUtilsTest.kt index de75b66e6..37daa00c9 100644 --- a/readingbat-core/src/test/kotlin/com/readingbat/utils/JsonUtilsTest.kt +++ b/readingbat-core/src/test/kotlin/com/readingbat/utils/JsonUtilsTest.kt @@ -47,7 +47,7 @@ class JsonUtilsTest : StringSpec() { } "toJson serializes a list of primitives" { - listOf(1, 2, 3).toJson() shouldBe "[1,2,3]" + [1, 2, 3].toJson() shouldBe "[1,2,3]" } "toJson serializes a map with string keys" { @@ -56,7 +56,7 @@ class JsonUtilsTest : StringSpec() { } "toJson serializes a nested data class round-trips through Json.decodeFromString" { - val original = Wrapper(tag = "t", values = listOf(1, 2, 3), person = Person("Bob", 7)) + val original = Wrapper(tag = "t", values = [1, 2, 3], person = Person("Bob", 7)) val encoded = original.toJson() Json.decodeFromString(encoded) shouldBe original } diff --git a/readingbat-kotest/src/main/kotlin/com/readingbat/kotest/TestSupport.kt b/readingbat-kotest/src/main/kotlin/com/readingbat/kotest/TestSupport.kt index 848a361a8..6e61e30fc 100644 --- a/readingbat-kotest/src/main/kotlin/com/readingbat/kotest/TestSupport.kt +++ b/readingbat-kotest/src/main/kotlin/com/readingbat/kotest/TestSupport.kt @@ -91,12 +91,12 @@ object TestSupport { functionInfo().block() } - private fun Challenge.formData() = - mutableListOf( + private fun Challenge.formData(): MutableList> = + [ LANG_SRC to challengeGroup.languageGroup.languageName.value, GROUP_SRC to challengeGroup.groupName.value, CHALLENGE_SRC to challengeName.value, - ) + ] private suspend fun Challenge.parseChallengeResults(content: String): List { var cnt = 0