@Test public void shouldInitializeTemporaryRegistryWhenVisitingTemporaries() { Temporaries temporaries = mock(Temporaries.class); analyser.visitBegin(temporaries); assertNotNull(analyser.temporariesRegistry()); assertEquals(0, analyser.temporariesRegistry().size()); }
@Test public void shouldRegisterTemporaryWhenVisitingTemporary() { Temporaries temporaries = mock(Temporaries.class); Temporary temporary = mock(Temporary.class); analyser.visitBegin(temporaries); analyser.visit(temporary, "temp", 1); assertNotNull(analyser.temporariesRegistry()); assertEquals(1, analyser.temporariesRegistry().size()); assertEquals(0, (int) analyser.temporariesRegistry().get("temp")); assertEquals(1, analyser.temporariesIndex()); }
@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 public void shouldHaveNoTemporariesRegistryWhenCreated() { ProgramAnalyser programAnalyser = new ProgramAnalyser(parent, "foo", "com.domain", false); assertNull(programAnalyser.temporariesRegistry()); assertEquals(0, programAnalyser.temporariesIndex()); }