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/ls24005243/checkr factor2 expression #676

Merged
merged 12 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -854,9 +854,9 @@ data class CheckStmt(

@Serializable
data class CheckrStmt(
val comparatorString: Expression, // Factor1
val baseString: Expression,
val start: Int = 1,
var comparatorString: Expression, // Factor1
lanarimarco marked this conversation as resolved.
Show resolved Hide resolved
var baseString: Expression,
var startPosition: Expression?,
val wrongCharPosition: AssignableExpression?,
@Derived val dataDefinition: InStatementDataDefinition? = null,
override val position: Position? = null
Expand All @@ -865,9 +865,10 @@ data class CheckrStmt(
get() = "CHECKR"

override fun execute(interpreter: InterpreterCore) {
val start = startPosition?.let { interpreter.eval(it).asString().value.toInt() } ?: 1
var baseString = interpreter.eval(this.baseString).asString().value
if (this.baseString is DataRefExpr) {
baseString = baseString.padEnd(this.baseString.size())
baseString = baseString.padEnd((this.baseString as DataRefExpr).size())
}
val charSet = interpreter.eval(comparatorString).asString().value
val wrongIndex = wrongCharPosition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,14 @@ internal fun CsCHECKContext.toAst(conf: ToAstConfiguration): Statement {
internal fun CsCHECKRContext.toAst(conf: ToAstConfiguration): Statement {
val position = toPosition(conf.considerPosition)
val factor1 = this.factor1Context()?.content?.toAst(conf) ?: throw UnsupportedOperationException("CHECKR operation requires factor 1: ${this.text} - ${position.atLine()}")
val (expression, startPosition) = this.cspec_fixed_standard_parts().factor2.toIndexedExpression(conf)
val factor2 = this.cspec_fixed_standard_parts().factor2
// factor2 is formed by TEXT:B
// where "TEXT" is the content to be substringed
val expression = this.cspec_fixed_standard_parts().factor2.factorContent(0).toAst(conf)
// and "B" is the start position to substring, if not specified it returns null
val positionExpression = if (factor2.factorContent().size > 1) {
factor2.factorContent(1).toAst(conf)
} else null

val result = this.cspec_fixed_standard_parts().result
val dataDefinition = this.cspec_fixed_standard_parts().toDataDefinition(result.text, position, conf)
Expand All @@ -1512,7 +1519,7 @@ internal fun CsCHECKRContext.toAst(conf: ToAstConfiguration): Statement {
return CheckrStmt(
factor1,
expression,
startPosition ?: 1,
positionExpression,
wrongCharExpression,
dataDefinition,
position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,16 @@ open class MULANGT10BaseCodopTest : MULANGTTest() {
assertEquals(expected, "smeup/MUDRNRAPU00274".outputOf(configuration = smeupConfig))
}

/**
* CHECKR with indexed expression based on a Data Reference
* @see #LS24005243
*/
@Test
fun executeMUDRNRAPU00275() {
val expected = listOf("ok")
assertEquals(expected, "smeup/MUDRNRAPU00275".outputOf(configuration = turnOnZAddLegacyFlagConfig))
}

/**
* This program tests the moving of value from Factor 2 to Result. This operation is performed at the end of execution of
* program called. In this case, MUDRNRAPU00172_P turn on indicator 35. Later, `DO` block ends its execution.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
V* ==============================================================
V* 04/12/2024 APU002 Creation
V* ==============================================================
O * PROGRAM GOAL
O * CHECKR with indexed expression based on a Data Reference
V* ==============================================================
O * JARIKO ANOMALY
O * Before the fix, jariko throw a syntax error
V* ============================================================== DA1 S 1
DN2 S 2 0
D T$C5MD S 15
DA1 S 2
C A1 CHECKR T$C5MD:N2 N2
C 'ok' DSPLY
Loading