@Test public void shouldInvokeVariableAtWhenVisitIdentifierOnLoadSideOfExpression() { Identifier identifier = mock(Identifier.class); when(identifier.isOnLoadSideOfExpression()).thenReturn(true); analyser.visit(identifier, "var", 3); verify(writer).invokeVariableAt("var", 3); }
@Test public void shouldStoreTemporaryWhenVisitTemporaryOnStoreSideOfExpression() { Identifier identifier = mock(Identifier.class); when(identifier.isOnLoadSideOfExpression()).thenReturn(false); analyser.initializeTemporariesRegistration(); analyser.temporariesRegistry().put("tmp", 1); analyser.visit(identifier, "tmp", 3); verify(writer).storeTemporary(1); }
@Test(expected = RedlineException.class) public void shouldNotAllowStoreIntoMethodOrBlockArgument() { Identifier identifier = mock(Identifier.class); when(identifier.isOnLoadSideOfExpression()).thenReturn(false); analyser.initializeBlockArgumentsRegistration(); analyser.argumentsRegistry().put("arg", 1); analyser.initializeTemporariesRegistration(); analyser.visit(identifier, "arg", 3); }
@Test public void shouldPushArgumentWhenVisitArgumentOnLoadSideOfExpression() { Identifier identifier = mock(Identifier.class); when(identifier.isOnLoadSideOfExpression()).thenReturn(true); analyser.initializeBlockArgumentsRegistration(); analyser.argumentsRegistry().put("arg", 1); analyser.visit(identifier, "arg", 3); verify(writer).pushArgument(1); }