@Test public void shouldPushTruePrimObjectFieldWhenVisitingTrueNode() { True aTrue = mock(True.class); analyser.visit(aTrue, 32); verify(writer).visitLine(32); verify(writer).pushObjectStaticField("TRUE"); }
@Test public void shouldInvokeArrayPutWhenVisitNumberInsideAnArray() { Number number = mock(Number.class); analyser.visit(number, "16", 32, true, 1); verify(writer).invokeObjectNumber("16", 1); verify(writer).invokeArrayPutAt(32, 1); }
@Test public void shouldInvokeArrayPutWhenVisitCharacterConstantInsideAnArray() { CharacterConstant characterConstant = mock(CharacterConstant.class); analyser.visit(characterConstant, "c", 32, true, 1); verify(writer).invokeObjectCharacter("c", 1); verify(writer).invokeArrayPutAt(32, 1); }
@Test public void shouldInvokeArrayPutWhenVisitSymbolInsideAnArray() { Symbol symbol = mock(Symbol.class); analyser.visit(symbol, "sym", 32, true, 1); verify(writer).invokeObjectSymbol("sym", 1); verify(writer).invokeArrayPutAt(32, 1); }
@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 shouldPushNilPrimObjectFieldWhenVisitingNilNode() { Nil nil = mock(Nil.class); analyser.visit(nil, 32); verify(writer).visitLine(32); verify(writer).pushObjectStaticField("NIL"); }
@Test public void shouldInvokeArrayPutWhenVisitStringConstantInsideAnArray() { StringConstant stringConstant = mock(StringConstant.class); analyser.visit(stringConstant, "hello", 32, true, 1); verify(writer).invokeObjectString("hello", 1); verify(writer).invokeArrayPutAt(32, 1); }
@Test public void shouldInvokePerformWhenVisitingUnarySelectorNode() { UnarySelector unarySelector = new UnarySelector("yourself", 42); analyser.visit(unarySelector, "yourself", 42); verify(writer).visitLine(42); verify(writer).invokeObjectPerform("yourself", 0, false); }
@Test public void shouldPushReceiverWhenVisitingSelfNode() { Self self = mock(Self.class); analyser.visit(self, 32); verify(writer).visitLine(32); verify(writer).pushReceiver(); }
@Test public void shouldPushFalsePrimObjectFieldWhenVisitingFalseNode() { False aFalse = mock(False.class); analyser.visit(aFalse, 32); verify(writer).visitLine(32); verify(writer).pushObjectStaticField("FALSE"); }
@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); }
@Test public void shouldRegisterArgumentWhenVisitingBlockArgument() { BlockArguments blockArguments = mock(BlockArguments.class); BlockArgument blockArgument = mock(BlockArgument.class); analyser.visitBegin(blockArguments, 1); analyser.visit(blockArgument, "arg", 1); assertNotNull(analyser.argumentsRegistry()); assertEquals(1, analyser.argumentsRegistry().size()); assertEquals(0, (int) analyser.argumentsRegistry().get("arg")); assertEquals(1, analyser.argumentsIndex()); }
@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 shouldInvokePrimObjectSymbolWhenVisitSymbol() { Symbol symbol = mock(Symbol.class); analyser.visit(symbol, "sym", 32, false, 1); verify(writer).invokeObjectSymbol("sym", 1); }
@Test public void shouldInvokePrimObjectSymbolWhenVisitSymbolConstant() { SymbolConstant symbolConstant = mock(SymbolConstant.class); analyser.visit(symbolConstant, "sym", 1); verify(writer).invokeObjectSymbol("sym", 1); }
@Test public void shouldInvokePrimObjectCharacterWhenVisitCharacterConstant() { CharacterConstant characterConstant = mock(CharacterConstant.class); analyser.visit(characterConstant, "c", 32, false, 1); verify(writer).invokeObjectCharacter("c", 1); }
@Test public void shouldInvokePrimObjectNumberWhenVisitNumber() { Number number = mock(Number.class); analyser.visit(number, "16", 32, false, 1); verify(writer).invokeObjectNumber("16", 1); }
@Test public void shouldInvokePrimObjectStringWhenVisitStringConstant() { StringConstant stringConstant = mock(StringConstant.class); analyser.visit(stringConstant, "hello", 0, false, 1); verify(writer).invokeObjectString("hello", 1); }