66
77import liquidjava .processor .context .*;
88import liquidjava .rj_language .Predicate ;
9- import liquidjava .rj_language .ast .*;
109import org .junit .jupiter .api .BeforeEach ;
1110import org .junit .jupiter .api .Test ;
1211
1514import spoon .reflect .reference .CtTypeReference ;
1615
1716/**
18- * Integration tests for Context management with variables, functions, ghosts, and refinements
19- * These tests verify that multiple components work together correctly in realistic scenarios
17+ * Integration tests for Context management with variables, functions, ghosts, and refinements These tests verify that
18+ * multiple components work together correctly in realistic scenarios
2019 */
2120class ContextIntegrationTest {
2221
@@ -35,35 +34,25 @@ void setUp() {
3534 void testCompleteVariableLifecycle () {
3635 // Scenario: Create variables, enter/exit contexts, track refinements
3736 CtTypeReference <Integer > intType = factory .Type ().integerPrimitiveType ();
38- Predicate initialPred = Predicate .createOperation (
39- Predicate .createVar ("x" ),
40- ">" ,
41- Predicate .createLit ("0" , "int" )
42- );
37+ Predicate initialPred = Predicate .createOperation (Predicate .createVar ("x" ), ">" ,
38+ Predicate .createLit ("0" , "int" ));
4339
4440 // Add variable in base scope
4541 context .addVarToContext ("x" , intType , initialPred , factory .createLiteral (0 ));
4642 assertTrue (context .hasVariable ("x" ), "Variable should exist in base scope" );
4743
4844 // Enter new scope and add local variable
4945 context .enterContext ();
50- Predicate localPred = Predicate .createOperation (
51- Predicate .createVar ("y" ),
52- "<" ,
53- Predicate .createLit ("100" , "int" )
54- );
46+ Predicate localPred = Predicate .createOperation (Predicate .createVar ("y" ), "<" ,
47+ Predicate .createLit ("100" , "int" ));
5548 context .addVarToContext ("y" , intType , localPred , factory .createLiteral (0 ));
5649
5750 assertTrue (context .hasVariable ("x" ), "Base scope variable accessible in nested scope" );
5851 assertTrue (context .hasVariable ("y" ), "Local variable exists" );
5952 assertEquals (2 , context .getAllVariables ().size (), "Should have 2 variables" );
6053
6154 // Update refinement for x
62- Predicate newPred = Predicate .createOperation (
63- Predicate .createVar ("x" ),
64- ">=" ,
65- Predicate .createLit ("5" , "int" )
66- );
55+ Predicate newPred = Predicate .createOperation (Predicate .createVar ("x" ), ">=" , Predicate .createLit ("5" , "int" ));
6756 context .newRefinementToVariableInContext ("x" , newPred );
6857 assertEquals (newPred .toString (), context .getVariableRefinements ("x" ).toString ());
6958
@@ -84,15 +73,12 @@ void testFunctionRegistrationAndRetrieval() {
8473 func .setName ("calculate" );
8574 func .setClass ("MathUtils" );
8675 func .setType (intType );
87- func .addArgRefinements ("x" , intType , Predicate .createOperation (
88- Predicate .createVar ("x" ), ">" , Predicate .createLit ("0" , "int" )
89- ));
90- func .addArgRefinements ("y" , intType , Predicate .createOperation (
91- Predicate .createVar ("y" ), ">" , Predicate .createLit ("0" , "int" )
92- ));
93- func .setRefReturn (Predicate .createOperation (
94- Predicate .createVar ("result" ), ">" , Predicate .createLit ("0" , "int" )
95- ));
76+ func .addArgRefinements ("x" , intType ,
77+ Predicate .createOperation (Predicate .createVar ("x" ), ">" , Predicate .createLit ("0" , "int" )));
78+ func .addArgRefinements ("y" , intType ,
79+ Predicate .createOperation (Predicate .createVar ("y" ), ">" , Predicate .createLit ("0" , "int" )));
80+ func .setRefReturn (
81+ Predicate .createOperation (Predicate .createVar ("result" ), ">" , Predicate .createLit ("0" , "int" )));
9682
9783 context .addFunctionToContext (func );
9884
@@ -124,17 +110,14 @@ void testGhostStatesAndRefinements() {
124110 // Define states using GhostState
125111 List <CtTypeReference <?>> emptyList = List .of ();
126112 GhostState isEmpty = new GhostState ("isEmpty" , emptyList , factory .Type ().booleanPrimitiveType (), "Stack" );
127- isEmpty .setRefinement (Predicate .createEquals (
128- Predicate .createInvocation ("Stack.size" , Predicate .createVar ("this" )),
129- Predicate .createLit ("0" , "int" )
130- ));
113+ isEmpty .setRefinement (
114+ Predicate .createEquals (Predicate .createInvocation ("Stack.size" , Predicate .createVar ("this" )),
115+ Predicate .createLit ("0" , "int" )));
131116
132117 GhostState isNonEmpty = new GhostState ("isNonEmpty" , emptyList , factory .Type ().booleanPrimitiveType (), "Stack" );
133- isNonEmpty .setRefinement (Predicate .createOperation (
134- Predicate .createInvocation ("Stack.size" , Predicate .createVar ("this" )),
135- ">" ,
136- Predicate .createLit ("0" , "int" )
137- ));
118+ isNonEmpty .setRefinement (
119+ Predicate .createOperation (Predicate .createInvocation ("Stack.size" , Predicate .createVar ("this" )), ">" ,
120+ Predicate .createLit ("0" , "int" )));
138121
139122 context .addToGhostClass ("Stack" , isEmpty );
140123 context .addToGhostClass ("Stack" , isNonEmpty );
@@ -158,7 +141,7 @@ void testVariableInstanceTracking() {
158141
159142 // Simulate assignment: x = 5
160143 VariableInstance instance1 = new VariableInstance ("x_1" , intType ,
161- Predicate .createEquals (Predicate .createVar ("x_1" ), Predicate .createLit ("5" , "int" )));
144+ Predicate .createEquals (Predicate .createVar ("x_1" ), Predicate .createLit ("5" , "int" )));
162145 var .addInstance (instance1 );
163146 context .addSpecificVariable (instance1 );
164147 context .addRefinementInstanceToVariable ("x" , "x_1" );
@@ -168,8 +151,8 @@ void testVariableInstanceTracking() {
168151
169152 // Simulate second assignment: x = x + 1
170153 VariableInstance instance2 = new VariableInstance ("x_2" , intType ,
171- Predicate .createEquals (Predicate .createVar ("x_2" ),
172- Predicate .createOperation (Predicate .createVar ("x_1" ), "+" , Predicate .createLit ("1" , "int" ))));
154+ Predicate .createEquals (Predicate .createVar ("x_2" ),
155+ Predicate .createOperation (Predicate .createVar ("x_1" ), "+" , Predicate .createLit ("1" , "int" ))));
173156 var .addInstance (instance2 );
174157 context .addSpecificVariable (instance2 );
175158 context .addRefinementInstanceToVariable ("x" , "x_2" );
@@ -190,13 +173,13 @@ void testIfBranchCombination() {
190173
191174 // Then branch: x = 10
192175 VariableInstance thenInstance = new VariableInstance ("x_then" , intType ,
193- Predicate .createEquals (Predicate .createVar ("x_then" ), Predicate .createLit ("10" , "int" )));
176+ Predicate .createEquals (Predicate .createVar ("x_then" ), Predicate .createLit ("10" , "int" )));
194177 var .addInstance (thenInstance );
195178 context .variablesSetThenIf ();
196179
197180 // Else branch: x = 20
198181 VariableInstance elseInstance = new VariableInstance ("x_else" , intType ,
199- Predicate .createEquals (Predicate .createVar ("x_else" ), Predicate .createLit ("20" , "int" )));
182+ Predicate .createEquals (Predicate .createVar ("x_else" ), Predicate .createLit ("20" , "int" )));
200183 var .addInstance (elseInstance );
201184 context .variablesSetElseIf ();
202185
@@ -221,14 +204,12 @@ void testComplexScenarioWithMultipleComponents() {
221204 processFunc .setClass ("Processor" );
222205 processFunc .setType (intType );
223206
224- Predicate precondition = Predicate .createOperation (
225- Predicate .createVar ("input" ), ">" , Predicate .createLit ("0" , "int" )
226- );
207+ Predicate precondition = Predicate .createOperation (Predicate .createVar ("input" ), ">" ,
208+ Predicate .createLit ("0" , "int" ));
227209 processFunc .addArgRefinements ("input" , intType , precondition );
228210
229- Predicate postcondition = Predicate .createOperation (
230- Predicate .createVar ("result" ), ">=" , Predicate .createVar ("input" )
231- );
211+ Predicate postcondition = Predicate .createOperation (Predicate .createVar ("result" ), ">=" ,
212+ Predicate .createVar ("input" ));
232213 processFunc .setRefReturn (postcondition );
233214
234215 context .addFunctionToContext (processFunc );
@@ -253,7 +234,7 @@ void testGlobalVariableManagement() {
253234 CtTypeReference <Integer > intType = factory .Type ().integerPrimitiveType ();
254235
255236 context .addGlobalVariableToContext ("GLOBAL_CONST" , intType ,
256- Predicate .createEquals (Predicate .createVar ("GLOBAL_CONST" ), Predicate .createLit ("42" , "int" )));
237+ Predicate .createEquals (Predicate .createVar ("GLOBAL_CONST" ), Predicate .createLit ("42" , "int" )));
257238
258239 assertTrue (context .hasVariable ("GLOBAL_CONST" ), "Global variable should exist" );
259240
0 commit comments