@@ -159,6 +159,8 @@ public void setUp() {
159159
160160 private enum IsSatisfiableTestCase {
161161 SATISFIABLE ("x > 5" , "x = (?:[6-9]|[1-9]\\ d+)" ),
162+ OPTIONAL_OR_VALUE_SKIPS_APPROXIMATE_ALTERNATIVE (
163+ "optional.of(x).orValue(int('123')) == 7" , "x = 7" ),
162164 DYNAMIC_ARITHMETIC ("request == 1 && request + 2 == 3" , "request = 1" ),
163165 DYNAMIC_ARITHMETIC_UNARY ("request == 1 && -request == -1" , "request = 1" ),
164166 GREATER_DOUBLE ("d > 1.5" , "d = " ),
@@ -689,6 +691,11 @@ public void isSatisfiable_approximate_returnsPotentialSatisfyingInput() throws E
689691 }
690692
691693 private enum IsSatisfiableInconclusiveTestCase {
694+ OPTIONAL_OR_VALUE_EMPTY_RECEIVER_APPROXIMATE_ALTERNATIVE (
695+ "optional.none().orValue(int('123')) == 7" ),
696+ OPTIONAL_OR_VALUE_APPROXIMATE_RECEIVER ("optional.of(int('123')).orValue(1) == 7" ),
697+ OPTIONAL_OR_EMPTY_RECEIVER_APPROXIMATE_ALTERNATIVE (
698+ "optional.none().or(optional.of(int('123'))) == optional.of(7)" ),
692699 // A list of nullable ints may hold null past the unroll limit.
693700 NULL_IN_NULLABLE_LIST_PAST_UNROLL_LIMIT (
694701 "size(nullable_int_list) == 6 && nullable_int_list[0] != null && nullable_int_list[1] !="
@@ -834,6 +841,7 @@ public void isSatisfiable_comprehensionZeroUnrollLimit_inconclusive() throws Exc
834841 }
835842
836843 private enum IsUnsatisfiableTestCase {
844+ OPTIONAL_OR_NON_OPTIONAL_ALTERNATIVE ("optional.none().or(dyn(x)) == dyn(x)" ),
837845 DYN_MESSAGE_PRESENT_UNDECLARED_FIELD ("dyn(test_all_types).unknown_field == 42" ),
838846 REPEATED_FIELD_FROM_NON_LIST (
839847 "dyn_var == 42 && TestAllTypes{repeated_int64: dyn_var} == TestAllTypes{}" ),
@@ -1225,6 +1233,9 @@ private enum IsAlwaysTrueTestCase {
12251233 OPTIONAL_OF_EQ_OF_VAR ("optional.of(x) == optional.of(x)" ),
12261234 OPTIONAL_OF_NEQ_OF_VAR ("x != y ? optional.of(x) != optional.of(y) : true" ),
12271235 OPTIONAL_OR_VALUE_VAR ("optional.of(x).orValue(y) == x" ),
1236+ OPTIONAL_OR_VALUE_SKIPS_FAILING_ALTERNATIVE ("optional.of(x).orValue(1 / 0) == x" ),
1237+ OPTIONAL_OR_SKIPS_FAILING_ALTERNATIVE (
1238+ "optional.of(x).or(optional.of(1 / 0)) == optional.of(x)" ),
12281239 // Indexing follows the value, whatever type the checker narrowed it to.
12291240 NARROWED_MAP_INDEXED_AS_LIST (
12301241 "dyn_var == optional.of([2]) ? dyn_var.orValue({0: 1})[0] == 2 : true" ),
@@ -1778,6 +1789,19 @@ public void verifyEquivalence_withUnknownIdentifiers_inconclusive(
17781789 assertThat (result .status ()).isEqualTo (VerificationStatus .INCONCLUSIVE );
17791790 }
17801791
1792+ @ Test
1793+ public void verifyEquivalence_orValueOfNonOptionalWithUnknownAlternative_verified ()
1794+ throws Exception {
1795+ CelVerifier verifier =
1796+ CelVerifierFactory .newVerifier (CEL ).addUnknownIdentifier ("unknown_var" ).build ();
1797+ CelAbstractSyntaxTree astA = CEL .compile ("dyn(1).orValue(unknown_var)" ).getAst ();
1798+ CelAbstractSyntaxTree astB = CEL .compile ("1 / 0" ).getAst ();
1799+
1800+ CelVerificationResult result = verifier .verifyEquivalence (astA , astB );
1801+
1802+ assertThat (result .status ()).isEqualTo (VerificationStatus .VERIFIED );
1803+ }
1804+
17811805 @ Test
17821806 public void verifyEquivalence_freeVariableIndicesDeduplicated () throws Exception {
17831807 CelAbstractSyntaxTree astA =
@@ -2514,6 +2538,9 @@ public void isAlwaysTrue_inconclusive_containsPotentialCounterexample() throws E
25142538 }
25152539
25162540 private enum EquivalenceInconclusiveTestCase {
2541+ OPTIONAL_OR_VALUE_OF_TRUNCATED_RECEIVER (
2542+ "size(int_list) > 5 ? int_list.map(n, optional.none())[0].orValue(1) : 0" ,
2543+ "size(int_list) > 5 ? int_list.map(n, optional.none())[0].orValue(2) : 0" ),
25172544 // A list or map typed dyn holding NaN (e.g. `[NaN]`) differs from itself, so these do diverge,
25182545 // but lists and maps typed dyn on both sides compare approximately.
25192546 DYN_NAN_INPUT_AND_LITERAL ("dyn_var != dyn_var ? 0.0 / 0.0 : dyn_var" , "dyn_var" ),
@@ -2641,6 +2668,7 @@ public void verifyEquivalence_inconclusive(
26412668 }
26422669
26432670 private enum EquivalenceTestCase {
2671+ OPTIONAL_OR_VALUE_OF_NON_OPTIONAL ("dyn(1).orValue(int('123'))" , "1 / 0" ),
26442672 STRUCT_UNSET_TIMESTAMP_DEFAULT ("TestAllTypes{}.single_timestamp" , "timestamp(0)" ),
26452673 // Both are errors.
26462674 STRUCT_UNSET_ANY_DEFAULT ("TestAllTypes{}.single_any == null" , "1 / 0 == 1" ),
@@ -3188,6 +3216,8 @@ private enum EquivalenceViolationTestCase {
31883216 CROSS_TYPE_SYMBOLIC_INEQUALITY_INT_UINT ("dyn(x) == dyn(u)" , "false" ),
31893217 CROSS_TYPE_SYMBOLIC_INEQUALITY_UINT_INT ("dyn(u) == dyn(x)" , "false" ),
31903218 OPTIONAL_OR_VALUE_VIOLATION ("optional.of(x).orValue(y)" , "y" ),
3219+ OPTIONAL_OR_VALUE_FAILING_ALTERNATIVE (
3220+ "optional.of(x).orValue(1 / 0)" , "optional.of(y).orValue(1 / 0)" ),
31913221 OPTIONAL_VALUE_VIOLATION ("optional.of(x).value()" , "y" ),
31923222 LIST_OPTIONAL_ELEMENTS_COLLISION ("[1, ?opt_var]" , "[1, opt_var]" ),
31933223 CROSS_NUMERIC_EQUALITY_INT_DYN_VIOLATION ("1 == request" , "false" ),
0 commit comments