Skip to content

Commit 1ee7d1d

Browse files
l46kokcopybara-github
authored andcommitted
Add missing entires to REVERSE_OPERATORS
PiperOrigin-RevId: 798311803
1 parent 4d114d6 commit 1ee7d1d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

parser/src/main/java/dev/cel/parser/Operator.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,34 @@ static Optional<Operator> find(String text) {
103103
private static final ImmutableMap<String, Operator> REVERSE_OPERATORS =
104104
ImmutableMap.<String, Operator>builder()
105105
.put(ADD.getFunction(), ADD)
106+
.put(ALL.getFunction(), ALL)
107+
.put(CONDITIONAL.getFunction(), CONDITIONAL)
106108
.put(DIVIDE.getFunction(), DIVIDE)
107109
.put(EQUALS.getFunction(), EQUALS)
110+
.put(EXISTS.getFunction(), EXISTS)
111+
.put(EXISTS_ONE.getFunction(), EXISTS_ONE)
112+
.put(FILTER.getFunction(), FILTER)
108113
.put(GREATER.getFunction(), GREATER)
109114
.put(GREATER_EQUALS.getFunction(), GREATER_EQUALS)
115+
.put(HAS.getFunction(), HAS)
110116
.put(IN.getFunction(), IN)
117+
.put(INDEX.getFunction(), INDEX)
111118
.put(LESS.getFunction(), LESS)
112119
.put(LESS_EQUALS.getFunction(), LESS_EQUALS)
113120
.put(LOGICAL_AND.getFunction(), LOGICAL_AND)
114121
.put(LOGICAL_NOT.getFunction(), LOGICAL_NOT)
115122
.put(LOGICAL_OR.getFunction(), LOGICAL_OR)
123+
.put(MAP.getFunction(), MAP)
116124
.put(MODULO.getFunction(), MODULO)
117125
.put(MULTIPLY.getFunction(), MULTIPLY)
118126
.put(NEGATE.getFunction(), NEGATE)
119127
.put(NOT_EQUALS.getFunction(), NOT_EQUALS)
120-
.put(SUBTRACT.getFunction(), SUBTRACT)
128+
.put(NOT_STRICTLY_FALSE.getFunction(), NOT_STRICTLY_FALSE)
121129
.put(OLD_IN.getFunction(), OLD_IN)
130+
.put(OLD_NOT_STRICTLY_FALSE.getFunction(), OLD_NOT_STRICTLY_FALSE)
131+
.put(OPTIONAL_INDEX.getFunction(), OPTIONAL_INDEX)
132+
.put(OPTIONAL_SELECT.getFunction(), OPTIONAL_SELECT)
133+
.put(SUBTRACT.getFunction(), SUBTRACT)
122134
.buildOrThrow();
123135

124136
// precedence of the operator, where the higher value means higher.
@@ -169,7 +181,7 @@ static Optional<Operator> find(String text) {
169181
.buildOrThrow();
170182

171183
/** Lookup an operator by its mangled name, as used within the AST. */
172-
static Optional<Operator> findReverse(String op) {
184+
public static Optional<Operator> findReverse(String op) {
173185
return Optional.ofNullable(REVERSE_OPERATORS.get(op));
174186
}
175187

parser/src/test/java/dev/cel/parser/OperatorTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.junit.Assert.assertFalse;
2020
import static org.junit.Assert.assertTrue;
2121

22+
import com.google.testing.junit.testparameterinjector.TestParameter;
2223
import com.google.testing.junit.testparameterinjector.TestParameterInjector;
2324
import com.google.testing.junit.testparameterinjector.TestParameters;
2425
import dev.cel.common.ast.CelExpr;
@@ -50,6 +51,11 @@ public void findReverse_returnsCorrectOperator() {
5051
assertThat(Operator.findReverse("_+_")).hasValue(Operator.ADD);
5152
}
5253

54+
@Test
55+
public void findReverse_allOperators(@TestParameter Operator operator) {
56+
assertThat(Operator.findReverse(operator.getFunction())).hasValue(operator);
57+
}
58+
5359
@Test
5460
public void findReverseBinaryOperator_returnsEmptyWhenNotFound() {
5561
assertThat(Operator.findReverseBinaryOperator("+")).isEmpty();

0 commit comments

Comments
 (0)