fix toString of parameter

This commit is contained in:
2023-06-03 01:01:33 +02:00
parent 3e3a72306b
commit 96aaa1ada9
3 changed files with 35 additions and 28 deletions

View File

@@ -6,16 +6,21 @@ class ParameterType(
val name: String, val name: String,
val precision: Int? = null, val precision: Int? = null,
val scale: Int? = null, val scale: Int? = null,
val isArray: Boolean = false, val array: String? = null,
) { ) {
val isArray: Boolean
get() = array != null
override fun toString(): String { override fun toString(): String {
return if (precision == null && scale == null) { val type = if (precision == null && scale == null) {
name name
} else if (scale == null) { } else if (scale == null) {
"""$name($precision)""" """$name($precision)"""
} else { } else {
"""$name($precision, $scale)""" """$name($precision, $scale)"""
} }
return type+array
} }
} }
@@ -38,6 +43,22 @@ class Parameter(
) )
enum class Direction { IN, OUT, INOUT } enum class Direction { IN, OUT, INOUT }
override fun toString(): String {
return buildString {
append(direction.name.lowercase())
if (name?.isNotBlank() == true) {
append(" ")
append(name)
}
append(" ")
append(type.toString())
if (default?.isNotBlank() == true) {
append(" ")
append(default)
}
}
}
} }
interface ParametersInterface { interface ParametersInterface {

View File

@@ -129,14 +129,14 @@ private fun ScriptPart.getParameterType(): NextScript<ParameterType> {
.apply { rest = nextScriptPart } .apply { rest = nextScriptPart }
rest = rest.trimStart(' ', '\n', '\t', ')') rest = rest.trimStart(' ', '\n', '\t', ')')
val isArray = rest.restOfScript.contains("""\[[0-9]*]""".toRegex()) val arrayDef = rest.restOfScript.trim().takeIf(String::isNotBlank)
return NextScript( return NextScript(
ParameterType( ParameterType(
name = name.value.trim().trim('[', ']'), name = name.value.trim().trim('[', ']'),
precision = precision.value, precision = precision.value,
scale = scale.value, scale = scale.value,
isArray = isArray array = arrayDef
), ),
fullType.nextScriptPart.restOfScript fullType.nextScriptPart.restOfScript
) )

View File

@@ -451,6 +451,16 @@ class FunctionTest : FreeSpec({
param[0].type.name shouldBe "text" param[0].type.name shouldBe "text"
param[1].type.name shouldBe "text" param[1].type.name shouldBe "text"
} }
"should return the type with array" {
param[0].type.toString() shouldBe "text[45]"
param[1].type.toString() shouldBe "text[1][]"
}
"should return the type name" {
param[0].toString() shouldBe "in one text[45]"
param[1].toString() shouldBe "in two text[1][]"
}
} }
} }
@@ -635,28 +645,4 @@ class FunctionTest : FreeSpec({
// } // }
// } // }
// } // }
//
// "getDefinition" - {
// TODO("must be implement")
// }
//
// "getParametersIndexedByName" - {
// TODO("must be implement")
// }
//
// "has same definition" - {
// TODO("must be implement")
// }
//
// "is different from" - {
// TODO("must be implement")
// }
//
// "script" - {
// TODO("must be implement")
// }
//
// "source" - {
// TODO("must be implement")
// }
}) })