}
@Test
public void constants() {
Program program = new Program();
BasicBlock block = program.createBasicBlock();
ClassConstantInstruction classConstInsn = new ClassConstantInstruction();
classConstInsn.setConstant(ValueType.BYTE);
classConstInsn.setReceiver(program.createVariable());
block.getInstructions().add(classConstInsn);
NullConstantInstruction nullConstInsn = new NullConstantInstruction();
nullConstInsn.setReceiver(program.createVariable());
block.getInstructions().add(nullConstInsn);
IntegerConstantInstruction intConsInsn = new IntegerConstantInstruction();
intConsInsn.setReceiver(program.createVariable());
intConsInsn.setConstant(23);
block.getInstructions().add(intConsInsn);
LongConstantInstruction longConsInsn = new LongConstantInstruction();
longConsInsn.setReceiver(program.createVariable());
longConsInsn.setConstant(234);
block.getInstructions().add(longConsInsn);
FloatConstantInstruction floatConsInsn = new FloatConstantInstruction();
floatConsInsn.setReceiver(program.createVariable());
floatConsInsn.setConstant(3.14f);
block.getInstructions().add(floatConsInsn);
DoubleConstantInstruction doubleConsInsn = new DoubleConstantInstruction();
doubleConsInsn.setReceiver(program.createVariable());
doubleConsInsn.setConstant(3.14159);
block.getInstructions().add(doubleConsInsn);
StringConstantInstruction stringConsInsn = new StringConstantInstruction();
stringConsInsn.setReceiver(program.createVariable());
stringConsInsn.setConstant("foo");
block.getInstructions().add(stringConsInsn);
program = inputOutput(program);
block = program.basicBlockAt(0);
assertThat(block.getInstructions().size(), is(7));
assertThat(block.getInstructions().get(0), instanceOf(ClassConstantInstruction.class));
assertThat(block.getInstructions().get(1), instanceOf(NullConstantInstruction.class));
assertThat(block.getInstructions().get(2), instanceOf(IntegerConstantInstruction.class));
assertThat(block.getInstructions().get(3), instanceOf(LongConstantInstruction.class));
assertThat(block.getInstructions().get(4), instanceOf(FloatConstantInstruction.class));
assertThat(block.getInstructions().get(5), instanceOf(DoubleConstantInstruction.class));
assertThat(block.getInstructions().get(6), instanceOf(StringConstantInstruction.class));
classConstInsn = (ClassConstantInstruction)block.getInstructions().get(0);
assertThat(classConstInsn.getReceiver().getIndex(), is(0));
assertThat(classConstInsn.getConstant().toString(), is(ValueType.BYTE.toString()));
nullConstInsn = (NullConstantInstruction)block.getInstructions().get(1);
assertThat(nullConstInsn.getReceiver().getIndex(), is(1));
intConsInsn = (IntegerConstantInstruction)block.getInstructions().get(2);
assertThat(intConsInsn.getConstant(), is(23));
assertThat(intConsInsn.getReceiver().getIndex(), is(2));
longConsInsn = (LongConstantInstruction)block.getInstructions().get(3);
assertThat(longConsInsn.getConstant(), is(234L));
assertThat(longConsInsn.getReceiver().getIndex(), is(3));
floatConsInsn = (FloatConstantInstruction)block.getInstructions().get(4);
assertThat(floatConsInsn.getConstant(), is(3.14f));
assertThat(floatConsInsn.getReceiver().getIndex(), is(4));
doubleConsInsn = (DoubleConstantInstruction)block.getInstructions().get(5);
assertThat(doubleConsInsn.getConstant(), is(3.14159));
assertThat(doubleConsInsn.getReceiver().getIndex(), is(5));
stringConsInsn = (StringConstantInstruction)block.getInstructions().get(6);
assertThat(stringConsInsn.getConstant(), is("foo"));
assertThat(stringConsInsn.getReceiver().getIndex(), is(6));
}