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 precision: Int? = null,
val scale: Int? = null,
val isArray: Boolean = false,
val array: String? = null,
) {
val isArray: Boolean
get() = array != null
override fun toString(): String {
return if (precision == null && scale == null) {
val type = if (precision == null && scale == null) {
name
} else if (scale == null) {
"""$name($precision)"""
} else {
"""$name($precision, $scale)"""
}
return type+array
}
}
@@ -38,6 +43,22 @@ class Parameter(
)
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 {

View File

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

View File

@@ -451,6 +451,16 @@ class FunctionTest : FreeSpec({
param[0].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")
// }
})