Skip to content

Commit 8d46af2

Browse files
committed
Add More Tests
1 parent 3153855 commit 8d46af2

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

liquidjava-verifier/src/test/java/liquidjava/rj_language/opt/ExpressionSimplifierTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,4 +666,37 @@ void testRepeatedEqualDefinitionPropagatesIntoTernaryCondition() {
666666

667667
assertEquals("explicit(param)", result.getValue().toString());
668668
}
669+
670+
@Test
671+
void testRepeatedEqualDefinitionsPropagateIntoCompoundTernaryCondition() {
672+
Expression expression = parse(
673+
"mode == 2 && other == 5 && ((mode == 2 && other == 5) ? explicit(param) : start(param))");
674+
ValDerivationNode result = ExpressionSimplifier.simplify(expression);
675+
676+
assertEquals("explicit(param)", result.getValue().toString());
677+
}
678+
679+
@Test
680+
void testRepeatedEqualDefinitionPropagatesWhenUsageComesFirst() {
681+
Expression expression = parse("(mode == 2 ? explicit(param) : start(param)) && mode == 2");
682+
ValDerivationNode result = ExpressionSimplifier.simplify(expression);
683+
684+
assertEquals("explicit(param)", result.getValue().toString());
685+
}
686+
687+
@Test
688+
void testRepeatedEqualDefinitionsPropagateIntoNestedTernaryConditions() {
689+
Expression expression = parse("mode == 2 && other == 3 && (mode == 2 ? (other == 3 ? a(p) : b(p)) : c(p))");
690+
ValDerivationNode result = ExpressionSimplifier.simplify(expression);
691+
692+
assertEquals("a(p)", result.getValue().toString());
693+
}
694+
695+
@Test
696+
void testRepeatedEqualDefinitionsPropagateIntoNestedTernaryElseBranch() {
697+
Expression expression = parse("mode == 2 && other == 4 && (mode == 2 ? (other == 3 ? a(p) : b(p)) : c(p))");
698+
ValDerivationNode result = ExpressionSimplifier.simplify(expression);
699+
700+
assertEquals("b(p)", result.getValue().toString());
701+
}
669702
}

liquidjava-verifier/src/test/java/liquidjava/rj_language/opt/VariableResolverTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,26 @@ void testRepeatedEqualDefinitionCountsAsUsage() {
108108
assertEquals("2", result.get("mode").toString());
109109
}
110110

111+
@Test
112+
void testRepeatedEqualDefinitionsInCompoundIteConditionCountAsUsage() {
113+
Expression expression = parse(
114+
"mode == 2 && other == 5 && ((mode == 2 && other == 5) ? explicit(param) : start(param))");
115+
Map<String, Expression> result = VariableResolver.resolve(expression);
116+
117+
assertEquals(2, result.size(), "Compound ternary condition should count as a use of both variables");
118+
assertEquals("2", result.get("mode").toString());
119+
assertEquals("5", result.get("other").toString());
120+
}
121+
122+
@Test
123+
void testRepeatedEqualDefinitionCountsAsUsageBeforeDefinitionConjunct() {
124+
Expression expression = parse("(mode == 2 ? explicit(param) : start(param)) && mode == 2");
125+
Map<String, Expression> result = VariableResolver.resolve(expression);
126+
127+
assertEquals(1, result.size(), "Conjunct order should not affect repeated equality usage detection");
128+
assertEquals("2", result.get("mode").toString());
129+
}
130+
111131
@Test
112132
void testReturnVariableIsNotSubstituted() {
113133
Expression expression = parse("x > 0 && #ret_1 == x");

0 commit comments

Comments
 (0)