use of org.sonar.java.se.ProgramState.Pop in project sonar-java by SonarSource.
the class ProgramStateTest method test_symbols_on_stack.
@Test
public void test_symbols_on_stack() {
ProgramState ps = ProgramState.EMPTY_STATE;
SymbolicValue sv = new SymbolicValue();
JavaSymbol.VariableJavaSymbol symbol = variable("a");
ps = ps.stackValue(sv, symbol);
Pop pop = ps.unstackValue(1);
assertThat(ps.peekValue()).isEqualTo(sv);
assertThat(ps.peekValueSymbol().symbol()).isEqualTo(symbol);
assertThat(pop.valuesAndSymbols.get(0).symbol()).isEqualTo(symbol);
assertThat(pop.valuesAndSymbols.get(0).symbolicValue()).isEqualTo(sv);
}
use of org.sonar.java.se.ProgramState.Pop in project sonar-java by SonarSource.
the class ProgramStateTest method testStackUnstack.
@Test
public void testStackUnstack() {
SymbolicValue sv1 = new SymbolicValue();
ProgramState state = ProgramState.EMPTY_STATE.stackValue(sv1);
assertThat(state.peekValue()).isSameAs(sv1);
SymbolicValue sv2 = new SymbolicValue();
state = state.stackValue(sv2);
List<SymbolicValue> values = state.peekValues(2);
assertThat(values).hasSize(2).containsSequence(sv2, sv1);
try {
state.peekValues(3);
Assert.fail("Able to retrieve more values than there are actually on the stack!");
} catch (IllegalStateException e) {
// Expected behavior
}
Pop unstack = state.unstackValue(1);
state = unstack.state;
values = unstack.values;
assertThat(values).hasSize(1);
assertThat(values.get(0)).isSameAs(sv2);
assertThat(state.peekValue()).isSameAs(sv1);
}
Aggregations