From a9148fc88dbaa6b81b9df6b75d49eb732838ec1e Mon Sep 17 00:00:00 2001 From: Daoortor Date: Thu, 25 Jul 2024 18:36:26 +0200 Subject: [PATCH] fix getAbbreviation --- .../academy/test/system/core/KTypeUtils.kt | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/core/src/main/kotlin/org/jetbrains/academy/test/system/core/KTypeUtils.kt b/core/src/main/kotlin/org/jetbrains/academy/test/system/core/KTypeUtils.kt index ca99f48..4aba276 100644 --- a/core/src/main/kotlin/org/jetbrains/academy/test/system/core/KTypeUtils.kt +++ b/core/src/main/kotlin/org/jetbrains/academy/test/system/core/KTypeUtils.kt @@ -42,29 +42,14 @@ private fun KType.checkAbbreviation(abbreviation: String, errorMessagePrefix: St Assertions.assertEquals( this.getAbbreviation(), abbreviation, - "The return type for $errorMessagePrefix must contain $abbreviation" + "The return type for $errorMessagePrefix must be $abbreviation" ) } private fun KType.getAbbreviation(): String { - val separator = " /*" - val strRepresentation = this.toString() - if (separator !in strRepresentation) { - if (arguments.isNotEmpty()) { - this.arguments.first().type?.toString()?.let { - return it - } - } - return if ("?" in strRepresentation) { - strRepresentation.dropLast(1) - } else { - strRepresentation - } - } - val abr = strRepresentation.split(separator).first() - return if ("<" in strRepresentation) { - "$abr>" - } else { - abr - } + val hintRegex = Regex(""" /\*[\w>.<, =_]+ \*/""") + return this + .toString() + .replace(hintRegex, "") + .filterNot { it == '?' } }