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 @@ -971,7 +976,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 adipiscing elit. Aeean commodo ligula eget dolor. Aenean ma")
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 adipiscing elit. Aeean commodo ligula eget dolor. Aenean ma")
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,55 @@
D A40_A100 S 100 DIM(300)
D A40_DS DS
D A40_DS_F1 10
D A40_DS_F2 29
D A40_DS_F3 21
D A40_DS_F4 01
D A40_DS_F5 04
D A40_DS_F6 01
D A40_DS_F7 01
D A40_DS_F8 10
D A40_DS_F9 16
D A40_DS_F10 02
D A40_DS_F11 05
D A40_DS_F12 100
D A40_DS_F13 300
D A40_A5 S 5 0

D OUTPUT S 100

C EVAL A40_DS_F1='Lorem ipsu'
C EVAL A40_DS_F2='m dolor sit amet, consectetue'
C EVAL A40_DS_F3='r adipiscing elit. Ae'
C EVAL A40_DS_F4='e'
C EVAL A40_DS_F5='an c'
C EVAL A40_DS_F6='o'
C EVAL A40_DS_F7='m'
C EVAL A40_DS_F8='modo ligul'
C EVAL A40_DS_F9='a eget dolor. Ae'
C EVAL A40_DS_F10='ne'
C EVAL A40_DS_F11='an ma'
C EVAL A40_DS_F12='ssa. Cum sociis natoque penatib'
c + 'us et magnis dis '
C + 'partu rient montes, nasce'
C + 'tur ridiculus mus.'
C + ' Donec qua'
C EVAL A40_DS_F13='m felis, ultricies nec, pellen'
C + 'tesque eu, pretium'
C + ' quis, sem. Nulla conse'
C + 'quat massa quis '
C + 'enim. Donec pede justo, '
C + 'fringilla vel, '
C + 'aliquet nec, vulputate'
C + ' eget, arcu. '
C + 'In enim justo, rhoncus '
C + 'ut, imperdiet a, '
C + 'venenatis vitae, justo. '
C + 'Nullam dictum '
C + 'felis eu pede mollis '
C + 'pretium. Integer '
C + 'tincidunt. Cras dapibus'

C EVAL A40_A5=1
C EVAL A40_A100(A40_A5)=A40_DS
C EVAL OUTPUT=A40_A100(A40_A5)
C OUTPUT DSPLY
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
D A40_A100 S 100 DIM(300) VARYING
D A40_DS DS
D A40_DS_F1 10
D A40_DS_F2 29
D A40_DS_F3 21
D A40_DS_F4 01
D A40_DS_F5 04
D A40_DS_F6 01
D A40_DS_F7 01
D A40_DS_F8 10
D A40_DS_F9 16
D A40_DS_F10 02
D A40_DS_F11 05
D A40_DS_F12 100
D A40_DS_F13 300
D A40_A5 S 5 0

D OUTPUT S 100

C EVAL A40_DS_F1='Lorem ipsu'
C EVAL A40_DS_F2='m dolor sit amet, consectetue'
C EVAL A40_DS_F3='r adipiscing elit. Ae'
C EVAL A40_DS_F4='e'
C EVAL A40_DS_F5='an c'
C EVAL A40_DS_F6='o'
C EVAL A40_DS_F7='m'
C EVAL A40_DS_F8='modo ligul'
C EVAL A40_DS_F9='a eget dolor. Ae'
C EVAL A40_DS_F10='ne'
C EVAL A40_DS_F11='an ma'
C EVAL A40_DS_F12='ssa. Cum sociis natoque penatib'
c + 'us et magnis dis '
C + 'partu rient montes, nasce'
C + 'tur ridiculus mus.'
C + ' Donec qua'
C EVAL A40_DS_F13='m felis, ultricies nec, pellen'
C + 'tesque eu, pretium'
C + ' quis, sem. Nulla conse'
C + 'quat massa quis '
C + 'enim. Donec pede justo, '
C + 'fringilla vel, '
C + 'aliquet nec, vulputate'
C + ' eget, arcu. '
C + 'In enim justo, rhoncus '
C + 'ut, imperdiet a, '
C + 'venenatis vitae, justo. '
C + 'Nullam dictum '
C + 'felis eu pede mollis '
C + 'pretium. Integer '
C + 'tincidunt. Cras dapibus'

C EVAL A40_A5=1
C EVAL A40_A100(A40_A5)=A40_DS
C EVAL OUTPUT=A40_A100(A40_A5)
C OUTPUT DSPLY