Skip to content

Commit

Permalink
fix: switch case with eps parameter type
Browse files Browse the repository at this point in the history
  • Loading branch information
Sayakie authored and wysohn committed Dec 9, 2023
1 parent b1144b4 commit 2bb97b1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,9 @@ private void start(Node node, InterpreterLocalContext localContext) throws Inter
parameterToken = tryUnwrapVariable(rawParameterToken, localContext);
}

if (variableType != Type.EPS && !variableType.equals(parameterToken.getType())) {
throw new InterpreterException("Mismatched type for parameter " + rawParameterToken + "! Expected " + variableType + " but found " + parameterToken.getType());
final Type parameterType = parameterToken.getType();
if (variableType != Type.EPS && parameterType != Type.EPS && !variableType.equals(parameterType)) {
throw new InterpreterException("Mismatched type for parameter " + rawParameterToken + "! Expected " + variableType + " but found " + parameterType);
}

if (variableNameToken.getValue().equals(parameterToken.getValue())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3657,6 +3657,33 @@ public void testSwitchWithEnum_SyntacticSugarForEnumByString2() throws Exception
verifyNoInteractions(failExecutor);
}

@Test
public void testSwitch_EpsParameterType() throws Exception {
// arrange
final String text = ""
+ "SWITCH 1557\n"
+ " CASE parseInt(\"1557\") => #PASS\n"
+ " DEFAULT => #FAIL\n"
+ "ENDSWITCH";

// act
final Executor passExecutor = mock(Executor.class);
final Executor failExecutor = mock(Executor.class);
when(passExecutor.evaluate(any(), anyMap(), any(), any())).thenReturn(null);
when(failExecutor.evaluate(any(), anyMap(), any(), any())).thenReturn(null);

final InterpreterTest test = InterpreterTest.Builder.of(text)
.putExecutor("PASS", passExecutor)
.putExecutor("FAIL", failExecutor)
.overrideSelfReference(new CommonFunctions())
.build();
test.test();

// assert
verify(passExecutor).evaluate(any(), anyMap(), any(), any());
verifyNoInteractions(failExecutor);
}

@Test
public void testLambdaInvokeFunction() throws Exception {
// arrange
Expand Down

0 comments on commit 2bb97b1

Please sign in to comment.