Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/ls24003755/ds to string when ds is greater than string #591

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,12 @@ data class StringValue(var value: String, var varying: Boolean = false) : Abstra

override fun asTimeStamp(): TimeStampValue = TimeStampValue.of(value)

fun setSubstring(startOffset: Int, endOffset: Int, substringValue: StringValue) {
fun setSubstring(startOffset: Int, endOffset: Int) {
require(startOffset >= 0)
require(startOffset <= value.length)
require(endOffset >= startOffset)
require(endOffset <= value.length) { "Asked startOffset=$startOffset, endOffset=$endOffset on string of length ${value.length}" }
substringValue.pad(endOffset - startOffset)
value = value.substring(0, startOffset) + substringValue.value + value.substring(endOffset)
value = value.substring(startOffset, endOffset)
}

fun getSubstring(startOffset: Int, endOffset: Int): StringValue {
Expand Down Expand Up @@ -633,26 +632,32 @@ data class ConcreteArrayValue(val elements: MutableList<Value>, override val ele
override fun setElement(index: Int, value: Value) {
require(index >= 1)
require(index <= arrayLength())
if (!value.assignableTo(elementType)) {
println("boom")
}
require(value.assignableTo(elementType)) {
"Cannot assign ${value::class.qualifiedName} to ${elementType::class.qualifiedName}"
}
if (elementType is StringType && !elementType.varying) {
val v = when (value) {
is AbstractStringValue -> {
(value as StringValue).copy()
when (elementType) {
is StringType -> {
val v = when (value) {
is AbstractStringValue -> {
(value as StringValue).copy()
}
is DataStructValue -> {
value.asString().copy()
}
else -> TODO("Not yet implemented")
}
is DataStructValue -> {
value.asString().copy()

/*
* Setting the value based of varying flag and length of target.
*/
if (!elementType.varying && v.length() < elementType.length) {
v.pad(elementType.length)
} else if (v.length() > elementType.length) {
v.setSubstring(0, elementType.length)
}
else -> TODO("Not yet implemented")
elements[index - 1] = v
}
v.pad(elementType.length)
elements[index - 1] = v
} else {
elements[index - 1] = value
else -> elements[index - 1] = value
}
}

Expand Down Expand Up @@ -997,7 +1002,7 @@ data class DataStructValue(var value: String, private val optionalExternalLen: I
// Check if the size of the value matches the expected size within the DS
// TO REVIEW
is DataStructureType -> true
is StringType -> expectedType.size >= this.value.length
is StringType -> true
else -> false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ open class MULANGT04EssentialsCodopAndBifTest : MULANGTTest() {
}

/**
*Assigns content of DS to a String VARYING in EVAL
*Assigns content of DS to a String VARYING in EVAL
* @see #LS24003679
*/
@Test
Expand All @@ -54,6 +54,26 @@ open class MULANGT04EssentialsCodopAndBifTest : MULANGTTest() {
assertEquals(expected, "smeup/MU044014".outputOf())
}

/**
*Assigns content of DS to a String not VARYING in EVAL where, size of DS is greater than String
* @see #LS24003755
*/
@Test
fun executeMUDRNRAPU00106() {
val expected = listOf("Lorem ipsum dolor sit amet, consectetuer adipiscin")
assertEquals(expected, "smeup/MUDRNRAPU00106".outputOf())
}

/**
*Assigns content of DS to a String not VARYING in EVAL where, size of DS is greater than String
* @see #LS24003755
*/
@Test
fun executeMUDRNRAPU00107() {
val expected = listOf("Lorem ipsum dolor sit amet, consectetuer adipiscin")
assertEquals(expected, "smeup/MUDRNRAPU00107".outputOf())
}

/**
* %DIFF with several DurationCodes
* @see #LS24003282
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
V* ==============================================================
V* 08/08/2024 APU001 Creation
V* 20/08/2024 APU001 Simplification by removing several
V* fields of DS.
V* ==============================================================
O * PROGRAM GOAL
O * Assignment the content of DS to an element of array that is
O * String type (not varying) with size smaller than DS.
O * After declaration of variable there is the assignment of
O * specific substring of "Lorem ipsum" to every field of DS.
O * Then, there is the assignment of DS content to an element
O * of array. In AS400 there is a truncate of content for adapting
O * to destination, smaller than DS.
O * The implementation is like the original source, by changing
O * only the name of variables and by adding the assignment
O * of substring to undestand about the behavior.
V* ==============================================================
O * JARIKO ANOMALY
O * Before the fix, the error occurred was
O * `Cannot assign DataStructValue to StringType`.
V* ==============================================================
D A40_A50 S 50 DIM(300)
D A40_DS DS
D A40_DS_F1 20
D A40_DS_F2 20
D A40_DS_F3 35
D A40_A5 S 5 0

D OUTPUT S 50

C EVAL A40_DS_F1='Lorem ipsum dolor si'
C EVAL A40_DS_F2='t amet, consectetuer'
C EVAL A40_DS_F3=' adipiscing elit. Aeean'
C + ' commodo lig'

C EVAL A40_A5=1
C EVAL A40_A50(A40_A5)=A40_DS Jariko Runtime Error: `Cannot assign DataStructValue to StringType`
C EVAL OUTPUT=A40_A50(A40_A5)
C OUTPUT DSPLY
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
V* ==============================================================
V* 08/08/2024 APU001 Creation
V* 20/08/2024 APU001 Simplification by removing several
V* fields of DS.
V* ==============================================================
O * PROGRAM GOAL
O * Assignment the content of DS to an element of array that is
O * String type (varying) with size smaller than DS.
O * After declaration of variable there is the assignment of
O * specific substring of "Lorem ipsum" to every field of DS.
O * Then, there is the assignment of DS content to an element
O * of array. In AS400 there is a truncate of content for adapting
O * to destination, smaller than DS.
O * The implementation is like the original source, by changing
O * only the name of variables and by adding the assignment
O * of substring to undestand about the behavior.
V* ==============================================================
O * JARIKO ANOMALY
O * Before the fix, the error occurred was
O * `Cannot assign DataStructValue to StringType`.
V* ==============================================================
D A40_A50 S 50 DIM(300) VARYING
D A40_DS DS
D A40_DS_F1 20
D A40_DS_F2 20
D A40_DS_F3 35
D A40_A5 S 5 0

D OUTPUT S 50

C EVAL A40_DS_F1='Lorem ipsum dolor si'
C EVAL A40_DS_F2='t amet, consectetuer'
C EVAL A40_DS_F3=' adipiscing elit. Aeean'
C + ' commodo lig'

C EVAL A40_A5=1
C EVAL A40_A50(A40_A5)=A40_DS Jariko Runtime Error: `Cannot assign DataStructValue to StringType`
C EVAL OUTPUT=A40_A50(A40_A5)
C OUTPUT DSPLY