Skip to content

Commit

Permalink
Merge pull request #474 from smeup/bugfix/NW23001440/262-mock-oc-feod
Browse files Browse the repository at this point in the history
Bugfix/nw23001440/262 mock oc feod
  • Loading branch information
lanarimarco authored Mar 22, 2024
2 parents fa7fc7b + 094838f commit 48813ac
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.smeup.rpgparser.execution
import com.smeup.dbnative.DBNativeAccessConfig
import com.smeup.rpgparser.interpreter.*
import com.smeup.rpgparser.parsing.ast.CompilationUnit
import com.smeup.rpgparser.parsing.ast.MockStatement
import com.smeup.rpgparser.parsing.facade.CopyBlocks
import com.smeup.rpgparser.parsing.facade.CopyId
import com.smeup.rpgparser.parsing.facade.SourceReference
Expand Down Expand Up @@ -162,7 +163,12 @@ data class JarikoCallback(
},
var onCallPgmError: (errorEvent: ErrorEvent) -> Unit = { },
var logInfo: ((channel: String, message: String) -> Unit)? = null,
var channelLoggingEnabled: ((channel: String) -> Boolean)? = null
var channelLoggingEnabled: ((channel: String) -> Boolean)? = null,
/**
* This is called for those statements mocked.
* @param mockStatement "Statement" where is get its name for the `println`.
*/
var onMockStatement: ((mockStatement: MockStatement) -> Unit) = { System.err.println("Executing mock: ${it.javaClass.simpleName}") }
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,12 @@ open class InternalInterpreter(
MainExecutionContext.getConfiguration().jarikoCallback.onEnterStatement(it.first, it.second)
}
}
statement.execute(this)

if (statement is MockStatement) {
MainExecutionContext.getConfiguration().jarikoCallback.onMockStatement
} else {
statement.execute(this)
}
}
} catch (e: ControlFlowException) {
throw e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ private val modules = SerializersModule {
subclass(DOWxxStmt::class)
subclass(EvalStmt::class)
subclass(ExecuteSubroutine::class)
subclass(ExfmtStmt::class)
subclass(FeodStmt::class)
subclass(ForStmt::class)
subclass(GotoStmt::class)
subclass(IfStmt::class)
Expand All @@ -78,15 +80,13 @@ private val modules = SerializersModule {
subclass(OccurStmt::class)
subclass(OpenStmt::class)
subclass(PlistStmt::class)
subclass(ReadcStmt::class)
subclass(ReadEqualStmt::class)
subclass(ReadPreviousStmt::class)
subclass(ReadPreviousEqualStmt::class)
subclass(ReadStmt::class)
subclass(ResetStmt::class)
subclass(ExfmtStmt::class)
subclass(ReadcStmt::class)
subclass(ReturnStmt::class)
subclass(UnlockStmt::class)
subclass(ScanStmt::class)
subclass(SelectStmt::class)
subclass(CaseStmt::class)
Expand All @@ -99,6 +99,7 @@ private val modules = SerializersModule {
subclass(SubstStmt::class)
subclass(TagStmt::class)
subclass(TimeStmt::class)
subclass(UnlockStmt::class)
subclass(UpdateStmt::class)
subclass(XFootStmt::class)
subclass(XlateStmt::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ abstract class Statement(
abstract fun execute(interpreter: InterpreterCore)
}

/**
* For statements with this interface there isn't execution but will be called the callback `onMockStatement`.
*/
interface MockStatement

interface CompositeStatement {
val body: List<Statement>
}
Expand Down Expand Up @@ -2055,26 +2060,27 @@ data class ResetStmt(
@Serializable
data class ExfmtStmt(
override val position: Position? = null
) : Statement(position) {
override fun execute(interpreter: InterpreterCore) {
// TODO
}
) : Statement(position), MockStatement {
override fun execute(interpreter: InterpreterCore) { }
}

@Serializable
data class ReadcStmt(
override val position: Position? = null
) : Statement(position) {
override fun execute(interpreter: InterpreterCore) {
// TODO
}
) : Statement(position), MockStatement {
override fun execute(interpreter: InterpreterCore) { }
}

@Serializable
data class UnlockStmt(
override val position: Position? = null
) : Statement(position) {
override fun execute(interpreter: InterpreterCore) {
// TODO
}
) : Statement(position), MockStatement {
override fun execute(interpreter: InterpreterCore) { }
}

@Serializable
data class FeodStmt(
override val position: Position? = null
) : Statement(position), MockStatement {
override fun execute(interpreter: InterpreterCore) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,9 @@ internal fun Cspec_fixed_standardContext.toAst(conf: ToAstConfiguration = ToAstC
this.csUNLOCK() != null -> this.csUNLOCK()
.let { it.cspec_fixed_standard_parts().validate(stmt = it.toAst(conf), conf = conf) }

this.csFEOD() != null -> this.csFEOD()
.let { it.cspec_fixed_standard_parts().validate(stmt = it.toAst(conf), conf = conf) }

else -> todo(conf = conf)
}
}
Expand Down Expand Up @@ -1997,6 +2000,12 @@ internal fun CsUNLOCKContext.toAst(conf: ToAstConfiguration = ToAstConfiguration
return UnlockStmt(position)
}

// TODO
internal fun CsFEODContext.toAst(conf: ToAstConfiguration = ToAstConfiguration()): Statement {
val position = toPosition(conf.considerPosition)
return FeodStmt(position)
}

/**
* Run a block. In case of error throws an error encapsulating useful information
* like node position
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
package com.smeup.rpgparser.smeup

open class MULANGT52FileAccess2Test : MULANGTTest()
import org.junit.Test
import kotlin.test.assertEquals

open class MULANGT52FileAccess2Test : MULANGTTest() {
/**
* Mock FEOD operation code
* @see #262
*/
@Test
fun executeT52_A07_P02() {
val expected = listOf("")
assertEquals(expected, "smeup/T52_A07_P02".outputOf())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
C FEOD MULANGTL
C '' DSPLY

0 comments on commit 48813ac

Please sign in to comment.