Skip to content

Commit 5de96a5

Browse files
authored
Add two var comprehensions to repl (#1167)
1 parent 2aa9572 commit 5de96a5

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

repl/evaluator.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ import (
4343

4444
var (
4545
extensionMap = map[string]cel.EnvOption{
46-
"optional": cel.OptionalTypes(),
47-
"bindings": ext.Bindings(),
48-
"strings": ext.Strings(),
49-
"protos": ext.Protos(),
50-
"math": ext.Math(),
51-
"encoders": ext.Encoders(),
52-
"sets": ext.Sets(),
53-
"lists": ext.Lists(),
46+
"optional": cel.OptionalTypes(),
47+
"bindings": ext.Bindings(),
48+
"strings": ext.Strings(),
49+
"protos": ext.Protos(),
50+
"math": ext.Math(),
51+
"encoders": ext.Encoders(),
52+
"sets": ext.Sets(),
53+
"lists": ext.Lists(),
54+
"two_var_comprehensions": ext.TwoVarComprehensions(),
5455
}
5556
)
5657

repl/evaluator_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,8 @@ func TestProcess(t *testing.T) {
709709
expr: "'test'.substring(2) == 'st' && " +
710710
"proto.getExt(google.expr.proto2.test.ExampleType{}, google.expr.proto2.test.int32_ext) == 0 && " +
711711
"math.greatest(1,2) == 2 && " +
712-
"base64.encode(b'hello') == 'aGVsbG8='",
712+
"base64.encode(b'hello') == 'aGVsbG8=' && " +
713+
"{'key': 1}.exists(k, v, k == 'key' && v == 1)",
713714
},
714715
},
715716
wantText: "true : bool",
@@ -1040,7 +1041,7 @@ func TestProcessOptionError(t *testing.T) {
10401041
"'bogus'",
10411042
},
10421043
},
1043-
errorMsg: "extension: Unknown option: 'bogus'. Available options are: ['all', 'bindings', 'encoders', 'lists', 'math', 'optional', 'protos', 'sets', 'strings']",
1044+
errorMsg: "extension: Unknown option: 'bogus'. Available options are: ['all', 'bindings', 'encoders', 'lists', 'math', 'optional', 'protos', 'sets', 'strings', 'two_var_comprehensions']",
10441045
},
10451046
}
10461047

repl/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/google/cel-go/repl
33
go 1.22.0
44

55
require (
6-
cel.dev/expr v0.22.1
6+
cel.dev/expr v0.23.1
77
github.com/antlr4-go/antlr/v4 v4.13.0
88
github.com/chzyer/readline v1.5.1
99
github.com/google/cel-go v0.0.0-00010101000000-000000000000

repl/main/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ into a protocol buffer text format representing the type-checked AST.
5050

5151
`%compile <expr>`
5252

53-
Example:
53+
Example:
5454

5555
```
5656
> %compile 3u
@@ -158,14 +158,15 @@ may take string arguments.
158158

159159
`--container <string>` sets the expression container for name resolution.
160160

161-
`--extension <extensionType>` enables CEL extensions. Valid options are:
162-
`strings`, `protos`, `math`, `encoders`, `optional`, `bindings`, and `all`.
161+
`--extension <extensionType>` enables CEL extensions. Valid options are:
162+
`strings`, `protos`, `math`, `encoders`, `optional`, `bindings`,
163+
`two_var_comprehensions` and `all` (enables all extensions).
163164

164165
`--enable_partial_eval` enables partial evaluations
165166

166167
example:
167168

168-
`%option --container 'google.protobuf'`
169+
`%option --container 'google.protobuf'`
169170

170171
`%option --extension 'strings'`
171172

@@ -175,7 +176,7 @@ example:
175176

176177
#### reset
177178

178-
`%reset` drops all options and let expressions, returning the evaluator to a
179+
`%reset` drops all options and let expressions, returning the evaluator to a
179180
starting empty state.
180181

181182
### Evaluation Model

0 commit comments

Comments
 (0)