From 4fba7c7152d20a50fa7179cd1c68c2b85d15c193 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 26 Aug 2026 10:58:58 +0000 Subject: [PATCH 1/4] Bump the protobuf-es group across 1 directory with 2 updates Bumps the protobuf-es group with 1 update in the / directory: [@bufbuild/protoc-gen-es](https://github.com/bufbuild/protobuf-es/tree/HEAD/packages/protoc-gen-es). Updates `@bufbuild/protoc-gen-es` from 2.10.2 to 2.14.0 - [Release notes](https://github.com/bufbuild/protobuf-es/releases) - [Commits](https://github.com/bufbuild/protobuf-es/commits/v2.14.0/packages/protoc-gen-es) Updates `@bufbuild/protobuf` from 2.10.2 to 2.14.0 - [Release notes](https://github.com/bufbuild/protobuf-es/releases) - [Commits](https://github.com/bufbuild/protobuf-es/commits/v2.14.0/packages/protobuf) --- updated-dependencies: - dependency-name: "@bufbuild/protobuf" dependency-version: 2.11.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: protobuf-es - dependency-name: "@bufbuild/protoc-gen-es" dependency-version: 2.11.0 dependency-type: direct:development update-type: version-update:semver-minor dependency-group: protobuf-es ... Signed-off-by: dependabot[bot] --- package-lock.json | 38 +++++++++++++++++++------------------- package.json | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index 038bc32f..8bc60885 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "@biomejs/biome": "^1.9.4", "@bufbuild/buf": "^1.64.0", "@bufbuild/license-header": "^0.0.4", - "@bufbuild/protoc-gen-es": "^2.10.2", + "@bufbuild/protoc-gen-es": "^2.14.0", "@types/node": "^25.1.0", "tsx": "^4.23.1", "turbo": "^2.10.7", @@ -421,29 +421,29 @@ } }, "node_modules/@bufbuild/protobuf": { - "version": "2.10.2", - "resolved": "https://registry.npmjs.org/@bufbuild/protobuf/-/protobuf-2.10.2.tgz", - "integrity": "sha512-uFsRXwIGyu+r6AMdz+XijIIZJYpoWeYzILt5yZ2d3mCjQrWUTVpVD9WL/jZAbvp+Ed04rOhrsk7FiTcEDseB5A==", + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/@bufbuild/protobuf/-/protobuf-2.14.0.tgz", + "integrity": "sha512-C3UGsiCwSprE2NKIIFA3hCDlpXTMCAXRZuEVp88L1GY36Y41+rYL5fryE+nOFhp4p4JPQvdV8PQ4DWgHgeTE+w==", "license": "(Apache-2.0 AND BSD-3-Clause)" }, "node_modules/@bufbuild/protoc-gen-es": { - "version": "2.10.2", - "resolved": "https://registry.npmjs.org/@bufbuild/protoc-gen-es/-/protoc-gen-es-2.10.2.tgz", - "integrity": "sha512-vbjPsuofbtZwZXuOP7Y16CQsxrwCjuRONffmJSBEhoC7PQu/Cabp0+Fu/poLPm9CNM0tDCQA0xvgobgudaEYxQ==", + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/@bufbuild/protoc-gen-es/-/protoc-gen-es-2.14.0.tgz", + "integrity": "sha512-/Rrui0BJWSRONiKGYzqWq9ivGN3+cYkmc47QWITufr7K6yDb8HfssuJUSQZeptyg/rHbHrfDzCUjzoJ2pwuafg==", "dev": true, "license": "Apache-2.0", "dependencies": { - "@bufbuild/protobuf": "2.10.2", - "@bufbuild/protoplugin": "2.10.2" + "@bufbuild/protobuf": "2.14.0", + "@bufbuild/protoplugin": "2.14.0" }, "bin": { "protoc-gen-es": "bin/protoc-gen-es" }, "engines": { - "node": ">=20" + "node": ">=22" }, "peerDependencies": { - "@bufbuild/protobuf": "2.10.2" + "@bufbuild/protobuf": "2.14.0" }, "peerDependenciesMeta": { "@bufbuild/protobuf": { @@ -452,13 +452,13 @@ } }, "node_modules/@bufbuild/protoplugin": { - "version": "2.10.2", - "resolved": "https://registry.npmjs.org/@bufbuild/protoplugin/-/protoplugin-2.10.2.tgz", - "integrity": "sha512-RAWVs9tCzRqSS3tUtaFhOcauOAazCrm7tlGh0WHFq/44n5Fj6YgefdlZEPIaAK6VAA+FdOoFgtOJK2Ji5U24pw==", + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/@bufbuild/protoplugin/-/protoplugin-2.14.0.tgz", + "integrity": "sha512-S0TvZhVtTEkZQRj2JsXBCXiib/b0+bLQtJCcn+hj9O/usgbcgxHn4D+ii22Ao3qj0/kKxVYeo7BtAI2dMk+iig==", "dev": true, "license": "Apache-2.0", "dependencies": { - "@bufbuild/protobuf": "2.10.2", + "@bufbuild/protobuf": "2.14.0", "@typescript/vfs": "^1.6.2", "typescript": "5.4.5" } @@ -1090,13 +1090,13 @@ } }, "node_modules/@typescript/vfs": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/@typescript/vfs/-/vfs-1.6.2.tgz", - "integrity": "sha512-hoBwJwcbKHmvd2QVebiytN1aELvpk9B74B4L1mFm/XT1Q/VOYAWl2vQ9AWRFtQq8zmz6enTpfTV8WRc4ATjW/g==", + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@typescript/vfs/-/vfs-1.6.4.tgz", + "integrity": "sha512-PJFXFS4ZJKiJ9Qiuix6Dz/OwEIqHD7Dme1UwZhTK11vR+5dqW2ACbdndWQexBzCx+CPuMe5WBYQWCsFyGlQLlQ==", "dev": true, "license": "MIT", "dependencies": { - "debug": "^4.1.1" + "debug": "^4.4.3" }, "peerDependencies": { "typescript": "*" diff --git a/package.json b/package.json index 07b52f46..87bcff14 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@biomejs/biome": "^1.9.4", "@bufbuild/buf": "^1.64.0", "@bufbuild/license-header": "^0.0.4", - "@bufbuild/protoc-gen-es": "^2.10.2", + "@bufbuild/protoc-gen-es": "^2.14.0", "@types/node": "^25.1.0", "tsx": "^4.23.1", "turbo": "^2.10.7", From d680c2db69fd96265e0d992bfe1944b54980164d Mon Sep 17 00:00:00 2001 From: Timo Stamm Date: Wed, 26 Aug 2026 13:17:40 +0200 Subject: [PATCH 2/4] generate --- .../cel-spec/src/gen/cel/expr/checked_pb.ts | 22 ++++----- .../conformance/conformance_service_pb.ts | 18 +++---- .../gen/cel/expr/conformance/env_config_pb.ts | 8 ++-- .../proto2/test_all_types_extensions_pb.ts | 2 +- .../conformance/proto2/test_all_types_pb.ts | 44 ++++++++--------- .../conformance/proto3/test_all_types_pb.ts | 48 +++++++++---------- .../cel/expr/conformance/test/simple_pb.ts | 6 +-- .../gen/cel/expr/conformance/test/suite_pb.ts | 10 ++-- packages/cel-spec/src/gen/cel/expr/eval_pb.ts | 2 +- .../cel-spec/src/gen/cel/expr/explain_pb.ts | 2 +- .../cel-spec/src/gen/cel/expr/syntax_pb.ts | 24 +++++----- .../cel-spec/src/gen/cel/expr/value_pb.ts | 6 +-- 12 files changed, 96 insertions(+), 96 deletions(-) diff --git a/packages/cel-spec/src/gen/cel/expr/checked_pb.ts b/packages/cel-spec/src/gen/cel/expr/checked_pb.ts index cbd4331e..ed916b21 100644 --- a/packages/cel-spec/src/gen/cel/expr/checked_pb.ts +++ b/packages/cel-spec/src/gen/cel/expr/checked_pb.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// @generated by protoc-gen-es v2.10.2 with parameter "target=ts,import_extension=.js,ts_nocheck=false" +// @generated by protoc-gen-es v2.14.0 with parameter "target=ts,import_extension=.js,ts_nocheck=false" // @generated from file cel/expr/checked.proto (package cel.expr, syntax proto3) /* eslint-disable */ @@ -74,7 +74,7 @@ export type CheckedExpr = Message<"cel.expr.CheckedExpr"> & { * * @generated from field: cel.expr.SourceInfo source_info = 5; */ - sourceInfo?: SourceInfo; + sourceInfo?: SourceInfo | undefined; /** * The expr version indicates the major / minor version number of the `expr` @@ -95,7 +95,7 @@ export type CheckedExpr = Message<"cel.expr.CheckedExpr"> & { * * @generated from field: cel.expr.Expr expr = 4; */ - expr?: Expr; + expr?: Expr | undefined; }; /** @@ -258,7 +258,7 @@ export type Type_ListType = Message<"cel.expr.Type.ListType"> & { * * @generated from field: cel.expr.Type elem_type = 1; */ - elemType?: Type; + elemType?: Type | undefined; }; /** @@ -279,14 +279,14 @@ export type Type_MapType = Message<"cel.expr.Type.MapType"> & { * * @generated from field: cel.expr.Type key_type = 1; */ - keyType?: Type; + keyType?: Type | undefined; /** * The type of the value. * * @generated from field: cel.expr.Type value_type = 2; */ - valueType?: Type; + valueType?: Type | undefined; }; /** @@ -307,7 +307,7 @@ export type Type_FunctionType = Message<"cel.expr.Type.FunctionType"> & { * * @generated from field: cel.expr.Type result_type = 1; */ - resultType?: Type; + resultType?: Type | undefined; /** * Argument types of the function. @@ -537,7 +537,7 @@ export type Decl_IdentDecl = Message<"cel.expr.Decl.IdentDecl"> & { * * @generated from field: cel.expr.Type type = 1; */ - type?: Type; + type?: Type | undefined; /** * The constant value of the identifier. If not specified, the identifier @@ -545,7 +545,7 @@ export type Decl_IdentDecl = Message<"cel.expr.Decl.IdentDecl"> & { * * @generated from field: cel.expr.Constant value = 2; */ - value?: Constant; + value?: Constant | undefined; /** * Documentation string for the identifier. @@ -676,7 +676,7 @@ export type Decl_FunctionDecl_Overload = Message<"cel.expr.Decl.FunctionDecl.Ove * * @generated from field: cel.expr.Type result_type = 4; */ - resultType?: Type; + resultType?: Type | undefined; /** * Whether the function is to be used in a method call-style `x.f(...)` @@ -759,7 +759,7 @@ export type Reference = Message<"cel.expr.Reference"> & { * * @generated from field: cel.expr.Constant value = 4; */ - value?: Constant; + value?: Constant | undefined; }; /** diff --git a/packages/cel-spec/src/gen/cel/expr/conformance/conformance_service_pb.ts b/packages/cel-spec/src/gen/cel/expr/conformance/conformance_service_pb.ts index 3ea7fcae..18d04d54 100644 --- a/packages/cel-spec/src/gen/cel/expr/conformance/conformance_service_pb.ts +++ b/packages/cel-spec/src/gen/cel/expr/conformance/conformance_service_pb.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// @generated by protoc-gen-es v2.10.2 with parameter "target=ts,import_extension=.js,ts_nocheck=false" +// @generated by protoc-gen-es v2.14.0 with parameter "target=ts,import_extension=.js,ts_nocheck=false" // @generated from file cel/expr/conformance/conformance_service.proto (package cel.expr.conformance, syntax proto3) /* eslint-disable */ @@ -85,14 +85,14 @@ export type ParseResponse = Message<"cel.expr.conformance.ParseResponse"> & { * * @generated from field: cel.expr.ParsedExpr parsed_expr = 1; */ - parsedExpr?: ParsedExpr; + parsedExpr?: ParsedExpr | undefined; /** * Any number of issues with [StatusDetails][] as the details. * * @generated from field: cel.expr.ErrorSet issues = 2; */ - issues?: ErrorSet; + issues?: ErrorSet | undefined; }; /** @@ -113,7 +113,7 @@ export type CheckRequest = Message<"cel.expr.conformance.CheckRequest"> & { * * @generated from field: cel.expr.ParsedExpr parsed_expr = 1; */ - parsedExpr?: ParsedExpr; + parsedExpr?: ParsedExpr | undefined; /** * Declarations of types for external variables and functions. @@ -160,14 +160,14 @@ export type CheckResponse = Message<"cel.expr.conformance.CheckResponse"> & { * * @generated from field: cel.expr.CheckedExpr checked_expr = 1; */ - checkedExpr?: CheckedExpr; + checkedExpr?: CheckedExpr | undefined; /** * Any number of issues with [StatusDetails][] as the details. * * @generated from field: cel.expr.ErrorSet issues = 2; */ - issues?: ErrorSet; + issues?: ErrorSet | undefined; }; /** @@ -240,7 +240,7 @@ export type EvalResponse = Message<"cel.expr.conformance.EvalResponse"> & { * * @generated from field: cel.expr.ExprValue result = 1; */ - result?: ExprValue; + result?: ExprValue | undefined; /** * Any number of issues with [StatusDetails][] as the details. @@ -250,7 +250,7 @@ export type EvalResponse = Message<"cel.expr.conformance.EvalResponse"> & { * * @generated from field: cel.expr.ErrorSet issues = 2; */ - issues?: ErrorSet; + issues?: ErrorSet | undefined; }; /** @@ -324,7 +324,7 @@ export type IssueDetails = Message<"cel.expr.conformance.IssueDetails"> & { * * @generated from field: cel.expr.conformance.SourcePosition position = 2; */ - position?: SourcePosition; + position?: SourcePosition | undefined; /** * Expression ID from [Expr][], 0 if unknown. diff --git a/packages/cel-spec/src/gen/cel/expr/conformance/env_config_pb.ts b/packages/cel-spec/src/gen/cel/expr/conformance/env_config_pb.ts index 68f39af3..6fa969ef 100644 --- a/packages/cel-spec/src/gen/cel/expr/conformance/env_config_pb.ts +++ b/packages/cel-spec/src/gen/cel/expr/conformance/env_config_pb.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// @generated by protoc-gen-es v2.10.2 with parameter "target=ts,import_extension=.js,ts_nocheck=false" +// @generated by protoc-gen-es v2.14.0 with parameter "target=ts,import_extension=.js,ts_nocheck=false" // @generated from file cel/expr/conformance/env_config.proto (package cel.expr.conformance, syntax proto3) /* eslint-disable */ @@ -75,7 +75,7 @@ export type Environment = Message<"cel.expr.conformance.Environment"> & { * * @generated from field: cel.expr.conformance.LibrarySubset stdlib = 5; */ - stdlib?: LibrarySubset; + stdlib?: LibrarySubset | undefined; /** * List of extensions to enable in the CEL environment. @@ -92,7 +92,7 @@ export type Environment = Message<"cel.expr.conformance.Environment"> & { * * @generated from field: cel.expr.conformance.Environment.ContextVariable context_variable = 7; */ - contextVariable?: Environment_ContextVariable; + contextVariable?: Environment_ContextVariable | undefined; /** * List of declarations to be configured in the CEL environment. @@ -141,7 +141,7 @@ export type Environment = Message<"cel.expr.conformance.Environment"> & { * * @generated from field: google.protobuf.FileDescriptorSet message_type_extension = 12; */ - messageTypeExtension?: FileDescriptorSet; + messageTypeExtension?: FileDescriptorSet | undefined; /** * When macro call tracking is enabled, the resulting SourceInfo in the diff --git a/packages/cel-spec/src/gen/cel/expr/conformance/proto2/test_all_types_extensions_pb.ts b/packages/cel-spec/src/gen/cel/expr/conformance/proto2/test_all_types_extensions_pb.ts index c1f4f953..ddacb900 100644 --- a/packages/cel-spec/src/gen/cel/expr/conformance/proto2/test_all_types_extensions_pb.ts +++ b/packages/cel-spec/src/gen/cel/expr/conformance/proto2/test_all_types_extensions_pb.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// @generated by protoc-gen-es v2.10.2 with parameter "target=ts,import_extension=.js,ts_nocheck=false" +// @generated by protoc-gen-es v2.14.0 with parameter "target=ts,import_extension=.js,ts_nocheck=false" // @generated from file cel/expr/conformance/proto2/test_all_types_extensions.proto (package cel.expr.conformance.proto2, syntax proto2) /* eslint-disable */ diff --git a/packages/cel-spec/src/gen/cel/expr/conformance/proto2/test_all_types_pb.ts b/packages/cel-spec/src/gen/cel/expr/conformance/proto2/test_all_types_pb.ts index 78a9d2a2..700bcca3 100644 --- a/packages/cel-spec/src/gen/cel/expr/conformance/proto2/test_all_types_pb.ts +++ b/packages/cel-spec/src/gen/cel/expr/conformance/proto2/test_all_types_pb.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// @generated by protoc-gen-es v2.10.2 with parameter "target=ts,import_extension=.js,ts_nocheck=false" +// @generated by protoc-gen-es v2.14.0 with parameter "target=ts,import_extension=.js,ts_nocheck=false" // @generated from file cel/expr/conformance/proto2/test_all_types.proto (package cel.expr.conformance.proto2, syntax proto2) /* eslint-disable */ @@ -124,77 +124,77 @@ export type TestAllTypes = Message<"cel.expr.conformance.proto2.TestAllTypes"> & * * @generated from field: optional google.protobuf.Any single_any = 100; */ - singleAny?: Any; + singleAny?: Any | undefined; /** * @generated from field: optional google.protobuf.Duration single_duration = 101; */ - singleDuration?: Duration; + singleDuration?: Duration | undefined; /** * @generated from field: optional google.protobuf.Timestamp single_timestamp = 102; */ - singleTimestamp?: Timestamp; + singleTimestamp?: Timestamp | undefined; /** * @generated from field: optional google.protobuf.Struct single_struct = 103; */ - singleStruct?: JsonObject; + singleStruct?: JsonObject | undefined; /** * @generated from field: optional google.protobuf.Value single_value = 104; */ - singleValue?: Value; + singleValue?: Value | undefined; /** * @generated from field: optional google.protobuf.Int64Value single_int64_wrapper = 105; */ - singleInt64Wrapper?: bigint; + singleInt64Wrapper?: bigint | undefined; /** * @generated from field: optional google.protobuf.Int32Value single_int32_wrapper = 106; */ - singleInt32Wrapper?: number; + singleInt32Wrapper?: number | undefined; /** * @generated from field: optional google.protobuf.DoubleValue single_double_wrapper = 107; */ - singleDoubleWrapper?: number; + singleDoubleWrapper?: number | undefined; /** * @generated from field: optional google.protobuf.FloatValue single_float_wrapper = 108; */ - singleFloatWrapper?: number; + singleFloatWrapper?: number | undefined; /** * @generated from field: optional google.protobuf.UInt64Value single_uint64_wrapper = 109; */ - singleUint64Wrapper?: bigint; + singleUint64Wrapper?: bigint | undefined; /** * @generated from field: optional google.protobuf.UInt32Value single_uint32_wrapper = 110; */ - singleUint32Wrapper?: number; + singleUint32Wrapper?: number | undefined; /** * @generated from field: optional google.protobuf.StringValue single_string_wrapper = 111; */ - singleStringWrapper?: string; + singleStringWrapper?: string | undefined; /** * @generated from field: optional google.protobuf.BoolValue single_bool_wrapper = 112; */ - singleBoolWrapper?: boolean; + singleBoolWrapper?: boolean | undefined; /** * @generated from field: optional google.protobuf.BytesValue single_bytes_wrapper = 113; */ - singleBytesWrapper?: Uint8Array; + singleBytesWrapper?: Uint8Array | undefined; /** * @generated from field: optional google.protobuf.ListValue list_value = 114; */ - listValue?: ListValue; + listValue?: ListValue | undefined; /** * @generated from field: optional google.protobuf.NullValue null_value = 115; @@ -209,12 +209,12 @@ export type TestAllTypes = Message<"cel.expr.conformance.proto2.TestAllTypes"> & /** * @generated from field: optional google.protobuf.FieldMask field_mask = 117; */ - fieldMask?: FieldMask; + fieldMask?: FieldMask | undefined; /** * @generated from field: optional google.protobuf.Empty empty = 118; */ - empty?: Empty; + empty?: Empty | undefined; /** * Nested messages @@ -238,7 +238,7 @@ export type TestAllTypes = Message<"cel.expr.conformance.proto2.TestAllTypes"> & /** * @generated from field: optional cel.expr.conformance.proto2.TestAllTypes.NestedMessage standalone_message = 23; */ - standaloneMessage?: TestAllTypes_NestedMessage; + standaloneMessage?: TestAllTypes_NestedMessage | undefined; /** * @generated from field: optional cel.expr.conformance.proto2.TestAllTypes.NestedEnum standalone_enum = 24; @@ -1274,7 +1274,7 @@ export type TestAllTypes = Message<"cel.expr.conformance.proto2.TestAllTypes"> & /** * @generated from field: optional cel.expr.conformance.proto2.TestAllTypes.NestedGroup nestedgroup = 403; */ - nestedgroup?: TestAllTypes_NestedGroup; + nestedgroup?: TestAllTypes_NestedGroup | undefined; /** * Field names formerly defined as reserved CEL identifiers. @@ -1449,12 +1449,12 @@ export type NestedTestAllTypes = Message<"cel.expr.conformance.proto2.NestedTest /** * @generated from field: optional cel.expr.conformance.proto2.NestedTestAllTypes child = 1; */ - child?: NestedTestAllTypes; + child?: NestedTestAllTypes | undefined; /** * @generated from field: optional cel.expr.conformance.proto2.TestAllTypes payload = 2; */ - payload?: TestAllTypes; + payload?: TestAllTypes | undefined; }; /** diff --git a/packages/cel-spec/src/gen/cel/expr/conformance/proto3/test_all_types_pb.ts b/packages/cel-spec/src/gen/cel/expr/conformance/proto3/test_all_types_pb.ts index 4b0d06f5..dd1ef238 100644 --- a/packages/cel-spec/src/gen/cel/expr/conformance/proto3/test_all_types_pb.ts +++ b/packages/cel-spec/src/gen/cel/expr/conformance/proto3/test_all_types_pb.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// @generated by protoc-gen-es v2.10.2 with parameter "target=ts,import_extension=.js,ts_nocheck=false" +// @generated by protoc-gen-es v2.14.0 with parameter "target=ts,import_extension=.js,ts_nocheck=false" // @generated from file cel/expr/conformance/proto3/test_all_types.proto (package cel.expr.conformance.proto3, syntax proto3) /* eslint-disable */ @@ -115,12 +115,12 @@ export type TestAllTypes = Message<"cel.expr.conformance.proto3.TestAllTypes"> & /** * @generated from field: optional bool optional_bool = 16; */ - optionalBool?: boolean; + optionalBool?: boolean | undefined; /** * @generated from field: optional string optional_string = 17; */ - optionalString?: string; + optionalString?: string | undefined; /** * Collides with 'in' operator. @@ -134,77 +134,77 @@ export type TestAllTypes = Message<"cel.expr.conformance.proto3.TestAllTypes"> & * * @generated from field: google.protobuf.Any single_any = 100; */ - singleAny?: Any; + singleAny?: Any | undefined; /** * @generated from field: google.protobuf.Duration single_duration = 101; */ - singleDuration?: Duration; + singleDuration?: Duration | undefined; /** * @generated from field: google.protobuf.Timestamp single_timestamp = 102; */ - singleTimestamp?: Timestamp; + singleTimestamp?: Timestamp | undefined; /** * @generated from field: google.protobuf.Struct single_struct = 103; */ - singleStruct?: JsonObject; + singleStruct?: JsonObject | undefined; /** * @generated from field: google.protobuf.Value single_value = 104; */ - singleValue?: Value; + singleValue?: Value | undefined; /** * @generated from field: google.protobuf.Int64Value single_int64_wrapper = 105; */ - singleInt64Wrapper?: bigint; + singleInt64Wrapper?: bigint | undefined; /** * @generated from field: google.protobuf.Int32Value single_int32_wrapper = 106; */ - singleInt32Wrapper?: number; + singleInt32Wrapper?: number | undefined; /** * @generated from field: google.protobuf.DoubleValue single_double_wrapper = 107; */ - singleDoubleWrapper?: number; + singleDoubleWrapper?: number | undefined; /** * @generated from field: google.protobuf.FloatValue single_float_wrapper = 108; */ - singleFloatWrapper?: number; + singleFloatWrapper?: number | undefined; /** * @generated from field: google.protobuf.UInt64Value single_uint64_wrapper = 109; */ - singleUint64Wrapper?: bigint; + singleUint64Wrapper?: bigint | undefined; /** * @generated from field: google.protobuf.UInt32Value single_uint32_wrapper = 110; */ - singleUint32Wrapper?: number; + singleUint32Wrapper?: number | undefined; /** * @generated from field: google.protobuf.StringValue single_string_wrapper = 111; */ - singleStringWrapper?: string; + singleStringWrapper?: string | undefined; /** * @generated from field: google.protobuf.BoolValue single_bool_wrapper = 112; */ - singleBoolWrapper?: boolean; + singleBoolWrapper?: boolean | undefined; /** * @generated from field: google.protobuf.BytesValue single_bytes_wrapper = 113; */ - singleBytesWrapper?: Uint8Array; + singleBytesWrapper?: Uint8Array | undefined; /** * @generated from field: google.protobuf.ListValue list_value = 114; */ - listValue?: ListValue; + listValue?: ListValue | undefined; /** * @generated from field: google.protobuf.NullValue null_value = 115; @@ -214,17 +214,17 @@ export type TestAllTypes = Message<"cel.expr.conformance.proto3.TestAllTypes"> & /** * @generated from field: optional google.protobuf.NullValue optional_null_value = 116; */ - optionalNullValue?: NullValue; + optionalNullValue?: NullValue | undefined; /** * @generated from field: google.protobuf.FieldMask field_mask = 117; */ - fieldMask?: FieldMask; + fieldMask?: FieldMask | undefined; /** * @generated from field: google.protobuf.Empty empty = 118; */ - empty?: Empty; + empty?: Empty | undefined; /** * Nested messages @@ -248,7 +248,7 @@ export type TestAllTypes = Message<"cel.expr.conformance.proto3.TestAllTypes"> & /** * @generated from field: cel.expr.conformance.proto3.TestAllTypes.NestedMessage standalone_message = 23; */ - standaloneMessage?: TestAllTypes_NestedMessage; + standaloneMessage?: TestAllTypes_NestedMessage | undefined; /** * @generated from field: cel.expr.conformance.proto3.TestAllTypes.NestedEnum standalone_enum = 24; @@ -1432,12 +1432,12 @@ export type NestedTestAllTypes = Message<"cel.expr.conformance.proto3.NestedTest /** * @generated from field: cel.expr.conformance.proto3.NestedTestAllTypes child = 1; */ - child?: NestedTestAllTypes; + child?: NestedTestAllTypes | undefined; /** * @generated from field: cel.expr.conformance.proto3.TestAllTypes payload = 2; */ - payload?: TestAllTypes; + payload?: TestAllTypes | undefined; }; /** diff --git a/packages/cel-spec/src/gen/cel/expr/conformance/test/simple_pb.ts b/packages/cel-spec/src/gen/cel/expr/conformance/test/simple_pb.ts index 42434217..2fbde03e 100644 --- a/packages/cel-spec/src/gen/cel/expr/conformance/test/simple_pb.ts +++ b/packages/cel-spec/src/gen/cel/expr/conformance/test/simple_pb.ts @@ -14,7 +14,7 @@ // Simple end-to-end conformance tests. -// @generated by protoc-gen-es v2.10.2 with parameter "target=ts,import_extension=.js,ts_nocheck=false" +// @generated by protoc-gen-es v2.14.0 with parameter "target=ts,import_extension=.js,ts_nocheck=false" // @generated from file cel/expr/conformance/test/simple.proto (package cel.expr.conformance.test, syntax proto3) /* eslint-disable */ @@ -270,14 +270,14 @@ export type TypedResult = Message<"cel.expr.conformance.test.TypedResult"> & { * * @generated from field: cel.expr.Value result = 1; */ - result?: Value; + result?: Value | undefined; /** * The deduced type of the expression as reported by the checker. * * @generated from field: cel.expr.Type deduced_type = 2; */ - deducedType?: Type; + deducedType?: Type | undefined; }; /** diff --git a/packages/cel-spec/src/gen/cel/expr/conformance/test/suite_pb.ts b/packages/cel-spec/src/gen/cel/expr/conformance/test/suite_pb.ts index a9b1b346..bf1ea2b8 100644 --- a/packages/cel-spec/src/gen/cel/expr/conformance/test/suite_pb.ts +++ b/packages/cel-spec/src/gen/cel/expr/conformance/test/suite_pb.ts @@ -14,7 +14,7 @@ // Unit tests and end-to-end conformance tests. -// @generated by protoc-gen-es v2.10.2 with parameter "target=ts,import_extension=.js,ts_nocheck=false" +// @generated by protoc-gen-es v2.14.0 with parameter "target=ts,import_extension=.js,ts_nocheck=false" // @generated from file cel/expr/conformance/test/suite.proto (package cel.expr.conformance.test, syntax proto3) /* eslint-disable */ @@ -151,7 +151,7 @@ export type TestCase = Message<"cel.expr.conformance.test.TestCase"> & { * * @generated from field: cel.expr.conformance.Environment env = 4; */ - env?: Environment; + env?: Environment | undefined; /** * A map representing a variable binding where the key is the name of the @@ -168,14 +168,14 @@ export type TestCase = Message<"cel.expr.conformance.test.TestCase"> & { * * @generated from field: cel.expr.conformance.test.InputContext input_context = 6; */ - inputContext?: InputContext; + inputContext?: InputContext | undefined; /** * Expected result of the test case. * * @generated from field: cel.expr.conformance.test.TestOutput output = 7; */ - output?: TestOutput; + output?: TestOutput | undefined; /** * If specified validates that the deduced type at check time matches @@ -184,7 +184,7 @@ export type TestCase = Message<"cel.expr.conformance.test.TestCase"> & { * * @generated from field: cel.expr.Type deduced_type = 8; */ - deducedType?: Type; + deducedType?: Type | undefined; /** * Bypass the type-checking and only attempt to evaluate the parsed diff --git a/packages/cel-spec/src/gen/cel/expr/eval_pb.ts b/packages/cel-spec/src/gen/cel/expr/eval_pb.ts index 5b970e69..eacd94c8 100644 --- a/packages/cel-spec/src/gen/cel/expr/eval_pb.ts +++ b/packages/cel-spec/src/gen/cel/expr/eval_pb.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// @generated by protoc-gen-es v2.10.2 with parameter "target=ts,import_extension=.js,ts_nocheck=false" +// @generated by protoc-gen-es v2.14.0 with parameter "target=ts,import_extension=.js,ts_nocheck=false" // @generated from file cel/expr/eval.proto (package cel.expr, syntax proto3) /* eslint-disable */ diff --git a/packages/cel-spec/src/gen/cel/expr/explain_pb.ts b/packages/cel-spec/src/gen/cel/expr/explain_pb.ts index 96b1650a..140486ab 100644 --- a/packages/cel-spec/src/gen/cel/expr/explain_pb.ts +++ b/packages/cel-spec/src/gen/cel/expr/explain_pb.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// @generated by protoc-gen-es v2.10.2 with parameter "target=ts,import_extension=.js,ts_nocheck=false" +// @generated by protoc-gen-es v2.14.0 with parameter "target=ts,import_extension=.js,ts_nocheck=false" // @generated from file cel/expr/explain.proto (package cel.expr, syntax proto3) /* eslint-disable */ diff --git a/packages/cel-spec/src/gen/cel/expr/syntax_pb.ts b/packages/cel-spec/src/gen/cel/expr/syntax_pb.ts index 1580d72b..3df15663 100644 --- a/packages/cel-spec/src/gen/cel/expr/syntax_pb.ts +++ b/packages/cel-spec/src/gen/cel/expr/syntax_pb.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// @generated by protoc-gen-es v2.10.2 with parameter "target=ts,import_extension=.js,ts_nocheck=false" +// @generated by protoc-gen-es v2.14.0 with parameter "target=ts,import_extension=.js,ts_nocheck=false" // @generated from file cel/expr/syntax.proto (package cel.expr, syntax proto3) /* eslint-disable */ @@ -39,14 +39,14 @@ export type ParsedExpr = Message<"cel.expr.ParsedExpr"> & { * * @generated from field: cel.expr.Expr expr = 2; */ - expr?: Expr; + expr?: Expr | undefined; /** * The source info derived from input that generated the parsed `expr`. * * @generated from field: cel.expr.SourceInfo source_info = 3; */ - sourceInfo?: SourceInfo; + sourceInfo?: SourceInfo | undefined; }; /** @@ -197,7 +197,7 @@ export type Expr_Select = Message<"cel.expr.Expr.Select"> & { * * @generated from field: cel.expr.Expr operand = 1; */ - operand?: Expr; + operand?: Expr | undefined; /** * Required. The name of the field to select. @@ -240,7 +240,7 @@ export type Expr_Call = Message<"cel.expr.Expr.Call"> & { * * @generated from field: cel.expr.Expr target = 1; */ - target?: Expr; + target?: Expr | undefined; /** * Required. The name of the function or method being called. @@ -380,7 +380,7 @@ export type Expr_CreateStruct_Entry = Message<"cel.expr.Expr.CreateStruct.Entry" * * @generated from field: cel.expr.Expr value = 4; */ - value?: Expr; + value?: Expr | undefined; /** * Whether the key-value pair is optional. @@ -481,7 +481,7 @@ export type Expr_Comprehension = Message<"cel.expr.Expr.Comprehension"> & { * * @generated from field: cel.expr.Expr iter_range = 2; */ - iterRange?: Expr; + iterRange?: Expr | undefined; /** * The name of the variable used for accumulation of the result. @@ -495,7 +495,7 @@ export type Expr_Comprehension = Message<"cel.expr.Expr.Comprehension"> & { * * @generated from field: cel.expr.Expr accu_init = 4; */ - accuInit?: Expr; + accuInit?: Expr | undefined; /** * An expression which can contain iter_var, iter_var2, and accu_var. @@ -505,7 +505,7 @@ export type Expr_Comprehension = Message<"cel.expr.Expr.Comprehension"> & { * * @generated from field: cel.expr.Expr loop_condition = 5; */ - loopCondition?: Expr; + loopCondition?: Expr | undefined; /** * An expression which can contain iter_var, iter_var2, and accu_var. @@ -514,7 +514,7 @@ export type Expr_Comprehension = Message<"cel.expr.Expr.Comprehension"> & { * * @generated from field: cel.expr.Expr loop_step = 6; */ - loopStep?: Expr; + loopStep?: Expr | undefined; /** * An expression which can contain accu_var. @@ -523,7 +523,7 @@ export type Expr_Comprehension = Message<"cel.expr.Expr.Comprehension"> & { * * @generated from field: cel.expr.Expr result = 7; */ - result?: Expr; + result?: Expr | undefined; }; /** @@ -753,7 +753,7 @@ export type SourceInfo_Extension = Message<"cel.expr.SourceInfo.Extension"> & { * * @generated from field: cel.expr.SourceInfo.Extension.Version version = 3; */ - version?: SourceInfo_Extension_Version; + version?: SourceInfo_Extension_Version | undefined; }; /** diff --git a/packages/cel-spec/src/gen/cel/expr/value_pb.ts b/packages/cel-spec/src/gen/cel/expr/value_pb.ts index 4e71f343..bdf086ee 100644 --- a/packages/cel-spec/src/gen/cel/expr/value_pb.ts +++ b/packages/cel-spec/src/gen/cel/expr/value_pb.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// @generated by protoc-gen-es v2.10.2 with parameter "target=ts,import_extension=.js,ts_nocheck=false" +// @generated by protoc-gen-es v2.14.0 with parameter "target=ts,import_extension=.js,ts_nocheck=false" // @generated from file cel/expr/value.proto (package cel.expr, syntax proto3) /* eslint-disable */ @@ -239,14 +239,14 @@ export type MapValue_Entry = Message<"cel.expr.MapValue.Entry"> & { * * @generated from field: cel.expr.Value key = 1; */ - key?: Value; + key?: Value | undefined; /** * The value. * * @generated from field: cel.expr.Value value = 2; */ - value?: Value; + value?: Value | undefined; }; /** From 18c4ee94c77683d58a2c6e83ce57acf687ed7e95 Mon Sep 17 00:00:00 2001 From: Timo Stamm Date: Wed, 26 Aug 2026 13:34:02 +0200 Subject: [PATCH 3/4] Retain -0 in testdata This fixes a bug in the harness, where the sign from -0 was dropped. The protobuf-es update surfaced the issue. --- packages/cel-spec/scripts/fetch-testdata.js | 5 ++++- packages/cel-spec/src/testdata/conformance.ts | 6 +++--- packages/cel-spec/src/testdata/json/conversions.json | 2 +- packages/cel-spec/src/testdata/json/dynamic.json | 2 +- packages/cel-spec/src/testdata/json/fp_math.json | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/cel-spec/scripts/fetch-testdata.js b/packages/cel-spec/scripts/fetch-testdata.js index d698561c..f4fd91b4 100644 --- a/packages/cel-spec/scripts/fetch-testdata.js +++ b/packages/cel-spec/scripts/fetch-testdata.js @@ -59,7 +59,10 @@ function convertTestDataToJson(testData, module, typeName) { for (const [name, content] of testData) { try { const jsonString = bufConvert(module, typeName, content); - const json = JSON.parse(jsonString); + const json = JSON.parse(jsonString, (_key, value, context) => + // Keep -0 via rawJSON + typeof value === "number" ? JSON.rawJSON(context.source) : value, + ); testFiles.push(json); } catch (e) { throw new Error(`Failed to convert ${name}`, { cause: e }); diff --git a/packages/cel-spec/src/testdata/conformance.ts b/packages/cel-spec/src/testdata/conformance.ts index 9c9703d1..f2856a2c 100644 --- a/packages/cel-spec/src/testdata/conformance.ts +++ b/packages/cel-spec/src/testdata/conformance.ts @@ -6425,7 +6425,7 @@ export const tests: SerializedIncrementalTestSuite = { original: { name: "string_neg_zero", expr: "double('-0.0')", - value: { doubleValue: 0 }, + value: { doubleValue: -0 }, }, ast: 'double(\n "-0.0"^#*expr.Constant_StringValue#\n)^#*expr.Expr_CallExpr#', checkedAst: 'double(\n "-0.0"~string\n)~double^string_to_double', @@ -8573,7 +8573,7 @@ export const tests: SerializedIncrementalTestSuite = { objectValue: { "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - singleFloatWrapper: 0, + singleFloatWrapper: -0, }, }, }, @@ -13772,7 +13772,7 @@ export const tests: SerializedIncrementalTestSuite = { original: { name: "negative_zero", expr: "-(0.0)", - value: { doubleValue: 0 }, + value: { doubleValue: -0 }, }, ast: "-_(\n 0^#*expr.Constant_DoubleValue#\n)^#*expr.Expr_CallExpr#", checkedAst: "-_(\n 0~double\n)~double^negate_double", diff --git a/packages/cel-spec/src/testdata/json/conversions.json b/packages/cel-spec/src/testdata/json/conversions.json index 29906cd0..2c6b7658 100644 --- a/packages/cel-spec/src/testdata/json/conversions.json +++ b/packages/cel-spec/src/testdata/json/conversions.json @@ -133,7 +133,7 @@ "name": "string_neg_zero", "expr": "double('-0.0')", "value": { - "doubleValue": 0 + "doubleValue": -0 } }, { diff --git a/packages/cel-spec/src/testdata/json/dynamic.json b/packages/cel-spec/src/testdata/json/dynamic.json index 47ca114b..898b130e 100644 --- a/packages/cel-spec/src/testdata/json/dynamic.json +++ b/packages/cel-spec/src/testdata/json/dynamic.json @@ -812,7 +812,7 @@ "value": { "objectValue": { "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleFloatWrapper": 0 + "singleFloatWrapper": -0 } } }, diff --git a/packages/cel-spec/src/testdata/json/fp_math.json b/packages/cel-spec/src/testdata/json/fp_math.json index 0d10f853..d59ac05e 100644 --- a/packages/cel-spec/src/testdata/json/fp_math.json +++ b/packages/cel-spec/src/testdata/json/fp_math.json @@ -120,7 +120,7 @@ "name": "negative_zero", "expr": "-(0.0)", "value": { - "doubleValue": 0 + "doubleValue": -0 } }, { From 4f4a8eaa5f1860aabebfd30c554edff5413450f7 Mon Sep 17 00:00:00 2001 From: Timo Stamm Date: Wed, 26 Aug 2026 15:11:18 +0200 Subject: [PATCH 4/4] Switch to txtpb for the upstream test data This drops the JSON conversion step entirely. --- packages/cel-spec/package.json | 3 +- packages/cel-spec/scripts/fetch-testdata.js | 83 +- .../cel-spec/scripts/gen_incremental_tests.go | 7 +- packages/cel-spec/src/testdata/conformance.ts | 2 +- .../cel-spec/src/testdata/json/basic.json | 436 --- .../src/testdata/json/bindings_ext.json | 46 - .../cel-spec/src/testdata/json/block_ext.json | 1096 ------ .../src/testdata/json/comparisons.json | 3271 ----------------- .../src/testdata/json/conversions.json | 881 ----- .../cel-spec/src/testdata/json/dynamic.json | 2854 -------------- .../src/testdata/json/encoders_ext.json | 49 - .../cel-spec/src/testdata/json/enums.json | 1006 ----- .../cel-spec/src/testdata/json/fields.json | 961 ----- .../cel-spec/src/testdata/json/fp_math.json | 230 -- .../src/testdata/json/integer_math.json | 557 --- .../cel-spec/src/testdata/json/lists.json | 358 -- .../cel-spec/src/testdata/json/logic.json | 285 -- .../cel-spec/src/testdata/json/macros.json | 430 --- .../cel-spec/src/testdata/json/macros2.json | 491 --- .../cel-spec/src/testdata/json/math_ext.json | 1323 ------- .../cel-spec/src/testdata/json/namespace.json | 119 - .../cel-spec/src/testdata/json/optionals.json | 606 --- .../cel-spec/src/testdata/json/parse.json | 1783 --------- .../cel-spec/src/testdata/json/plumbing.json | 110 - .../cel-spec/src/testdata/json/proto2.json | 1403 ------- .../src/testdata/json/proto2_ext.json | 476 --- .../cel-spec/src/testdata/json/proto3.json | 811 ---- .../cel-spec/src/testdata/json/string.json | 405 -- .../src/testdata/json/string_ext.json | 1689 --------- .../src/testdata/json/timestamps.json | 681 ---- .../src/testdata/json/type_deductions.json | 1171 ------ .../cel-spec/src/testdata/json/unknowns.json | 4 - .../cel-spec/src/testdata/json/wrappers.json | 374 -- .../src/testdata/textproto/basic.textproto | 293 ++ .../testdata/textproto/bindings_ext.textproto | 43 + .../testdata/textproto/block_ext.textproto | 1070 ++++++ .../testdata/textproto/comparisons.textproto | 2370 ++++++++++++ .../testdata/textproto/conversions.textproto | 622 ++++ .../src/testdata/textproto/dynamic.textproto | 2291 ++++++++++++ .../testdata/textproto/encoders_ext.textproto | 44 + .../src/testdata/textproto/enums.textproto | 933 +++++ .../src/testdata/textproto/fields.textproto | 674 ++++ .../src/testdata/textproto/fp_math.textproto | 167 + .../testdata/textproto/integer_math.textproto | 386 ++ .../src/testdata/textproto/lists.textproto | 245 ++ .../src/testdata/textproto/logic.textproto | 198 + .../src/testdata/textproto/macros.textproto | 289 ++ .../src/testdata/textproto/macros2.textproto | 354 ++ .../src/testdata/textproto/math_ext.textproto | 1266 +++++++ .../testdata/textproto/namespace.textproto | 71 + .../testdata/textproto/optionals.textproto | 451 +++ .../src/testdata/textproto/parse.textproto | 1410 +++++++ .../src/testdata/textproto/plumbing.textproto | 74 + .../src/testdata/textproto/proto2.textproto | 1229 +++++++ .../testdata/textproto/proto2_ext.textproto | 372 ++ .../src/testdata/textproto/proto3.textproto | 758 ++++ .../src/testdata/textproto/string.textproto | 288 ++ .../testdata/textproto/string_ext.textproto | 1491 ++++++++ .../testdata/textproto/timestamps.textproto | 478 +++ .../textproto/type_deduction.textproto | 953 +++++ .../src/testdata/textproto/unknowns.textproto | 5 + .../src/testdata/textproto/wrappers.textproto | 374 ++ packages/cel-spec/turbo.json | 6 +- 63 files changed, 19218 insertions(+), 23988 deletions(-) delete mode 100644 packages/cel-spec/src/testdata/json/basic.json delete mode 100644 packages/cel-spec/src/testdata/json/bindings_ext.json delete mode 100644 packages/cel-spec/src/testdata/json/block_ext.json delete mode 100644 packages/cel-spec/src/testdata/json/comparisons.json delete mode 100644 packages/cel-spec/src/testdata/json/conversions.json delete mode 100644 packages/cel-spec/src/testdata/json/dynamic.json delete mode 100644 packages/cel-spec/src/testdata/json/encoders_ext.json delete mode 100644 packages/cel-spec/src/testdata/json/enums.json delete mode 100644 packages/cel-spec/src/testdata/json/fields.json delete mode 100644 packages/cel-spec/src/testdata/json/fp_math.json delete mode 100644 packages/cel-spec/src/testdata/json/integer_math.json delete mode 100644 packages/cel-spec/src/testdata/json/lists.json delete mode 100644 packages/cel-spec/src/testdata/json/logic.json delete mode 100644 packages/cel-spec/src/testdata/json/macros.json delete mode 100644 packages/cel-spec/src/testdata/json/macros2.json delete mode 100644 packages/cel-spec/src/testdata/json/math_ext.json delete mode 100644 packages/cel-spec/src/testdata/json/namespace.json delete mode 100644 packages/cel-spec/src/testdata/json/optionals.json delete mode 100644 packages/cel-spec/src/testdata/json/parse.json delete mode 100644 packages/cel-spec/src/testdata/json/plumbing.json delete mode 100644 packages/cel-spec/src/testdata/json/proto2.json delete mode 100644 packages/cel-spec/src/testdata/json/proto2_ext.json delete mode 100644 packages/cel-spec/src/testdata/json/proto3.json delete mode 100644 packages/cel-spec/src/testdata/json/string.json delete mode 100644 packages/cel-spec/src/testdata/json/string_ext.json delete mode 100644 packages/cel-spec/src/testdata/json/timestamps.json delete mode 100644 packages/cel-spec/src/testdata/json/type_deductions.json delete mode 100644 packages/cel-spec/src/testdata/json/unknowns.json delete mode 100644 packages/cel-spec/src/testdata/json/wrappers.json create mode 100644 packages/cel-spec/src/testdata/textproto/basic.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/bindings_ext.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/block_ext.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/comparisons.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/conversions.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/dynamic.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/encoders_ext.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/enums.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/fields.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/fp_math.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/integer_math.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/lists.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/logic.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/macros.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/macros2.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/math_ext.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/namespace.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/optionals.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/parse.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/plumbing.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/proto2.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/proto2_ext.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/proto3.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/string.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/string_ext.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/timestamps.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/type_deduction.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/unknowns.textproto create mode 100644 packages/cel-spec/src/testdata/textproto/wrappers.textproto diff --git a/packages/cel-spec/package.json b/packages/cel-spec/package.json index 6a2f5aed..4ad3eeaa 100644 --- a/packages/cel-spec/package.json +++ b/packages/cel-spec/package.json @@ -19,12 +19,11 @@ "fetch-proto": "node scripts/fetch-proto.js", "postfetch-proto": "license-header proto", "fetch-testdata": "node scripts/fetch-testdata.js", - "postfetch-testdata": "biome format --write src/testdata/json/*.json", "fetch-parsing": "go run -C scripts gen_incremental_tests.go -output ../src/testdata/parsing.ts parser/parser_test.go", "postfetch-parsing": "biome format --write src/testdata/parsing.ts && license-header src/testdata/parsing.ts", "fetch-comprehension": "go run -C scripts gen_incremental_tests.go -output ../src/testdata/comprehension.ts ext/comprehensions_test.go", "postfetch-comprehension": "biome format --write src/testdata/comprehension.ts && license-header src/testdata/comprehension.ts", - "fetch-conformance": "go run -C scripts gen_incremental_tests.go -output ../src/testdata/conformance.ts ../src/testdata/json", + "fetch-conformance": "go run -C scripts gen_incremental_tests.go -output ../src/testdata/conformance.ts ../src/testdata/textproto", "postfetch-conformance": "biome format --write src/testdata/conformance.ts && license-header src/testdata/conformance.ts", "fetch-checking": "go run -C scripts gen_incremental_tests.go -output ../src/testdata/checking.ts checker/checker_test.go", "postfetch-checking": "biome format --write src/testdata/checking.ts && license-header src/testdata/checking.ts", diff --git a/packages/cel-spec/scripts/fetch-testdata.js b/packages/cel-spec/scripts/fetch-testdata.js index f4fd91b4..86d565cb 100644 --- a/packages/cel-spec/scripts/fetch-testdata.js +++ b/packages/cel-spec/scripts/fetch-testdata.js @@ -12,14 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { extractFiles, fetchRepository, readPackageJson } from "./common.js"; -import { spawnSync } from "node:child_process"; -import { promises as fs } from "node:fs"; +import { + extractFiles, + fetchRepository, + readPackageJson, + writeFiles, +} from "./common.js"; /* * Fetch conformance test data from the upstream github.com/google/cel-spec - * Because we convert the test data from textproto to JSON, this script depends - * on the directory "proto" to contain the corresponding Protobuf files. + * The test data is stored as it is published upstream, in the Protobuf Text + * Format. See scripts/gen_incremental_tests.go for the conversion to TypeScript. */ const { upstreamCelSpecRef } = readPackageJson("package.json"); @@ -27,75 +30,9 @@ const { upstreamCelSpecRef } = readPackageJson("package.json"); // Fetch github.com/google/cel-spec const archive = await fetchRepository(upstreamCelSpecRef); // Extract testdata/simple/*.textproto -const testdataTextProto = extractFiles( +const testdata = extractFiles( archive, /^cel-spec-[^/]+\/tests\/simple\/testdata\/([^/]+\.textproto)$/, ); -// Convert textproto to JSON with `buf convert`, using the local module "proto". -const testdataJsonFiles = convertTestDataToJson( - testdataTextProto, - "proto", - "cel.expr.conformance.test.SimpleTestFile", -); - -// Write to JSON -await Promise.all( - testdataJsonFiles.map((file) => - fs.writeFile( - `src/testdata/json/${file.name}.json`, - JSON.stringify(file, null, 2), - ), - ), -); -/** - * @param {[string, Uint8Array|string][]} testData - * @param {string} module - * @param {string} typeName - * @return {any[]} - */ -function convertTestDataToJson(testData, module, typeName) { - const testFiles = []; - for (const [name, content] of testData) { - try { - const jsonString = bufConvert(module, typeName, content); - const json = JSON.parse(jsonString, (_key, value, context) => - // Keep -0 via rawJSON - typeof value === "number" ? JSON.rawJSON(context.source) : value, - ); - testFiles.push(json); - } catch (e) { - throw new Error(`Failed to convert ${name}`, { cause: e }); - } - } - return testFiles; -} - -/** - * @param {string} input - * @param {string} typeName - * @param {string | Uint8Array} from - * @return {string} - */ -function bufConvert(input, typeName, from) { - const command = "buf"; - const args = [ - "convert", - input, - `--type=${typeName}`, - "--from=-#format=txtpb", - "--to=-#format=json", - ]; - const p = spawnSync(command, args, { - encoding: "buffer", - input: from, - windowsHide: true, - }); - if (p.error !== undefined) { - throw p.error; - } - if (p.status !== 0) { - throw new Error(p.stderr.toString()); - } - return p.stdout.toString(); -} +writeFiles(testdata, "src/testdata/textproto"); diff --git a/packages/cel-spec/scripts/gen_incremental_tests.go b/packages/cel-spec/scripts/gen_incremental_tests.go index a35d9f7f..6cf1b5ca 100644 --- a/packages/cel-spec/scripts/gen_incremental_tests.go +++ b/packages/cel-spec/scripts/gen_incremental_tests.go @@ -47,6 +47,7 @@ import ( proto3pb "github.com/google/cel-go/test/proto3pb" "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/encoding/prototext" ) var ( @@ -176,7 +177,7 @@ func main() { outputPath := flag.String("output", "output.json", "write result to file") flag.Parse() if len(flag.Args()) != 1 { - log.Fatalf("must provide path to a cel-go source file or testdata JSON directory") + log.Fatalf("must provide path to a cel-go source file or testdata textproto directory") } sourcePath := flag.Args()[0] suite := &IncrementalSuite{} @@ -189,14 +190,14 @@ func main() { for _, path := range simpleTestFilePaths { name := path.Name() - if strings.HasSuffix(name, ".json") { + if strings.HasSuffix(name, ".textproto") { simpleTestFile, err := os.ReadFile(sourcePath + "/" + name) if err != nil { log.Fatalf("failed to read file: %v", err) } var file testpb.SimpleTestFile - err = protojson.Unmarshal(simpleTestFile, &file) + err = prototext.Unmarshal(simpleTestFile, &file) if err != nil { log.Fatalf("failed to unmarshal file: %v", err) } diff --git a/packages/cel-spec/src/testdata/conformance.ts b/packages/cel-spec/src/testdata/conformance.ts index f2856a2c..a8e73f80 100644 --- a/packages/cel-spec/src/testdata/conformance.ts +++ b/packages/cel-spec/src/testdata/conformance.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Generated from cel-go ../src/testdata/json +// Generated from cel-go ../src/testdata/textproto import type { SerializedIncrementalTestSuite } from "./tests.js"; export const tests: SerializedIncrementalTestSuite = { name: "conformance", diff --git a/packages/cel-spec/src/testdata/json/basic.json b/packages/cel-spec/src/testdata/json/basic.json deleted file mode 100644 index bb63dd46..00000000 --- a/packages/cel-spec/src/testdata/json/basic.json +++ /dev/null @@ -1,436 +0,0 @@ -{ - "name": "basic", - "description": "Basic conformance tests that all implementations should pass.", - "section": [ - { - "name": "self_eval_zeroish", - "description": "Simple self-evaluating forms to zero-ish values.", - "test": [ - { - "name": "self_eval_int_zero", - "expr": "0", - "value": { - "int64Value": "0" - } - }, - { - "name": "self_eval_uint_zero", - "expr": "0u", - "value": { - "uint64Value": "0" - } - }, - { - "name": "self_eval_uint_alias_zero", - "expr": "0U", - "value": { - "uint64Value": "0" - } - }, - { - "name": "self_eval_float_zero", - "expr": "0.0", - "value": { - "doubleValue": 0 - } - }, - { - "name": "self_eval_float_zerowithexp", - "expr": "0e+0", - "value": { - "doubleValue": 0 - } - }, - { - "name": "self_eval_string_empty", - "expr": "''", - "value": { - "stringValue": "" - } - }, - { - "name": "self_eval_string_empty_quotes", - "expr": "\"\"", - "value": { - "stringValue": "" - } - }, - { - "name": "self_eval_string_raw_prefix", - "expr": "r\"\"", - "value": { - "stringValue": "" - } - }, - { - "name": "self_eval_bytes_empty", - "expr": "b\"\"", - "value": { - "bytesValue": "" - } - }, - { - "name": "self_eval_bool_false", - "expr": "false", - "value": { - "boolValue": false - } - }, - { - "name": "self_eval_null", - "expr": "null", - "value": { - "nullValue": null - } - }, - { - "name": "self_eval_empty_list", - "expr": "[]", - "value": { - "listValue": {} - } - }, - { - "name": "self_eval_empty_map", - "expr": "{}", - "value": { - "mapValue": {} - } - }, - { - "name": "self_eval_string_raw_prefix_triple_double", - "expr": "r\"\"\"\"\"\"", - "value": { - "stringValue": "" - } - }, - { - "name": "self_eval_string_raw_prefix_triple_single", - "expr": "r''''''", - "value": { - "stringValue": "" - } - } - ] - }, - { - "name": "self_eval_nonzeroish", - "description": "Simple self-evaluating forms to non-zero-ish values.", - "test": [ - { - "name": "self_eval_int_nonzero", - "expr": "42", - "value": { - "int64Value": "42" - } - }, - { - "name": "self_eval_uint_nonzero", - "expr": "123456789u", - "value": { - "uint64Value": "123456789" - } - }, - { - "name": "self_eval_uint_alias_nonzero", - "expr": "123456789U", - "value": { - "uint64Value": "123456789" - } - }, - { - "name": "self_eval_int_negative_min", - "expr": "-9223372036854775808", - "value": { - "int64Value": "-9223372036854775808" - } - }, - { - "name": "self_eval_float_negative_exp", - "expr": "-2.3e+1", - "value": { - "doubleValue": -23 - } - }, - { - "name": "self_eval_string_excl", - "expr": "\"!\"", - "value": { - "stringValue": "!" - } - }, - { - "name": "self_eval_string_escape", - "expr": "'\\''", - "value": { - "stringValue": "'" - } - }, - { - "name": "self_eval_bytes_escape", - "expr": "b'ÿ'", - "value": { - "bytesValue": "w78=" - } - }, - { - "name": "self_eval_bytes_invalid_utf8", - "expr": "b'\\000\\xff'", - "value": { - "bytesValue": "AP8=" - } - }, - { - "name": "self_eval_list_singleitem", - "expr": "[-1]", - "value": { - "listValue": { - "values": [ - { - "int64Value": "-1" - } - ] - } - } - }, - { - "name": "self_eval_map_singleitem", - "expr": "{\"k\":\"v\"}", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "k" - }, - "value": { - "stringValue": "v" - } - } - ] - } - } - }, - { - "name": "self_eval_bool_true", - "expr": "true", - "value": { - "boolValue": true - } - }, - { - "name": "self_eval_int_hex", - "expr": "0x55555555", - "value": { - "int64Value": "1431655765" - } - }, - { - "name": "self_eval_int_hex_negative", - "expr": "-0x55555555", - "value": { - "int64Value": "-1431655765" - } - }, - { - "name": "self_eval_uint_hex", - "expr": "0x55555555u", - "value": { - "uint64Value": "1431655765" - } - }, - { - "name": "self_eval_uint_alias_hex", - "expr": "0x55555555U", - "value": { - "uint64Value": "1431655765" - } - }, - { - "name": "self_eval_unicode_escape_four", - "expr": "\"\\u270c\"", - "value": { - "stringValue": "✌" - } - }, - { - "name": "self_eval_unicode_escape_eight", - "expr": "\"\\U0001f431\"", - "value": { - "stringValue": "🐱" - } - }, - { - "name": "self_eval_ascii_escape_seq", - "expr": "\"\\a\\b\\f\\n\\r\\t\\v\\\"\\'\\\\\"", - "value": { - "stringValue": "\u0007\b\f\n\r\t\u000b\"'\\" - } - } - ] - }, - { - "name": "variables", - "description": "Variable lookups.", - "test": [ - { - "name": "self_eval_bound_lookup", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "primitive": "INT64" - } - } - } - ], - "bindings": { - "x": { - "value": { - "int64Value": "123" - } - } - }, - "value": { - "int64Value": "123" - } - }, - { - "name": "self_eval_unbound_lookup", - "description": "An unbound variable should be marked as an error during execution. See google/cel-go#154", - "expr": "x", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "undeclared reference to 'x' (in container '')" - } - ] - } - }, - { - "name": "unbound_is_runtime_error", - "description": "Make sure we can short-circuit around an unbound variable.", - "expr": "x || true", - "disableCheck": true, - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "functions", - "description": "Basic mechanisms for function calls.", - "test": [ - { - "name": "binop", - "expr": "1 + 1", - "value": { - "int64Value": "2" - } - }, - { - "name": "unbound", - "expr": "f_unknown(17)", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "unbound function" - } - ] - } - }, - { - "name": "unbound_is_runtime_error", - "expr": "f_unknown(17) || true", - "disableCheck": true, - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "reserved_const", - "description": "Named constants should never be shadowed by identifiers.", - "test": [ - { - "name": "false", - "expr": "false", - "typeEnv": [ - { - "name": "false", - "ident": { - "type": { - "primitive": "BOOL" - } - } - } - ], - "bindings": { - "false": { - "value": { - "boolValue": true - } - } - }, - "value": { - "boolValue": false - } - }, - { - "name": "true", - "expr": "true", - "typeEnv": [ - { - "name": "true", - "ident": { - "type": { - "primitive": "BOOL" - } - } - } - ], - "bindings": { - "true": { - "value": { - "boolValue": false - } - } - }, - "value": { - "boolValue": true - } - }, - { - "name": "null", - "expr": "null", - "typeEnv": [ - { - "name": "null", - "ident": { - "type": { - "primitive": "BOOL" - } - } - } - ], - "bindings": { - "null": { - "value": { - "boolValue": true - } - } - }, - "value": { - "nullValue": null - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/bindings_ext.json b/packages/cel-spec/src/testdata/json/bindings_ext.json deleted file mode 100644 index 01437afe..00000000 --- a/packages/cel-spec/src/testdata/json/bindings_ext.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "bindings_ext", - "description": "Tests for the bindings extension library.", - "section": [ - { - "name": "bind", - "test": [ - { - "name": "boolean_literal", - "expr": "cel.bind(t, true, t)", - "value": { - "boolValue": true - } - }, - { - "name": "string_concat", - "expr": "cel.bind(msg, \"hello\", msg + msg + msg)", - "value": { - "stringValue": "hellohellohello" - } - }, - { - "name": "bind_nested", - "expr": "cel.bind(t1, true, cel.bind(t2, true, t1 && t2))", - "value": { - "boolValue": true - } - }, - { - "name": "macro_exists", - "expr": "cel.bind(valid_elems, [1, 2, 3], [3, 4, 5].exists(e, e in valid_elems))", - "value": { - "boolValue": true - } - }, - { - "name": "macro_not_exists", - "expr": "cel.bind(valid_elems, [1, 2, 3], ![4, 5].exists(e, e in valid_elems))", - "value": { - "boolValue": true - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/block_ext.json b/packages/cel-spec/src/testdata/json/block_ext.json deleted file mode 100644 index 7a9f37f6..00000000 --- a/packages/cel-spec/src/testdata/json/block_ext.json +++ /dev/null @@ -1,1096 +0,0 @@ -{ - "name": "block_ext", - "description": "Tests for cel.block.", - "section": [ - { - "name": "basic", - "test": [ - { - "name": "int_add", - "expr": "cel.block([1, cel.index(0) + 1, cel.index(1) + 1, cel.index(2) + 1], cel.index(3))", - "value": { - "int64Value": "4" - } - }, - { - "name": "size_1", - "expr": "cel.block([[1, 2], size(cel.index(0)), cel.index(1) + cel.index(1), cel.index(2) + 1], cel.index(3))", - "value": { - "int64Value": "5" - } - }, - { - "name": "size_2", - "expr": "cel.block([[1, 2], size(cel.index(0)), 2 + cel.index(1), cel.index(2) + cel.index(1), cel.index(3) + 1], cel.index(4))", - "value": { - "int64Value": "7" - } - }, - { - "name": "size_3", - "expr": "cel.block([[0], size(cel.index(0)), [1, 2], size(cel.index(2)), cel.index(1) + cel.index(1), cel.index(4) + cel.index(3), cel.index(5) + cel.index(3)], cel.index(6))", - "value": { - "int64Value": "6" - } - }, - { - "name": "size_4", - "expr": "cel.block([[0], size(cel.index(0)), [1, 2], size(cel.index(2)), [1, 2, 3], size(cel.index(4)), 5 + cel.index(1), cel.index(6) + cel.index(1), cel.index(7) + cel.index(3), cel.index(8) + cel.index(3), cel.index(9) + cel.index(5), cel.index(10) + cel.index(5)], cel.index(11))", - "value": { - "int64Value": "17" - } - }, - { - "name": "timestamp", - "expr": "cel.block([timestamp(1000000000), int(cel.index(0)), timestamp(cel.index(1)), cel.index(2).getFullYear(), timestamp(50), int(cel.index(4)), timestamp(cel.index(5)), timestamp(200), int(cel.index(7)), timestamp(cel.index(8)), cel.index(9).getFullYear(), timestamp(75), int(cel.index(11)), timestamp(cel.index(12)), cel.index(13).getFullYear(), cel.index(3) + cel.index(14), cel.index(6).getFullYear(), cel.index(15) + cel.index(16), cel.index(17) + cel.index(3), cel.index(6).getSeconds(), cel.index(18) + cel.index(19), cel.index(20) + cel.index(10), cel.index(21) + cel.index(10), cel.index(13).getMinutes(), cel.index(22) + cel.index(23), cel.index(24) + cel.index(3)], cel.index(25))", - "value": { - "int64Value": "13934" - } - }, - { - "name": "map_index", - "expr": "cel.block([{\"a\": 2}, cel.index(0)[\"a\"], cel.index(1) * cel.index(1), cel.index(1) + cel.index(2)], cel.index(3))", - "value": { - "int64Value": "6" - } - }, - { - "name": "nested_map_construction", - "expr": "cel.block([{\"b\": 1}, {\"e\": cel.index(0)}], {\"a\": cel.index(0), \"c\": cel.index(0), \"d\": cel.index(1), \"e\": cel.index(1)})", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "a" - }, - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "b" - }, - "value": { - "int64Value": "1" - } - } - ] - } - } - }, - { - "key": { - "stringValue": "c" - }, - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "b" - }, - "value": { - "int64Value": "1" - } - } - ] - } - } - }, - { - "key": { - "stringValue": "d" - }, - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "e" - }, - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "b" - }, - "value": { - "int64Value": "1" - } - } - ] - } - } - } - ] - } - } - }, - { - "key": { - "stringValue": "e" - }, - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "e" - }, - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "b" - }, - "value": { - "int64Value": "1" - } - } - ] - } - } - } - ] - } - } - } - ] - } - } - }, - { - "name": "nested_list_construction", - "expr": "cel.block([[1, 2, 3, 4], [1, 2], [cel.index(1), cel.index(0)]], [1, cel.index(0), 2, cel.index(0), 5, cel.index(0), 7, cel.index(2), cel.index(1)])", - "value": { - "listValue": { - "values": [ - { - "int64Value": "1" - }, - { - "listValue": { - "values": [ - { - "int64Value": "1" - }, - { - "int64Value": "2" - }, - { - "int64Value": "3" - }, - { - "int64Value": "4" - } - ] - } - }, - { - "int64Value": "2" - }, - { - "listValue": { - "values": [ - { - "int64Value": "1" - }, - { - "int64Value": "2" - }, - { - "int64Value": "3" - }, - { - "int64Value": "4" - } - ] - } - }, - { - "int64Value": "5" - }, - { - "listValue": { - "values": [ - { - "int64Value": "1" - }, - { - "int64Value": "2" - }, - { - "int64Value": "3" - }, - { - "int64Value": "4" - } - ] - } - }, - { - "int64Value": "7" - }, - { - "listValue": { - "values": [ - { - "listValue": { - "values": [ - { - "int64Value": "1" - }, - { - "int64Value": "2" - } - ] - } - }, - { - "listValue": { - "values": [ - { - "int64Value": "1" - }, - { - "int64Value": "2" - }, - { - "int64Value": "3" - }, - { - "int64Value": "4" - } - ] - } - } - ] - } - }, - { - "listValue": { - "values": [ - { - "int64Value": "1" - }, - { - "int64Value": "2" - } - ] - } - } - ] - } - } - }, - { - "name": "select", - "expr": "cel.block([msg.single_int64, cel.index(0) + cel.index(0)], cel.index(1))", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32": 5, - "singleInt64": "3", - "oneofType": { - "payload": { - "singleInt32": 8, - "singleInt64": "10", - "mapInt32Int64": { - "0": "1", - "1": "5", - "2": "2" - }, - "mapStringString": { - "key": "A" - } - } - } - } - } - } - }, - "value": { - "int64Value": "6" - } - }, - { - "name": "select_nested_1", - "expr": "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).single_int64, cel.index(1).single_int32, cel.index(2) + cel.index(3), cel.index(4) + cel.index(2), msg.single_int64, cel.index(5) + cel.index(6), cel.index(1).oneof_type, cel.index(8).payload, cel.index(9).single_int64, cel.index(7) + cel.index(10)], cel.index(11))", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32": 5, - "singleInt64": "3", - "oneofType": { - "payload": { - "singleInt32": 8, - "singleInt64": "10", - "mapInt32Int64": { - "0": "1", - "1": "5", - "2": "2" - }, - "mapStringString": { - "key": "A" - } - } - } - } - } - } - }, - "value": { - "int64Value": "31" - } - }, - { - "name": "select_nested_2", - "expr": "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).oneof_type, cel.index(2).payload, cel.index(3).oneof_type, cel.index(4).payload, cel.index(5).oneof_type, cel.index(6).payload, cel.index(7).single_bool, true || cel.index(8), cel.index(4).child, cel.index(10).child, cel.index(11).payload, cel.index(12).single_bool], cel.index(9) || cel.index(13))", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32": 5, - "singleInt64": "3", - "oneofType": { - "payload": { - "singleInt32": 8, - "singleInt64": "10", - "mapInt32Int64": { - "0": "1", - "1": "5", - "2": "2" - }, - "mapStringString": { - "key": "A" - } - } - } - } - } - } - }, - "value": { - "boolValue": true - } - }, - { - "name": "select_nested_message_map_index_1", - "expr": "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).map_int32_int64, cel.index(2)[1], cel.index(3) + cel.index(3), cel.index(4) + cel.index(3)], cel.index(5))", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32": 5, - "singleInt64": "3", - "oneofType": { - "payload": { - "singleInt32": 8, - "singleInt64": "10", - "mapInt32Int64": { - "0": "1", - "1": "5", - "2": "2" - }, - "mapStringString": { - "key": "A" - } - } - } - } - } - } - }, - "value": { - "int64Value": "15" - } - }, - { - "name": "select_nested_message_map_index_2", - "expr": "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).map_int32_int64, cel.index(2)[0], cel.index(2)[1], cel.index(3) + cel.index(4), cel.index(2)[2], cel.index(5) + cel.index(6)], cel.index(7))", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32": 5, - "singleInt64": "3", - "oneofType": { - "payload": { - "singleInt32": 8, - "singleInt64": "10", - "mapInt32Int64": { - "0": "1", - "1": "5", - "2": "2" - }, - "mapStringString": { - "key": "A" - } - } - } - } - } - } - }, - "value": { - "int64Value": "8" - } - }, - { - "name": "ternary", - "expr": "cel.block([msg.single_int64, cel.index(0) > 0, cel.index(1) ? cel.index(0) : 0], cel.index(2))", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32": 5, - "singleInt64": "3", - "oneofType": { - "payload": { - "singleInt32": 8, - "singleInt64": "10", - "mapInt32Int64": { - "0": "1", - "1": "5", - "2": "2" - }, - "mapStringString": { - "key": "A" - } - } - } - } - } - } - }, - "value": { - "int64Value": "3" - } - }, - { - "name": "nested_ternary", - "expr": "cel.block([msg.single_int64, msg.single_int32, cel.index(0) > 0, cel.index(1) > 0, cel.index(0) + cel.index(1), cel.index(3) ? cel.index(4) : 0, cel.index(2) ? cel.index(5) : 0], cel.index(6))", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32": 5, - "singleInt64": "3", - "oneofType": { - "payload": { - "singleInt32": 8, - "singleInt64": "10", - "mapInt32Int64": { - "0": "1", - "1": "5", - "2": "2" - }, - "mapStringString": { - "key": "A" - } - } - } - } - } - } - }, - "value": { - "int64Value": "8" - } - }, - { - "name": "multiple_macros_1", - "expr": "cel.block([[1].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 0), size([cel.index(0)]), [2].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 1), size([cel.index(2)])], cel.index(1) + cel.index(1) + cel.index(3) + cel.index(3))", - "value": { - "int64Value": "4" - } - }, - { - "name": "multiple_macros_2", - "expr": "cel.block([[1].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 0), [cel.index(0)], ['a'].exists(cel.iterVar(0, 1), cel.iterVar(0, 1) == 'a'), [cel.index(2)]], cel.index(1) + cel.index(1) + cel.index(3) + cel.index(3))", - "value": { - "listValue": { - "values": [ - { - "boolValue": true - }, - { - "boolValue": true - }, - { - "boolValue": true - }, - { - "boolValue": true - } - ] - } - } - }, - { - "name": "multiple_macros_3", - "expr": "cel.block([[1].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 0)], cel.index(0) && cel.index(0) && [1].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 1) && [2].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 1))", - "value": { - "boolValue": false - } - }, - { - "name": "nested_macros_1", - "expr": "cel.block([[1, 2, 3]], cel.index(0).map(cel.iterVar(0, 0), cel.index(0).map(cel.iterVar(1, 0), cel.iterVar(1, 0) + 1)))", - "value": { - "listValue": { - "values": [ - { - "listValue": { - "values": [ - { - "int64Value": "2" - }, - { - "int64Value": "3" - }, - { - "int64Value": "4" - } - ] - } - }, - { - "listValue": { - "values": [ - { - "int64Value": "2" - }, - { - "int64Value": "3" - }, - { - "int64Value": "4" - } - ] - } - }, - { - "listValue": { - "values": [ - { - "int64Value": "2" - }, - { - "int64Value": "3" - }, - { - "int64Value": "4" - } - ] - } - } - ] - } - } - }, - { - "name": "nested_macros_2", - "expr": "[1, 2].map(cel.iterVar(0, 0), [1, 2, 3].filter(cel.iterVar(1, 0), cel.iterVar(1, 0) == cel.iterVar(0, 0)))", - "value": { - "listValue": { - "values": [ - { - "listValue": { - "values": [ - { - "int64Value": "1" - } - ] - } - }, - { - "listValue": { - "values": [ - { - "int64Value": "2" - } - ] - } - } - ] - } - } - }, - { - "name": "adjacent_macros", - "expr": "cel.block([[1, 2, 3], cel.index(0).map(cel.iterVar(0, 0), cel.index(0).map(cel.iterVar(1, 0), cel.iterVar(1, 0) + 1))], cel.index(1) == cel.index(1))", - "value": { - "boolValue": true - } - }, - { - "name": "macro_shadowed_variable_1", - "expr": "cel.block([x - 1, cel.index(0) > 3], [cel.index(1) ? cel.index(0) : 5].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) - 1 > 3) || cel.index(1))", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "primitive": "INT64" - } - } - } - ], - "bindings": { - "x": { - "value": { - "int64Value": "5" - } - } - }, - "value": { - "boolValue": true - } - }, - { - "name": "macro_shadowed_variable_2", - "expr": "['foo', 'bar'].map(cel.iterVar(1, 0), [cel.iterVar(1, 0) + cel.iterVar(1, 0), cel.iterVar(1, 0) + cel.iterVar(1, 0)]).map(cel.iterVar(0, 0), [cel.iterVar(0, 0) + cel.iterVar(0, 0), cel.iterVar(0, 0) + cel.iterVar(0, 0)])", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "primitive": "INT64" - } - } - } - ], - "bindings": { - "x": { - "value": { - "int64Value": "5" - } - } - }, - "value": { - "listValue": { - "values": [ - { - "listValue": { - "values": [ - { - "listValue": { - "values": [ - { - "stringValue": "foofoo" - }, - { - "stringValue": "foofoo" - }, - { - "stringValue": "foofoo" - }, - { - "stringValue": "foofoo" - } - ] - } - }, - { - "listValue": { - "values": [ - { - "stringValue": "foofoo" - }, - { - "stringValue": "foofoo" - }, - { - "stringValue": "foofoo" - }, - { - "stringValue": "foofoo" - } - ] - } - } - ] - } - }, - { - "listValue": { - "values": [ - { - "listValue": { - "values": [ - { - "stringValue": "barbar" - }, - { - "stringValue": "barbar" - }, - { - "stringValue": "barbar" - }, - { - "stringValue": "barbar" - } - ] - } - }, - { - "listValue": { - "values": [ - { - "stringValue": "barbar" - }, - { - "stringValue": "barbar" - }, - { - "stringValue": "barbar" - }, - { - "stringValue": "barbar" - } - ] - } - } - ] - } - } - ] - } - } - }, - { - "name": "inclusion_list", - "expr": "cel.block([[1, 2, 3], 1 in cel.index(0), 2 in cel.index(0), cel.index(1) && cel.index(2), [3, cel.index(0)], 3 in cel.index(4), cel.index(5) && cel.index(1)], cel.index(3) && cel.index(6))", - "value": { - "boolValue": true - } - }, - { - "name": "inclusion_map", - "expr": "cel.block([{true: false}, {\"a\": 1, 2: cel.index(0), 3: cel.index(0)}], 2 in cel.index(1))", - "value": { - "boolValue": true - } - }, - { - "name": "presence_test", - "expr": "cel.block([{\"a\": true}, has(cel.index(0).a), cel.index(0)[\"a\"]], cel.index(1) && cel.index(2))", - "value": { - "boolValue": true - } - }, - { - "name": "presence_test_2", - "expr": "cel.block([{\"a\": true}, has(cel.index(0).a)], cel.index(1) && cel.index(1))", - "value": { - "boolValue": true - } - }, - { - "name": "presence_test_with_ternary", - "expr": "cel.block([msg.oneof_type, has(cel.index(0).payload), cel.index(0).payload, cel.index(2).single_int64, cel.index(1) ? cel.index(3) : 0], cel.index(4))", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32": 5, - "singleInt64": "3", - "oneofType": { - "payload": { - "singleInt32": 8, - "singleInt64": "10", - "mapInt32Int64": { - "0": "1", - "1": "5", - "2": "2" - }, - "mapStringString": { - "key": "A" - } - } - } - } - } - } - }, - "value": { - "int64Value": "10" - } - }, - { - "name": "presence_test_with_ternary_2", - "expr": "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).single_int64, has(cel.index(0).payload), cel.index(2) * 0, cel.index(3) ? cel.index(2) : cel.index(4)], cel.index(5))", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32": 5, - "singleInt64": "3", - "oneofType": { - "payload": { - "singleInt32": 8, - "singleInt64": "10", - "mapInt32Int64": { - "0": "1", - "1": "5", - "2": "2" - }, - "mapStringString": { - "key": "A" - } - } - } - } - } - } - }, - "value": { - "int64Value": "10" - } - }, - { - "name": "presence_test_with_ternary_3", - "expr": "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).single_int64, has(cel.index(1).single_int64), cel.index(2) * 0, cel.index(3) ? cel.index(2) : cel.index(4)], cel.index(5))", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32": 5, - "singleInt64": "3", - "oneofType": { - "payload": { - "singleInt32": 8, - "singleInt64": "10", - "mapInt32Int64": { - "0": "1", - "1": "5", - "2": "2" - }, - "mapStringString": { - "key": "A" - } - } - } - } - } - } - }, - "value": { - "int64Value": "10" - } - }, - { - "name": "presence_test_with_ternary_nested", - "expr": "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).map_string_string, has(msg.oneof_type), has(cel.index(0).payload), cel.index(3) && cel.index(4), has(cel.index(1).single_int64), cel.index(5) && cel.index(6), has(cel.index(1).map_string_string), has(cel.index(2).key), cel.index(8) && cel.index(9), cel.index(2).key, cel.index(11) == \"A\", cel.index(10) ? cel.index(12) : false], cel.index(7) ? cel.index(13) : false)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32": 5, - "singleInt64": "3", - "oneofType": { - "payload": { - "singleInt32": 8, - "singleInt64": "10", - "mapInt32Int64": { - "0": "1", - "1": "5", - "2": "2" - }, - "mapStringString": { - "key": "A" - } - } - } - } - } - } - }, - "value": { - "boolValue": true - } - }, - { - "name": "optional_list", - "expr": "cel.block([optional.none(), [?cel.index(0), ?optional.of(opt_x)], [5], [10, ?cel.index(0), cel.index(1), cel.index(1)], [10, cel.index(2), cel.index(2)]], cel.index(3) == cel.index(4))", - "typeEnv": [ - { - "name": "opt_x", - "ident": { - "type": { - "primitive": "INT64" - } - } - } - ], - "bindings": { - "opt_x": { - "value": { - "int64Value": "5" - } - } - }, - "value": { - "boolValue": true - } - }, - { - "name": "optional_map", - "expr": "cel.block([optional.of(\"hello\"), {?\"hello\": cel.index(0)}, cel.index(1)[\"hello\"], cel.index(2) + cel.index(2)], cel.index(3) == \"hellohello\")", - "value": { - "boolValue": true - } - }, - { - "name": "optional_map_chained", - "expr": "cel.block([{\"key\": \"test\"}, optional.of(\"test\"), {?\"key\": cel.index(1)}, cel.index(2)[?\"bogus\"], cel.index(0)[?\"bogus\"], cel.index(3).or(cel.index(4)), cel.index(0)[\"key\"], cel.index(5).orValue(cel.index(6))], cel.index(7))", - "value": { - "stringValue": "test" - } - }, - { - "name": "optional_message", - "expr": "cel.block([optional.ofNonZeroValue(1), optional.of(4), TestAllTypes{?single_int64: cel.index(0), ?single_int32: cel.index(1)}, cel.index(2).single_int32, cel.index(2).single_int64, cel.index(3) + cel.index(4)], cel.index(5))", - "container": "cel.expr.conformance.proto3", - "value": { - "int64Value": "5" - } - }, - { - "name": "call", - "expr": "cel.block([\"h\" + \"e\", cel.index(0) + \"l\", cel.index(1) + \"l\", cel.index(2) + \"o\", cel.index(3) + \" world\"], cel.index(4).matches(cel.index(3)))", - "value": { - "boolValue": true - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/comparisons.json b/packages/cel-spec/src/testdata/json/comparisons.json deleted file mode 100644 index 6bb2f1df..00000000 --- a/packages/cel-spec/src/testdata/json/comparisons.json +++ /dev/null @@ -1,3271 +0,0 @@ -{ - "name": "comparisons", - "description": "Tests for boolean-valued functions and operators.", - "section": [ - { - "name": "eq_literal", - "description": "Literals comparison on _==_", - "test": [ - { - "name": "eq_int", - "expr": "1 == 1", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_int", - "expr": "-1 == 1", - "value": { - "boolValue": false - } - }, - { - "name": "eq_int_uint", - "expr": "dyn(1) == 1u", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_int_uint", - "expr": "dyn(2) == 1u", - "value": { - "boolValue": false - } - }, - { - "name": "eq_int_double", - "expr": "dyn(1) == 1.0", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_int_double", - "expr": "dyn(2) == 1.0", - "value": { - "boolValue": false - } - }, - { - "name": "eq_uint", - "expr": "2u == 2u", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_uint", - "expr": "1u == 2u", - "value": { - "boolValue": false - } - }, - { - "name": "eq_uint_int", - "expr": "dyn(1u) == 1", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_uint_int", - "expr": "dyn(2u) == 1", - "value": { - "boolValue": false - } - }, - { - "name": "eq_uint_double", - "expr": "dyn(1u) == 1.0", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_uint_double", - "expr": "dyn(2u) == 1.0", - "value": { - "boolValue": false - } - }, - { - "name": "eq_double", - "expr": "1.0 == 1.0e+0", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_double", - "expr": "-1.0 == 1.0", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_double_nan", - "expr": "0.0/0.0 == 0.0/0.0", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_int_double_nan", - "expr": "dyn(1) == 0.0/0.0", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_uint_double_nan", - "expr": "dyn(1u) == 0.0/0.0", - "value": { - "boolValue": false - } - }, - { - "name": "eq_double_int", - "expr": "dyn(1.0) == 1", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_double_int", - "expr": "dyn(2.0) == 1", - "value": { - "boolValue": false - } - }, - { - "name": "eq_double_uint", - "expr": "dyn(1.0) == 1u", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_double_uint", - "expr": "dyn(2.0) == 1u", - "value": { - "boolValue": false - } - }, - { - "name": "eq_string", - "expr": "'' == \"\"", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_string", - "expr": "'a' == 'b'", - "value": { - "boolValue": false - } - }, - { - "name": "eq_raw_string", - "expr": "'abc' == r'abc'", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_string_case", - "expr": "'abc' == 'ABC'", - "value": { - "boolValue": false - } - }, - { - "name": "eq_string_unicode", - "expr": "'ίσος' == 'ίσος'", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_string_unicode_ascii", - "expr": "'a' == 'à'", - "value": { - "boolValue": false - } - }, - { - "name": "no_string_normalization", - "description": "Should not normalize Unicode.", - "expr": "'Am\\u00E9lie' == 'Ame\\u0301lie'", - "value": { - "boolValue": false - } - }, - { - "name": "eq_null", - "expr": "null == null", - "value": { - "boolValue": true - } - }, - { - "name": "eq_bool", - "expr": "true == true", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_bool", - "expr": "false == true", - "value": { - "boolValue": false - } - }, - { - "name": "eq_bytes", - "description": "Test bytes literal equality with encoding", - "expr": "b'ÿ' == b'\\303\\277'", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_bytes", - "expr": "b'abc' == b'abcd'", - "value": { - "boolValue": false - } - }, - { - "name": "eq_list_empty", - "expr": "[] == []", - "value": { - "boolValue": true - } - }, - { - "name": "eq_list_null", - "expr": "[null] == [null]", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_list_null", - "expr": "['1', '2', null] == ['1', '2', '3']", - "value": { - "boolValue": false - } - }, - { - "name": "eq_list_numbers", - "expr": "[1, 2, 3] == [1, 2, 3]", - "value": { - "boolValue": true - } - }, - { - "name": "eq_list_mixed_type_numbers", - "expr": "[1.0, 2.0, 3] == [1u, 2, 3u]", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_list_mixed_type_numbers", - "expr": "[1.0, 2.1] == [1u, 2]", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_list_order", - "expr": "[1, 2, 3] == [1, 3, 2]", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_list_string_case", - "expr": "['case'] == ['cAse']", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_list_length", - "expr": "['one'] == [2, 3]", - "disableCheck": true, - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_list_false_vs_types", - "expr": "[1, 'dos', 3] == [1, 2, 4]", - "value": { - "boolValue": false - } - }, - { - "name": "eq_map_empty", - "expr": "{} == {}", - "value": { - "boolValue": true - } - }, - { - "name": "eq_map_null", - "expr": "{'k': null} == {'k': null}", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_map_null", - "expr": "{'k': 1, 'j': 2} == {'k': 1, 'j': null}", - "value": { - "boolValue": false - } - }, - { - "name": "eq_map_onekey", - "expr": "{'k':'v'} == {\"k\":\"v\"}", - "value": { - "boolValue": true - } - }, - { - "name": "eq_map_double_value", - "expr": "{'k':1.0} == {'k':1e+0}", - "value": { - "boolValue": true - } - }, - { - "name": "eq_map_mixed_type_numbers", - "expr": "{1: 1.0, 2u: 3u} == {1u: 1, 2: 3.0}", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_map_value", - "expr": "{'k':'v'} == {'k':'v1'}", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_map_extra_key", - "expr": "{'k':'v','k1':'v1'} == {'k':'v'}", - "value": { - "boolValue": false - } - }, - { - "name": "eq_map_key_order", - "expr": "{'k1':'v1','k2':'v2'} == {'k2':'v2','k1':'v1'}", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_map_key_casing", - "expr": "{'key':'value'} == {'Key':'value'}", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_map_false_vs_types", - "expr": "{'k1': 1, 'k2': 'dos', 'k3': 3} == {'k1': 1, 'k2': 2, 'k3': 4}", - "value": { - "boolValue": false - } - }, - { - "name": "eq_mixed_types", - "expr": "1.0 == 1", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "eq_list_elem_mixed_types", - "expr": "[1] == [1.0]", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "eq_map_value_mixed_types", - "expr": "{'k':'v', 1:1} == {'k':'v', 1:'v1'}", - "value": { - "boolValue": false - } - }, - { - "name": "eq_dyn_json_null", - "expr": "dyn(google.protobuf.Value{}) == null", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_dyn_bool_null", - "expr": "dyn(false) == null", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_dyn_bytes_null", - "expr": "dyn(b'') == null", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_dyn_double_null", - "expr": "dyn(2.1) == null", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_dyn_duration_null", - "expr": "dyn(duration('0s')) == null", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_dyn_int_null", - "expr": "dyn(1) == null", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_dyn_list_null", - "expr": "dyn([]) == null", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_dyn_map_null", - "expr": "dyn({}) == null", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_dyn_proto2_msg_null", - "expr": "dyn(TestAllTypes{}) == null", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_dyn_proto3_msg_null", - "expr": "dyn(TestAllTypes{}) == null", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_dyn_string_null", - "expr": "dyn('') == null", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_dyn_timestamp_null", - "expr": "dyn(timestamp(0)) == null", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_list_elem_null", - "expr": "[1, 2, null] == [1, null, 3]", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_map_value_null", - "expr": "{1:'hello', 2:'world'} == {1:'goodbye', 2:null}", - "value": { - "boolValue": false - } - }, - { - "name": "eq_dyn_int_uint", - "expr": "dyn(1) == 1u", - "value": { - "boolValue": true - } - }, - { - "name": "eq_dyn_int_double", - "expr": "dyn(1) == 1.0", - "value": { - "boolValue": true - } - }, - { - "name": "eq_dyn_uint_int", - "expr": "dyn(1u) == 1", - "value": { - "boolValue": true - } - }, - { - "name": "eq_dyn_uint_double", - "expr": "dyn(1u) == 1.0", - "value": { - "boolValue": true - } - }, - { - "name": "eq_dyn_double_int", - "expr": "dyn(1.0) == 1", - "value": { - "boolValue": true - } - }, - { - "name": "eq_dyn_double_uint", - "expr": "dyn(1.0) == 1u", - "value": { - "boolValue": true - } - }, - { - "name": "not_eq_dyn_int_uint", - "expr": "dyn(1) == 2u", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_dyn_int_double", - "expr": "dyn(1) == 2.0", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_dyn_uint_int", - "expr": "dyn(1u) == 2", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_dyn_uint_double", - "expr": "dyn(1u) == 120", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_dyn_double_int", - "expr": "dyn(1.0) == 2", - "value": { - "boolValue": false - } - }, - { - "name": "not_eq_dyn_double_uint", - "expr": "dyn(1.0) == 2u", - "value": { - "boolValue": false - } - } - ] - }, - { - "name": "eq_wrapper", - "description": "Wrapper type comparison on _==_. Wrapper types treated as boxed primitives when they appear on message fields. An unset wrapper field should be treated as null. The tests show the distinction between unset, empty, and set equality behavior.", - "test": [ - { - "name": "eq_bool", - "expr": "google.protobuf.BoolValue{value: true} == true", - "value": { - "boolValue": true - } - }, - { - "name": "eq_bool_empty", - "expr": "google.protobuf.BoolValue{} == false", - "value": { - "boolValue": true - } - }, - { - "name": "eq_bool_not_null", - "expr": "google.protobuf.BoolValue{} != null", - "value": { - "boolValue": true - } - }, - { - "name": "eq_bool_proto2_null", - "expr": "TestAllTypes{}.single_bool_wrapper == null", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "eq_bool_proto3_null", - "expr": "TestAllTypes{}.single_bool_wrapper == null", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "eq_bytes", - "expr": "google.protobuf.BytesValue{value: b'set'} == b'set'", - "value": { - "boolValue": true - } - }, - { - "name": "eq_bytes_empty", - "expr": "google.protobuf.BytesValue{} == b''", - "value": { - "boolValue": true - } - }, - { - "name": "eq_bytes_not_null", - "expr": "google.protobuf.BytesValue{} != null", - "value": { - "boolValue": true - } - }, - { - "name": "eq_bytes_proto2_null", - "expr": "TestAllTypes{}.single_bytes_wrapper == null", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "eq_bytes_proto3_null", - "expr": "TestAllTypes{}.single_bytes_wrapper == null", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "eq_double", - "expr": "google.protobuf.DoubleValue{value: -1.175494e-40} == -1.175494e-40", - "value": { - "boolValue": true - } - }, - { - "name": "eq_double_empty", - "expr": "google.protobuf.DoubleValue{} == 0.0", - "value": { - "boolValue": true - } - }, - { - "name": "eq_double_not_null", - "expr": "google.protobuf.DoubleValue{} != null", - "value": { - "boolValue": true - } - }, - { - "name": "eq_double_proto2_null", - "expr": "TestAllTypes{}.single_double_wrapper == null", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "eq_double_proto3_null", - "expr": "TestAllTypes{}.single_double_wrapper == null", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "eq_float", - "expr": "google.protobuf.FloatValue{value: -1.5} == -1.5", - "value": { - "boolValue": true - } - }, - { - "name": "eq_float_empty", - "expr": "google.protobuf.FloatValue{} == 0.0", - "value": { - "boolValue": true - } - }, - { - "name": "eq_float_not_null", - "expr": "google.protobuf.FloatValue{} != null", - "value": { - "boolValue": true - } - }, - { - "name": "eq_float_proto2_null", - "expr": "TestAllTypes{}.single_float_wrapper == null", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "eq_float_proto3_null", - "expr": "TestAllTypes{}.single_float_wrapper == null", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "eq_int32", - "expr": "google.protobuf.Int32Value{value: 123} == 123", - "value": { - "boolValue": true - } - }, - { - "name": "eq_int32_empty", - "expr": "google.protobuf.Int32Value{} == 0", - "value": { - "boolValue": true - } - }, - { - "name": "eq_int32_not_null", - "expr": "google.protobuf.Int32Value{} != null", - "value": { - "boolValue": true - } - }, - { - "name": "eq_int32_proto2_null", - "expr": "TestAllTypes{}.single_int32_wrapper == null", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "eq_int32_proto3_null", - "expr": "TestAllTypes{}.single_int32_wrapper == null", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "eq_int64", - "expr": "google.protobuf.Int64Value{value: 2147483650} == 2147483650", - "value": { - "boolValue": true - } - }, - { - "name": "eq_int64_empty", - "expr": "google.protobuf.Int64Value{} == 0", - "value": { - "boolValue": true - } - }, - { - "name": "eq_int64_not_null", - "expr": "google.protobuf.Int64Value{} != null", - "value": { - "boolValue": true - } - }, - { - "name": "eq_int64_proto2_null", - "expr": "TestAllTypes{}.single_int64_wrapper == null", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "eq_int64_proto3_null", - "expr": "TestAllTypes{}.single_int64_wrapper == null", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "eq_string", - "expr": "google.protobuf.StringValue{value: 'set'} == 'set'", - "value": { - "boolValue": true - } - }, - { - "name": "eq_string_empty", - "expr": "google.protobuf.StringValue{} == ''", - "value": { - "boolValue": true - } - }, - { - "name": "eq_string_not_null", - "expr": "google.protobuf.StringValue{} != null", - "value": { - "boolValue": true - } - }, - { - "name": "eq_string_proto2_null", - "expr": "TestAllTypes{}.single_string_wrapper == null", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "eq_string_proto3_null", - "expr": "TestAllTypes{}.single_string_wrapper == null", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "eq_uint32", - "expr": "google.protobuf.UInt32Value{value: 42u} == 42u", - "value": { - "boolValue": true - } - }, - { - "name": "eq_uint32_empty", - "expr": "google.protobuf.UInt32Value{} == 0u", - "value": { - "boolValue": true - } - }, - { - "name": "eq_uint32_not_null", - "expr": "google.protobuf.UInt32Value{} != null", - "value": { - "boolValue": true - } - }, - { - "name": "eq_uint32_proto2_null", - "expr": "TestAllTypes{}.single_uint32_wrapper == null", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "eq_uint32_proto3_null", - "expr": "TestAllTypes{}.single_uint32_wrapper == null", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "eq_uint64", - "expr": "google.protobuf.UInt64Value{value: 4294967296u} == 4294967296u", - "value": { - "boolValue": true - } - }, - { - "name": "eq_uint64_empty", - "expr": "google.protobuf.UInt64Value{} == 0u", - "value": { - "boolValue": true - } - }, - { - "name": "eq_uint64_not_null", - "expr": "google.protobuf.UInt64Value{} != null", - "value": { - "boolValue": true - } - }, - { - "name": "eq_uint64_proto2_null", - "expr": "TestAllTypes{}.single_uint64_wrapper == null", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "eq_uint64_proto3_null", - "expr": "TestAllTypes{}.single_uint64_wrapper == null", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "eq_proto2", - "expr": "TestAllTypes{single_int64: 1234, single_string: '1234'} == TestAllTypes{single_int64: 1234, single_string: '1234'}", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "eq_proto3", - "expr": "TestAllTypes{single_int64: 1234, single_string: '1234'} == TestAllTypes{single_int64: 1234, single_string: '1234'}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "eq_proto2_missing_fields_neq", - "expr": "TestAllTypes{single_int64: 1234} == TestAllTypes{single_string: '1234'}", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "eq_proto3_missing_fields_neq", - "expr": "TestAllTypes{single_int64: 1234} == TestAllTypes{single_string: '1234'}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "eq_proto_nan_equal", - "description": "For proto equality, fields with NaN value are treated as not equal.", - "expr": "TestAllTypes{single_double: double('NaN')} == TestAllTypes{single_double: double('NaN')}", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "eq_proto_different_types", - "description": "At runtime, differently typed messages are treated as not equal.", - "expr": "dyn(TestAllTypes{}) == dyn(NestedTestAllTypes{})", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "eq_proto2_any_unpack_equal", - "description": "Any values should be unpacked and compared.", - "expr": "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} == TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "eq_proto2_any_unpack_not_equal", - "description": "Any values should be unpacked and compared.", - "expr": "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'a\\000\\000\\000\\000\\000H\\223\\300r\\0041234'}} == TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "eq_proto2_any_unpack_bytewise_fallback_not_equal", - "description": "If an any field is missing its type_url, the comparison should fallback to a bytewise comparison of the serialized proto.", - "expr": "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} == TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "eq_proto2_any_unpack_bytewise_fallback_equal", - "description": "If an any field is missing its type_url, the comparison should fallback to a bytewise comparison of the serialized proto.", - "expr": "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} == TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}}", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "eq_proto3_any_unpack_equal", - "description": "Any values should be unpacked and compared.", - "expr": "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} == TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "eq_proto3_any_unpack_not_equal", - "description": "Any values should be unpacked and compared.", - "expr": "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'a\\000\\000\\000\\000\\000H\\223\\300r\\0041234'}} == TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "eq_proto3_any_unpack_bytewise_fallback_not_equal", - "description": "If an any field is missing its type_url, the comparison should fallback to a bytewise comparison of the serialized proto.", - "expr": "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} == TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "eq_proto3_any_unpack_bytewise_fallback_equal", - "description": "If an any field is missing its type_url, the comparison should fallback to a bytewise comparison of the serialized proto.", - "expr": "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} == TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "ne_literal", - "description": "Literals comparison on _!=_", - "test": [ - { - "name": "ne_int", - "expr": "24 != 42", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_int", - "expr": "1 != 1", - "value": { - "boolValue": false - } - }, - { - "name": "ne_int_double", - "expr": "dyn(24) != 24.1", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_int_double", - "expr": "dyn(1) != 1.0", - "value": { - "boolValue": false - } - }, - { - "name": "ne_int_uint", - "expr": "dyn(24) != 42u", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_int_uint", - "expr": "dyn(1) != 1u", - "value": { - "boolValue": false - } - }, - { - "name": "ne_uint", - "expr": "1u != 2u", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_uint", - "expr": "99u != 99u", - "value": { - "boolValue": false - } - }, - { - "name": "ne_uint_double", - "expr": "dyn(1u) != 2.0", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_uint_double", - "expr": "dyn(99u) != 99.0", - "value": { - "boolValue": false - } - }, - { - "name": "ne_double", - "expr": "9.0e+3 != 9001.0", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_double_nan", - "expr": "0.0/0.0 != 0.0/0.0", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_int_double_nan", - "expr": "dyn(1) != 0.0/0.0", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_uint_double_nan", - "expr": "dyn(1u) != 0.0/0.0", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_double", - "expr": "1.0 != 1e+0", - "value": { - "boolValue": false - } - }, - { - "name": "ne_double_int", - "expr": "dyn(9000) != 9001.0", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_double_int", - "expr": "dyn(1) != 1e+0", - "value": { - "boolValue": false - } - }, - { - "name": "ne_double_uint", - "expr": "dyn(9000u) != 9001.0", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_double_uint", - "expr": "dyn(1u) != 1e+0", - "value": { - "boolValue": false - } - }, - { - "name": "ne_double_nan", - "expr": "0.0/0.0 != 0.0/0.0", - "value": { - "boolValue": true - } - }, - { - "name": "ne_string", - "expr": "'abc' != ''", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_string", - "expr": "'abc' != 'abc'", - "value": { - "boolValue": false - } - }, - { - "name": "ne_string_unicode", - "expr": "'résumé' != 'resume'", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_string_unicode", - "expr": "'ίδιο' != 'ίδιο'", - "value": { - "boolValue": false - } - }, - { - "name": "ne_bytes", - "expr": "b'\\x00\\xFF' != b'ÿ'", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_bytes", - "expr": "b'\\303\\277' != b'ÿ'", - "value": { - "boolValue": false - } - }, - { - "name": "ne_bool", - "expr": "false != true", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_bool", - "expr": "true != true", - "value": { - "boolValue": false - } - }, - { - "name": "not_ne_null", - "description": "null can only be equal to null, or else it won't match", - "expr": "null != null", - "value": { - "boolValue": false - } - }, - { - "name": "ne_list_empty", - "expr": "[] != [1]", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_list_empty", - "expr": "[] != []", - "value": { - "boolValue": false - } - }, - { - "name": "ne_list_bool", - "expr": "[true, false, true] != [true, true, false]", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_list_bool", - "expr": "[false, true] != [false, true]", - "value": { - "boolValue": false - } - }, - { - "name": "not_ne_list_of_list", - "expr": "[[]] != [[]]", - "value": { - "boolValue": false - } - }, - { - "name": "ne_map_by_value", - "expr": "{'k':'v'} != {'k':'v1'}", - "value": { - "boolValue": true - } - }, - { - "name": "ne_map_by_key", - "expr": "{'k':true} != {'k1':true}", - "value": { - "boolValue": true - } - }, - { - "name": "not_ne_map_int_to_float", - "expr": "{1:1.0} != {1:1.0}", - "value": { - "boolValue": false - } - }, - { - "name": "not_ne_map_key_order", - "expr": "{'a':'b','c':'d'} != {'c':'d','a':'b'}", - "value": { - "boolValue": false - } - }, - { - "name": "ne_mixed_types", - "expr": "2u != 2", - "disableCheck": true, - "value": { - "boolValue": false - } - }, - { - "name": "ne_proto2", - "expr": "TestAllTypes{single_int64: 1234, single_string: '1234'} != TestAllTypes{single_int64: 1234, single_string: '1234'}", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "ne_proto3", - "expr": "TestAllTypes{single_int64: 1234, single_string: '1234'} != TestAllTypes{single_int64: 1234, single_string: '1234'}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "ne_proto2_missing_fields_neq", - "expr": "TestAllTypes{single_int64: 1234} != TestAllTypes{single_string: '1234'}", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "ne_proto3_missing_fields_neq", - "expr": "TestAllTypes{single_int64: 1234} != TestAllTypes{single_string: '1234'}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "ne_proto_nan_not_equal", - "description": "For proto equality, NaN field values are not considered equal.", - "expr": "TestAllTypes{single_double: double('NaN')} != TestAllTypes{single_double: double('NaN')}", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "ne_proto_different_types", - "description": "At runtime, comparing differently typed messages is false.", - "expr": "dyn(TestAllTypes{}) != dyn(NestedTestAllTypes{})", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "ne_proto2_any_unpack", - "description": "Any values should be unpacked and compared.", - "expr": "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} != TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "ne_proto2_any_unpack_bytewise_fallback", - "description": "If an any field is missing its type_url, the comparison should fallback to a bytewise comparison of the serialized proto.", - "expr": "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} != TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "ne_proto3_any_unpack", - "description": "Any values should be unpacked and compared.", - "expr": "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} != TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "ne_proto3_any_unpack_bytewise_fallback", - "description": "If an any field is missing its type_url, the comparison should fallback to a bytewise comparison of the serialized proto.", - "expr": "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} != TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "lt_literal", - "description": "Literals comparison on _<_. (a < b) == (b > a) == !(a >= b) == !(b <= a)", - "test": [ - { - "name": "lt_int", - "expr": "-1 < 0", - "value": { - "boolValue": true - } - }, - { - "name": "not_lt_int", - "expr": "0 < 0", - "value": { - "boolValue": false - } - }, - { - "name": "lt_uint", - "expr": "0u < 1u", - "value": { - "boolValue": true - } - }, - { - "name": "not_lt_uint", - "expr": "2u < 2u", - "value": { - "boolValue": false - } - }, - { - "name": "lt_double", - "expr": "1.0 < 1.0000001", - "value": { - "boolValue": true - } - }, - { - "name": "not_lt_double", - "description": "Following IEEE 754, negative zero compares equal to zero", - "expr": "-0.0 < 0.0", - "value": { - "boolValue": false - } - }, - { - "name": "lt_string", - "expr": "'a' < 'b'", - "value": { - "boolValue": true - } - }, - { - "name": "lt_string_empty_to_nonempty", - "expr": "'' < 'a'", - "value": { - "boolValue": true - } - }, - { - "name": "lt_string_case", - "expr": "'Abc' < 'aBC'", - "value": { - "boolValue": true - } - }, - { - "name": "lt_string_length", - "expr": "'abc' < 'abcd'", - "value": { - "boolValue": true - } - }, - { - "name": "lt_string_diacritical_mark_sensitive", - "description": "Verifies that the we're not using a string comparison function that strips diacritical marks (á)", - "expr": "'a' < '\\u00E1'", - "value": { - "boolValue": true - } - }, - { - "name": "not_lt_string_empty", - "expr": "'' < ''", - "value": { - "boolValue": false - } - }, - { - "name": "not_lt_string_same", - "expr": "'abc' < 'abc'", - "value": { - "boolValue": false - } - }, - { - "name": "not_lt_string_case_length", - "expr": "'a' < 'AB'", - "value": { - "boolValue": false - } - }, - { - "name": "unicode_order_lexical", - "description": "Compare the actual code points of the string, instead of decomposing ế into 'e' plus accent modifiers.", - "expr": "'f' < '\\u1EBF'", - "value": { - "boolValue": true - } - }, - { - "name": "lt_bytes", - "expr": "b'a' < b'b'", - "value": { - "boolValue": true - } - }, - { - "name": "not_lt_bytes_same", - "expr": "b'abc' < b'abc'", - "value": { - "boolValue": false - } - }, - { - "name": "not_lt_bytes_width", - "expr": "b'á' < b'b'", - "value": { - "boolValue": false - } - }, - { - "name": "lt_bool_false_first", - "expr": "false < true", - "value": { - "boolValue": true - } - }, - { - "name": "not_lt_bool_same", - "expr": "true < true", - "value": { - "boolValue": false - } - }, - { - "name": "not_lt_bool_true_first", - "expr": "true < false", - "value": { - "boolValue": false - } - }, - { - "name": "lt_list_unsupported", - "expr": "[0] < [1]", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "lt_map_unsupported", - "expr": "{0:'a'} < {1:'b'}", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "lt_null_unsupported", - "description": "Ensure _<_ doesn't have a binding for null", - "expr": "null < null", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "lt_mixed_types_error", - "expr": "'foo' < 1024", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "lt_dyn_int_uint", - "expr": "dyn(1) < 2u", - "value": { - "boolValue": true - } - }, - { - "name": "lt_dyn_int_double", - "expr": "dyn(1) < 2.0", - "value": { - "boolValue": true - } - }, - { - "name": "lt_dyn_uint_int", - "expr": "dyn(1u) < 2", - "value": { - "boolValue": true - } - }, - { - "name": "lt_dyn_uint_double", - "expr": "dyn(1u) < 2.0", - "value": { - "boolValue": true - } - }, - { - "name": "lt_dyn_double_int", - "expr": "dyn(1.0) < 2", - "value": { - "boolValue": true - } - }, - { - "name": "lt_dyn_double_uint", - "expr": "dyn(1.0) < 2u", - "value": { - "boolValue": true - } - }, - { - "name": "not_lt_dyn_int_uint", - "expr": "dyn(1) < 1u", - "value": { - "boolValue": false - } - }, - { - "name": "not_lt_dyn_int_double", - "expr": "dyn(1) < 1.0", - "value": { - "boolValue": false - } - }, - { - "name": "not_lt_dyn_uint_int", - "expr": "dyn(1u) < 1", - "value": { - "boolValue": false - } - }, - { - "name": "not_lt_dyn_uint_double", - "expr": "dyn(1u) < 1.0", - "value": { - "boolValue": false - } - }, - { - "name": "not_lt_dyn_double_int", - "expr": "dyn(1.0) < 1", - "value": { - "boolValue": false - } - }, - { - "name": "not_lt_dyn_double_uint", - "expr": "dyn(1.0) < 1u", - "value": { - "boolValue": false - } - }, - { - "name": "lt_dyn_int_big_uint", - "expr": "dyn(1) < 9223372036854775808u", - "value": { - "boolValue": true - } - }, - { - "name": "lt_dyn_small_int_uint", - "expr": "dyn(-1) < 0u", - "value": { - "boolValue": true - } - }, - { - "name": "not_lt_dyn_int_big_lossy_double", - "expr": "dyn(9223372036854775807) < 9223372036854775808.0", - "value": { - "boolValue": false - } - }, - { - "name": "lt_dyn_int_big_lossy_double", - "expr": "dyn(9223372036854775807) < 9223372036854777857.0", - "value": { - "boolValue": true - } - }, - { - "name": "not_lt_dyn_int_small_double", - "expr": "dyn(9223372036854775807) < -9223372036854777857.0", - "value": { - "boolValue": false - } - }, - { - "name": "not_lt_dyn_int_small_lossy_double", - "expr": "dyn(-9223372036854775808) < -9223372036854775809.0", - "value": { - "boolValue": false - } - }, - { - "name": "not_lt_dyn_uint_small_int", - "expr": "dyn(1u) < -9223372036854775808", - "value": { - "boolValue": false - } - }, - { - "name": "not_lt_dyn_big_uint_int", - "expr": "dyn(9223372036854775808u) < 1", - "value": { - "boolValue": false - } - }, - { - "name": "not_lt_dyn_uint_small_double", - "expr": "dyn(18446744073709551615u) < -1.0", - "value": { - "boolValue": false - } - }, - { - "name": "lt_dyn_uint_big_double", - "expr": "dyn(18446744073709551615u) < 18446744073709590000.0", - "value": { - "boolValue": true - } - }, - { - "name": "not_lt_dyn_big_double_uint", - "expr": "dyn(18446744073709553665.0) < 18446744073709551615u", - "value": { - "boolValue": false - } - }, - { - "name": "not_lt_dyn_big_double_int", - "expr": "dyn(9223372036854775808.0) < 9223372036854775807", - "value": { - "boolValue": false - } - }, - { - "name": "not_lt_dyn_small_double_int", - "expr": "dyn(-9223372036854775809.0) < -9223372036854775808", - "value": { - "boolValue": false - } - } - ] - }, - { - "name": "gt_literal", - "description": "Literals comparison on _>_", - "test": [ - { - "name": "gt_int", - "expr": "42 > -42", - "value": { - "boolValue": true - } - }, - { - "name": "not_gt_int", - "expr": "0 > 0", - "value": { - "boolValue": false - } - }, - { - "name": "gt_uint", - "expr": "48u > 46u", - "value": { - "boolValue": true - } - }, - { - "name": "not_gt_uint", - "expr": "0u > 999u", - "value": { - "boolValue": false - } - }, - { - "name": "gt_double", - "expr": "1e+1 > 1e+0", - "value": { - "boolValue": true - } - }, - { - "name": "not_gt_double", - "expr": ".99 > 9.9e-1", - "value": { - "boolValue": false - } - }, - { - "name": "gt_string_case", - "expr": "'abc' > 'aBc'", - "value": { - "boolValue": true - } - }, - { - "name": "gt_string_to_empty", - "expr": "'A' > ''", - "value": { - "boolValue": true - } - }, - { - "name": "not_gt_string_empty_to_empty", - "expr": "'' > ''", - "value": { - "boolValue": false - } - }, - { - "name": "gt_string_unicode", - "expr": "'α' > 'omega'", - "value": { - "boolValue": true - } - }, - { - "name": "gt_bytes_one", - "expr": "b'\u0001' > b'\u0000'", - "value": { - "boolValue": true - } - }, - { - "name": "gt_bytes_one_to_empty", - "expr": "b'\u0000' > b''", - "value": { - "boolValue": true - } - }, - { - "name": "not_gt_bytes_sorting", - "expr": "b'\u0000\u0001' > b'\u0001'", - "value": { - "boolValue": false - } - }, - { - "name": "gt_bool_true_false", - "expr": "true > false", - "value": { - "boolValue": true - } - }, - { - "name": "not_gt_bool_false_true", - "expr": "false > true", - "value": { - "boolValue": false - } - }, - { - "name": "not_gt_bool_same", - "expr": "true > true", - "value": { - "boolValue": false - } - }, - { - "name": "gt_null_unsupported", - "expr": "null > null", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "gt_list_unsupported", - "expr": "[1] > [0]", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "gt_map_unsupported", - "expr": "{1:'b'} > {0:'a'}", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "gt_mixed_types_error", - "expr": "'foo' > 1024", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "gt_dyn_int_uint", - "expr": "dyn(2) > 1u", - "value": { - "boolValue": true - } - }, - { - "name": "gt_dyn_int_double", - "expr": "dyn(2) > 1.0", - "value": { - "boolValue": true - } - }, - { - "name": "gt_dyn_uint_int", - "expr": "dyn(2u) > 1", - "value": { - "boolValue": true - } - }, - { - "name": "gt_dyn_uint_double", - "expr": "dyn(2u) > 1.0", - "value": { - "boolValue": true - } - }, - { - "name": "gt_dyn_double_int", - "expr": "dyn(2.0) > 1", - "value": { - "boolValue": true - } - }, - { - "name": "gt_dyn_double_uint", - "expr": "dyn(2.0) > 1u", - "value": { - "boolValue": true - } - }, - { - "name": "not_gt_dyn_int_uint", - "expr": "dyn(1) > 1u", - "value": { - "boolValue": false - } - }, - { - "name": "not_gt_dyn_int_double", - "expr": "dyn(1) > 1.0", - "value": { - "boolValue": false - } - }, - { - "name": "not_gt_dyn_uint_int", - "expr": "dyn(1u) > 1", - "value": { - "boolValue": false - } - }, - { - "name": "not_gt_dyn_uint_double", - "expr": "dyn(1u) > 1.0", - "value": { - "boolValue": false - } - }, - { - "name": "not_gt_dyn_double_int", - "expr": "dyn(1.0) > 1", - "value": { - "boolValue": false - } - }, - { - "name": "not_gt_dyn_double_uint", - "expr": "dyn(1.0) > 1u", - "value": { - "boolValue": false - } - }, - { - "name": "not_gt_dyn_int_big_uint", - "expr": "dyn(1) > 9223372036854775808u", - "value": { - "boolValue": false - } - }, - { - "name": "not_gt_dyn_small_int_uint", - "expr": "dyn(-1) > 0u", - "value": { - "boolValue": false - } - }, - { - "name": "not_gt_dyn_int_big_double", - "expr": "dyn(9223372036854775807) > 9223372036854775808.0", - "value": { - "boolValue": false - } - }, - { - "name": "not_gt_dyn_int_small_lossy_double", - "description": "The conversion of the int to double is lossy and the numbers end up being equal", - "expr": "dyn(-9223372036854775808) > -9223372036854775809.0", - "value": { - "boolValue": false - } - }, - { - "name": "gt_dyn_int_small_lossy_double_greater", - "expr": "dyn(-9223372036854775808) > -9223372036854777857.0", - "value": { - "boolValue": true - } - }, - { - "name": "gt_dyn_uint_small_int", - "expr": "dyn(1u) > -1", - "value": { - "boolValue": true - } - }, - { - "name": "gt_dyn_big_uint_int", - "expr": "dyn(9223372036854775808u) > 1", - "value": { - "boolValue": true - } - }, - { - "name": "gt_dyn_uint_small_double", - "expr": "dyn(9223372036854775807u) > -1.0", - "value": { - "boolValue": true - } - }, - { - "name": "not_gt_dyn_uint_big_double", - "expr": "dyn(18446744073709551615u) > 18446744073709590000.0", - "value": { - "boolValue": false - } - }, - { - "name": "gt_dyn_big_double_uint", - "expr": "dyn(18446744073709553665.0) > 18446744073709551615u", - "value": { - "boolValue": true - } - }, - { - "name": "not_gt_dyn_big_double_int", - "expr": "dyn(9223372036854775808.0) > 9223372036854775807", - "value": { - "boolValue": false - } - }, - { - "name": "not_gt_dyn_small_double_int", - "expr": "dyn(-9223372036854775809.0) > -9223372036854775808", - "value": { - "boolValue": false - } - } - ] - }, - { - "name": "lte_literal", - "description": "Literals comparison on _<=_", - "test": [ - { - "name": "lte_int_lt", - "expr": "0 <= 1", - "value": { - "boolValue": true - } - }, - { - "name": "lte_int_eq", - "expr": "1 <= 1", - "value": { - "boolValue": true - } - }, - { - "name": "not_lte_int_gt", - "expr": "1 <= -1", - "value": { - "boolValue": false - } - }, - { - "name": "lte_uint_lt", - "expr": "0u <= 1u", - "value": { - "boolValue": true - } - }, - { - "name": "lte_uint_eq", - "expr": "1u <= 1u", - "value": { - "boolValue": true - } - }, - { - "name": "not_lte_uint_gt", - "expr": "1u <= 0u", - "value": { - "boolValue": false - } - }, - { - "name": "lte_double_lt", - "expr": "0.0 <= 0.1e-31", - "value": { - "boolValue": true - } - }, - { - "name": "lte_double_eq", - "expr": "0.0 <= 0e-1", - "value": { - "boolValue": true - } - }, - { - "name": "not_lte_double_gt", - "expr": "1.0 <= 0.99", - "value": { - "boolValue": false - } - }, - { - "name": "lte_string_empty", - "expr": "'' <= ''", - "value": { - "boolValue": true - } - }, - { - "name": "lte_string_from_empty", - "expr": "'' <= 'a'", - "value": { - "boolValue": true - } - }, - { - "name": "not_lte_string_to_empty", - "expr": "'a' <= ''", - "value": { - "boolValue": false - } - }, - { - "name": "lte_string_lexicographical", - "expr": "'aBc' <= 'abc'", - "value": { - "boolValue": true - } - }, - { - "name": "lte_string_unicode_eq", - "expr": "'α' <= 'α'", - "value": { - "boolValue": true - } - }, - { - "name": "lte_string_unicode_lt", - "expr": "'a' <= 'α'", - "value": { - "boolValue": true - } - }, - { - "name": "not_lte_string_unicode", - "expr": "'α' <= 'a'", - "value": { - "boolValue": false - } - }, - { - "name": "lte_bytes_empty", - "expr": "b'' <= b'\u0000'", - "value": { - "boolValue": true - } - }, - { - "name": "not_lte_bytes_length", - "expr": "b'\u0001\u0000' <= b'\u0001'", - "value": { - "boolValue": false - } - }, - { - "name": "lte_bool_false_true", - "expr": "false <= true", - "value": { - "boolValue": true - } - }, - { - "name": "lte_bool_false_false", - "expr": "false <= false", - "value": { - "boolValue": true - } - }, - { - "name": "lte_bool_true_false", - "expr": "true <= false", - "value": { - "boolValue": false - } - }, - { - "name": "lte_null_unsupported", - "expr": "null <= null", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "lte_list_unsupported", - "expr": "[0] <= [0]", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "lte_map_unsupported", - "expr": "{0:'a'} <= {1:'b'}", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "lte_mixed_types_error", - "expr": "'foo' <= 1024", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "lte_dyn_int_uint", - "expr": "dyn(1) <= 2u", - "value": { - "boolValue": true - } - }, - { - "name": "lte_dyn_int_double", - "expr": "dyn(1) <= 2.0", - "value": { - "boolValue": true - } - }, - { - "name": "lte_dyn_uint_int", - "expr": "dyn(1u) <= 2", - "value": { - "boolValue": true - } - }, - { - "name": "lte_dyn_uint_double", - "expr": "dyn(1u) <= 2.0", - "value": { - "boolValue": true - } - }, - { - "name": "lte_dyn_double_int", - "expr": "dyn(1.0) <= 2", - "value": { - "boolValue": true - } - }, - { - "name": "lte_dyn_double_uint", - "expr": "dyn(1.0) <= 2u", - "value": { - "boolValue": true - } - }, - { - "name": "not_lte_dyn_int_uint", - "expr": "dyn(2) <= 1u", - "value": { - "boolValue": false - } - }, - { - "name": "not_lte_dyn_int_double", - "expr": "dyn(2) <= 1.0", - "value": { - "boolValue": false - } - }, - { - "name": "not_lte_dyn_uint_int", - "expr": "dyn(2u) <= 1", - "value": { - "boolValue": false - } - }, - { - "name": "not_lte_dyn_uint_double", - "expr": "dyn(2u) <= 1.0", - "value": { - "boolValue": false - } - }, - { - "name": "not_lte_dyn_double_int", - "expr": "dyn(2.0) <= 1", - "value": { - "boolValue": false - } - }, - { - "name": "not_lte_dyn_double_uint", - "expr": "dyn(2.0) <= 1u", - "value": { - "boolValue": false - } - }, - { - "name": "lte_dyn_int_big_uint", - "expr": "dyn(1) <= 9223372036854775808u", - "value": { - "boolValue": true - } - }, - { - "name": "lte_dyn_small_int_uint", - "expr": "dyn(-1) <= 0u", - "value": { - "boolValue": true - } - }, - { - "name": "lte_dyn_int_big_double", - "expr": "dyn(9223372036854775807) <= 9223372036854775808.0", - "value": { - "boolValue": true - } - }, - { - "name": "lte_dyn_int_small_lossy_double", - "description": "The conversion of the int to double is lossy and the numbers end up being equal", - "expr": "dyn(-9223372036854775808) <= -9223372036854775809.0", - "value": { - "boolValue": true - } - }, - { - "name": "not_lte_dyn_int_small_lossy_double_less", - "expr": "dyn(-9223372036854775808) <= -9223372036854777857.0", - "value": { - "boolValue": false - } - }, - { - "name": "not_lte_dyn_uint_small_int", - "expr": "dyn(1u) <= -9223372036854775808", - "value": { - "boolValue": false - } - }, - { - "name": "not_lte_dyn_big_uint_int", - "expr": "dyn(9223372036854775808u) <= 1", - "value": { - "boolValue": false - } - }, - { - "name": "not_lte_dyn_uint_small_double", - "expr": "dyn(18446744073709551615u) <= -1.0", - "value": { - "boolValue": false - } - }, - { - "name": "lte_dyn_uint_big_double", - "expr": "dyn(18446744073709551615u) <= 18446744073709590000.0", - "value": { - "boolValue": true - } - }, - { - "name": "not_lte_dyn_big_double_uint", - "expr": "dyn(18446744073709553665.0) <= 18446744073709551615u", - "value": { - "boolValue": false - } - }, - { - "name": "lte_dyn_big_double_int", - "expr": "dyn(9223372036854775808.0) <= 9223372036854775807", - "value": { - "boolValue": true - } - }, - { - "name": "lte_dyn_small_double_int", - "expr": "dyn(-9223372036854775809.0) <= -9223372036854775808", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "gte_literal", - "description": "Literals comparison on _>=_", - "test": [ - { - "name": "gte_int_gt", - "expr": "0 >= -1", - "value": { - "boolValue": true - } - }, - { - "name": "gte_int_eq", - "expr": "999 >= 999", - "value": { - "boolValue": true - } - }, - { - "name": "not_gte_int_lt", - "expr": "999 >= 1000", - "value": { - "boolValue": false - } - }, - { - "name": "gte_uint_gt", - "expr": "1u >= 0u", - "value": { - "boolValue": true - } - }, - { - "name": "gte_uint_eq", - "expr": "0u >= 0u", - "value": { - "boolValue": true - } - }, - { - "name": "not_gte_uint_lt", - "expr": "1u >= 10u", - "value": { - "boolValue": false - } - }, - { - "name": "gte_double_gt", - "expr": "1e+1 >= 1e+0", - "value": { - "boolValue": true - } - }, - { - "name": "gte_double_eq", - "expr": "9.80665 >= 9.80665e+0", - "value": { - "boolValue": true - } - }, - { - "name": "not_gte_double_lt", - "expr": "0.9999 >= 1.0", - "value": { - "boolValue": false - } - }, - { - "name": "gte_string_empty", - "expr": "'' >= ''", - "value": { - "boolValue": true - } - }, - { - "name": "gte_string_to_empty", - "expr": "'a' >= ''", - "value": { - "boolValue": true - } - }, - { - "name": "gte_string_empty_to_nonempty", - "expr": "'' >= 'a'", - "value": { - "boolValue": false - } - }, - { - "name": "gte_string_length", - "expr": "'abcd' >= 'abc'", - "value": { - "boolValue": true - } - }, - { - "name": "not_gte_string_lexicographical", - "expr": "'abc' >= 'abd'", - "value": { - "boolValue": false - } - }, - { - "name": "gte_string_unicode_eq", - "expr": "'τ' >= 'τ'", - "value": { - "boolValue": true - } - }, - { - "name": "gte_string_unicode_gt", - "expr": "'τ' >= 't'", - "value": { - "boolValue": true - } - }, - { - "name": "not_get_string_unicode", - "expr": "'t' >= 'τ'", - "value": { - "boolValue": false - } - }, - { - "name": "gte_bytes_to_empty", - "expr": "b'\u0000' >= b''", - "value": { - "boolValue": true - } - }, - { - "name": "not_gte_bytes_empty_to_nonempty", - "expr": "b'' >= b'\u0000'", - "value": { - "boolValue": false - } - }, - { - "name": "gte_bytes_samelength", - "expr": "b'\u0000\u0001' >= b'\u0001\u0000'", - "value": { - "boolValue": false - } - }, - { - "name": "gte_bool_gt", - "expr": "true >= false", - "value": { - "boolValue": true - } - }, - { - "name": "gte_bool_eq", - "expr": "true >= true", - "value": { - "boolValue": true - } - }, - { - "name": "not_gte_bool_lt", - "expr": "false >= true", - "value": { - "boolValue": false - } - }, - { - "name": "gte_null_unsupported", - "expr": "null >= null", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "gte_list_unsupported", - "expr": "['y'] >= ['x']", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "gte_map_unsupported", - "expr": "{1:'b'} >= {0:'a'}", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "gte_mixed_types_error", - "expr": "'foo' >= 1.0", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "gte_dyn_int_uint", - "expr": "dyn(2) >= 1u", - "value": { - "boolValue": true - } - }, - { - "name": "gte_dyn_int_double", - "expr": "dyn(2) >= 1.0", - "value": { - "boolValue": true - } - }, - { - "name": "gte_dyn_uint_int", - "expr": "dyn(2u) >= 1", - "value": { - "boolValue": true - } - }, - { - "name": "gte_dyn_uint_double", - "expr": "dyn(2u) >= 1.0", - "value": { - "boolValue": true - } - }, - { - "name": "gte_dyn_double_int", - "expr": "dyn(2.0) >= 1", - "value": { - "boolValue": true - } - }, - { - "name": "gte_dyn_double_uint", - "expr": "dyn(2.0) >= 1u", - "value": { - "boolValue": true - } - }, - { - "name": "not_gte_dyn_int_uint", - "expr": "dyn(0) >= 1u", - "value": { - "boolValue": false - } - }, - { - "name": "not_gte_dyn_int_double", - "expr": "dyn(0) >= 1.0", - "value": { - "boolValue": false - } - }, - { - "name": "not_gte_dyn_uint_int", - "expr": "dyn(0u) >= 1", - "value": { - "boolValue": false - } - }, - { - "name": "not_gte_dyn_uint_double", - "expr": "dyn(0u) >= 1.0", - "value": { - "boolValue": false - } - }, - { - "name": "not_gte_dyn_double_int", - "expr": "dyn(0.0) >= 1", - "value": { - "boolValue": false - } - }, - { - "name": "not_gte_dyn_double_uint", - "expr": "dyn(0.0) >= 1u", - "value": { - "boolValue": false - } - }, - { - "name": "not_gte_dyn_int_big_uint", - "expr": "dyn(1) >= 9223372036854775808u", - "value": { - "boolValue": false - } - }, - { - "name": "not_gte_dyn_small_int_uint", - "expr": "dyn(-1) >= 0u", - "value": { - "boolValue": false - } - }, - { - "name": "gte_dyn_int_big_lossy_double", - "expr": "dyn(9223372036854775807) >= 9223372036854775808.0", - "value": { - "boolValue": true - } - }, - { - "name": "not_gte_dyn_int_big_double", - "expr": "dyn(9223372036854775807) >= 9223372036854777857.0", - "value": { - "boolValue": false - } - }, - { - "name": "gte_dyn_int_small_lossy_double_equal", - "description": "The conversion of the int to double is lossy and the numbers end up being equal", - "expr": "dyn(-9223372036854775808) >= -9223372036854775809.0", - "value": { - "boolValue": true - } - }, - { - "name": "gte_dyn_int_small_lossy_double_greater", - "expr": "dyn(-9223372036854775808) >= -9223372036854777857.0", - "value": { - "boolValue": true - } - }, - { - "name": "gte_dyn_uint_small_int", - "expr": "dyn(1u) >= -1", - "value": { - "boolValue": true - } - }, - { - "name": "gte_dyn_big_uint_int", - "expr": "dyn(9223372036854775808u) >= 1", - "value": { - "boolValue": true - } - }, - { - "name": "gte_dyn_uint_small_double", - "expr": "dyn(9223372036854775807u) >= -1.0", - "value": { - "boolValue": true - } - }, - { - "name": "not_gte_dyn_uint_big_double", - "expr": "dyn(18446744073709551615u) >= 18446744073709553665.0", - "value": { - "boolValue": false - } - }, - { - "name": "gte_dyn_big_double_uint", - "expr": "dyn(18446744073709553665.0) >= 18446744073709551615u", - "value": { - "boolValue": true - } - }, - { - "name": "gte_dyn_big_double_int", - "expr": "dyn(9223372036854775808.0) >= 9223372036854775807", - "value": { - "boolValue": true - } - }, - { - "name": "gte_dyn_small_double_int", - "expr": "dyn(-9223372036854775809.0) >= -9223372036854775808", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "in_list_literal", - "description": "Set membership tests using list literals and the 'in' operator", - "test": [ - { - "name": "elem_not_in_empty_list", - "expr": "'empty' in []", - "value": { - "boolValue": false - } - }, - { - "name": "elem_in_list", - "expr": "'elem' in ['elem', 'elemA', 'elemB']", - "value": { - "boolValue": true - } - }, - { - "name": "elem_not_in_list", - "expr": "'not' in ['elem1', 'elem2', 'elem3']", - "value": { - "boolValue": false - } - }, - { - "name": "elem_in_mixed_type_list", - "description": "Set membership tests should succeed if the 'elem' exists in a mixed element type list.", - "expr": "'elem' in [1, 'elem', 2]", - "value": { - "boolValue": true - } - }, - { - "name": "elem_in_mixed_type_list_cross_type", - "description": "Set membership tests should return false due to the introduction of heterogeneous-equality. Set membership via 'in' is equivalent to the macro exists() behavior.", - "expr": "'elem' in [1u, 'str', 2, b'bytes']", - "value": { - "boolValue": false - } - } - ] - }, - { - "name": "in_map_literal", - "description": "Set membership tests using map literals and the 'in' operator", - "test": [ - { - "name": "key_not_in_empty_map", - "expr": "'empty' in {}", - "value": { - "boolValue": false - } - }, - { - "name": "key_in_map", - "expr": "'key' in {'key':'1', 'other':'2'}", - "value": { - "boolValue": true - } - }, - { - "name": "key_not_in_map", - "expr": "'key' in {'lock':1, 'gate':2}", - "value": { - "boolValue": false - } - }, - { - "name": "key_in_mixed_key_type_map", - "description": "Map keys are of mixed type, but since the key is present the result is true.", - "expr": "'key' in {3:3.0, 'key':2u}", - "value": { - "boolValue": true - } - }, - { - "name": "key_in_mixed_key_type_map_cross_type", - "expr": "'key' in {1u:'str', 2:b'bytes'}", - "value": { - "boolValue": false - } - } - ] - }, - { - "name": "bound", - "description": "Comparing bound variables with literals or other variables", - "test": [ - { - "name": "bytes_gt_left_false", - "expr": "x > b'\u0000'", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "primitive": "BYTES" - } - } - } - ], - "bindings": { - "x": { - "value": { - "bytesValue": "AA==" - } - } - }, - "value": { - "boolValue": false - } - }, - { - "name": "int_lte_right_true", - "expr": "123 <= x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "primitive": "INT64" - } - } - } - ], - "bindings": { - "x": { - "value": { - "int64Value": "124" - } - } - }, - "value": { - "boolValue": true - } - }, - { - "name": "bool_lt_right_true", - "expr": "false < x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "primitive": "BOOL" - } - } - } - ], - "bindings": { - "x": { - "value": { - "boolValue": true - } - } - }, - "value": { - "boolValue": true - } - }, - { - "name": "double_ne_left_false", - "expr": "x != 9.8", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "primitive": "DOUBLE" - } - } - } - ], - "bindings": { - "x": { - "value": { - "doubleValue": 9.8 - } - } - }, - "value": { - "boolValue": false - } - }, - { - "name": "map_ne_right_false", - "expr": "{'a':'b','c':'d'} != x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "mapType": { - "keyType": { - "primitive": "STRING" - }, - "valueType": { - "primitive": "STRING" - } - } - } - } - } - ], - "bindings": { - "x": { - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "c" - }, - "value": { - "stringValue": "d" - } - }, - { - "key": { - "stringValue": "a" - }, - "value": { - "stringValue": "b" - } - } - ] - } - } - } - }, - "value": { - "boolValue": false - } - }, - { - "name": "null_eq_left_true", - "description": "A comparison _==_ against null only binds if the type is determined to be null or we skip the type checking", - "expr": "x == null", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "null": null - } - } - } - ], - "bindings": { - "x": { - "value": { - "nullValue": null - } - } - }, - "value": { - "boolValue": true - } - }, - { - "name": "list_eq_right_false", - "expr": "[1, 2] == x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "listType": { - "elemType": { - "primitive": "INT64" - } - } - } - } - } - ], - "bindings": { - "x": { - "value": { - "listValue": { - "values": [ - { - "int64Value": "2" - }, - { - "int64Value": "1" - } - ] - } - } - } - }, - "value": { - "boolValue": false - } - }, - { - "name": "string_gte_right_true", - "expr": "'abcd' >= x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "primitive": "STRING" - } - } - } - ], - "bindings": { - "x": { - "value": { - "stringValue": "abc" - } - } - }, - "value": { - "boolValue": true - } - }, - { - "name": "uint_eq_right_false", - "expr": "999u == x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "primitive": "UINT64" - } - } - } - ], - "bindings": { - "x": { - "value": { - "uint64Value": "1000" - } - } - }, - "value": { - "boolValue": false - } - }, - { - "name": "null_lt_right_no_such_overload", - "description": "There is no _<_ operation for null, even if both operands are null", - "expr": "null < x", - "disableCheck": true, - "bindings": { - "x": { - "value": { - "nullValue": null - } - } - }, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/conversions.json b/packages/cel-spec/src/testdata/json/conversions.json deleted file mode 100644 index 2c6b7658..00000000 --- a/packages/cel-spec/src/testdata/json/conversions.json +++ /dev/null @@ -1,881 +0,0 @@ -{ - "name": "conversions", - "description": "Tests for type conversions.", - "section": [ - { - "name": "bytes", - "description": "Conversions to bytes.", - "test": [ - { - "name": "string_empty", - "expr": "bytes('')", - "value": { - "bytesValue": "" - } - }, - { - "name": "string", - "expr": "bytes('abc')", - "value": { - "bytesValue": "YWJj" - } - }, - { - "name": "string_unicode", - "expr": "bytes('ÿ')", - "value": { - "bytesValue": "w78=" - } - }, - { - "name": "string_unicode_vs_literal", - "expr": "bytes('\\377') == b'\\377'", - "value": { - "boolValue": false - } - } - ] - }, - { - "name": "double", - "description": "Conversions to double.", - "test": [ - { - "name": "int_zero", - "expr": "double(0)", - "value": { - "doubleValue": 0 - } - }, - { - "name": "int_pos", - "expr": "double(1000000000000)", - "value": { - "doubleValue": 1000000000000 - } - }, - { - "name": "int_neg", - "expr": "double(-1000000000000000)", - "value": { - "doubleValue": -1000000000000000 - } - }, - { - "name": "int_min_exact", - "description": "Smallest contiguous representable int (-2^53).", - "expr": "double(-9007199254740992)", - "value": { - "doubleValue": -9007199254740992 - } - }, - { - "name": "int_max_exact", - "description": "Largest contiguous representable int (2^53).", - "expr": "double(9007199254740992)", - "value": { - "doubleValue": 9007199254740992 - } - }, - { - "name": "int_range", - "description": "Largest signed 64-bit. Rounds to nearest double.", - "expr": "double(9223372036854775807)", - "value": { - "doubleValue": 9223372036854776000 - } - }, - { - "name": "uint_zero", - "expr": "double(0u)", - "value": { - "doubleValue": 0 - } - }, - { - "name": "uint_pos", - "expr": "double(123u)", - "value": { - "doubleValue": 123 - } - }, - { - "name": "uint_max_exact", - "description": "Largest contiguous representable int (2^53).", - "expr": "double(9007199254740992u)", - "value": { - "doubleValue": 9007199254740992 - } - }, - { - "name": "uint_range", - "description": "Largest unsigned 64-bit.", - "expr": "double(18446744073709551615u)", - "value": { - "doubleValue": 18446744073709552000 - } - }, - { - "name": "string_zero", - "expr": "double('0')", - "value": { - "doubleValue": 0 - } - }, - { - "name": "string_zero_dec", - "expr": "double('0.0')", - "value": { - "doubleValue": 0 - } - }, - { - "name": "string_neg_zero", - "expr": "double('-0.0')", - "value": { - "doubleValue": -0 - } - }, - { - "name": "string_no_dec", - "expr": "double('123')", - "value": { - "doubleValue": 123 - } - }, - { - "name": "string_pos", - "expr": "double('123.456')", - "value": { - "doubleValue": 123.456 - } - }, - { - "name": "string_neg", - "expr": "double('-987.654')", - "value": { - "doubleValue": -987.654 - } - }, - { - "name": "string_exp_pos_pos", - "expr": "double('6.02214e23')", - "value": { - "doubleValue": 6.02214e23 - } - }, - { - "name": "string_exp_pos_neg", - "expr": "double('1.38e-23')", - "value": { - "doubleValue": 1.38e-23 - } - }, - { - "name": "string_exp_neg_pos", - "expr": "double('-84.32e7')", - "value": { - "doubleValue": -843200000 - } - }, - { - "name": "string_exp_neg_neg", - "expr": "double('-5.43e-21')", - "value": { - "doubleValue": -5.43e-21 - } - } - ] - }, - { - "name": "dyn", - "description": "Tests for dyn annotation.", - "test": [ - { - "name": "dyn_heterogeneous_list", - "description": "No need to disable type checking.", - "expr": "type(dyn([1, 'one']))", - "value": { - "typeValue": "list" - } - } - ] - }, - { - "name": "int", - "description": "Conversions to int.", - "test": [ - { - "name": "uint", - "expr": "int(42u)", - "value": { - "int64Value": "42" - } - }, - { - "name": "uint_zero", - "expr": "int(0u)", - "value": { - "int64Value": "0" - } - }, - { - "name": "uint_max_exact", - "expr": "int(9223372036854775807u)", - "value": { - "int64Value": "9223372036854775807" - } - }, - { - "name": "uint_range", - "expr": "int(18446744073709551615u)", - "evalError": { - "errors": [ - { - "message": "range error" - } - ] - } - }, - { - "name": "double_round_neg", - "expr": "int(-123.456)", - "value": { - "int64Value": "-123" - } - }, - { - "name": "double_truncate", - "expr": "int(1.9)", - "value": { - "int64Value": "1" - } - }, - { - "name": "double_truncate_neg", - "expr": "int(-7.9)", - "value": { - "int64Value": "-7" - } - }, - { - "name": "double_half_pos", - "expr": "int(11.5)", - "value": { - "int64Value": "11" - } - }, - { - "name": "double_half_neg", - "expr": "int(-3.5)", - "value": { - "int64Value": "-3" - } - }, - { - "name": "double_big_exact", - "description": "Beyond exact range (2^53), but no loss of precision (2^55).", - "expr": "int(double(36028797018963968))", - "value": { - "int64Value": "36028797018963968" - } - }, - { - "name": "double_big_precision", - "description": "Beyond exact range (2^53), but loses precision (2^55 + 1).", - "expr": "int(double(36028797018963969))", - "value": { - "int64Value": "36028797018963968" - } - }, - { - "name": "double_int_max_range", - "description": "The double(2^63-1) cast produces a floating point value outside the int range", - "expr": "int(9223372036854775807.0)", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "double_int_min_range", - "description": "The double(-2^63) cast produces a floating point value outside the int range", - "expr": "int(-9223372036854775808.0)", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "double_range", - "expr": "int(1e99)", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "string", - "expr": "int('987')", - "value": { - "int64Value": "987" - } - }, - { - "name": "timestamp", - "expr": "int(timestamp('2004-09-16T23:59:59Z'))", - "value": { - "int64Value": "1095379199" - } - } - ] - }, - { - "name": "string", - "description": "Conversions to string.", - "test": [ - { - "name": "int", - "expr": "string(123)", - "value": { - "stringValue": "123" - } - }, - { - "name": "int_neg", - "expr": "string(-456)", - "value": { - "stringValue": "-456" - } - }, - { - "name": "uint", - "expr": "string(9876u)", - "value": { - "stringValue": "9876" - } - }, - { - "name": "double", - "expr": "string(123.456)", - "value": { - "stringValue": "123.456" - } - }, - { - "name": "double_hard", - "expr": "string(-4.5e-3)", - "value": { - "stringValue": "-0.0045" - } - }, - { - "name": "bytes", - "expr": "string(b'abc')", - "value": { - "stringValue": "abc" - } - }, - { - "name": "bytes_unicode", - "expr": "string(b'\\303\\277')", - "value": { - "stringValue": "ÿ" - } - }, - { - "name": "bytes_invalid", - "expr": "string(b'\\000\\xff')", - "evalError": { - "errors": [ - { - "message": "invalid UTF-8" - } - ] - } - } - ] - }, - { - "name": "type", - "description": "Type reflection tests.", - "test": [ - { - "name": "bool", - "expr": "type(true)", - "value": { - "typeValue": "bool" - } - }, - { - "name": "bool_denotation", - "expr": "bool", - "value": { - "typeValue": "bool" - } - }, - { - "name": "dyn_no_denotation", - "expr": "dyn", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "unknown variable" - } - ] - } - }, - { - "name": "int", - "expr": "type(0)", - "value": { - "typeValue": "int" - } - }, - { - "name": "int_denotation", - "expr": "int", - "value": { - "typeValue": "int" - } - }, - { - "name": "eq_same", - "expr": "type(true) == type(false)", - "value": { - "boolValue": true - } - }, - { - "name": "uint", - "expr": "type(64u)", - "value": { - "typeValue": "uint" - } - }, - { - "name": "uint_denotation", - "expr": "uint", - "value": { - "typeValue": "uint" - } - }, - { - "name": "double", - "expr": "type(3.14)", - "value": { - "typeValue": "double" - } - }, - { - "name": "double_denotation", - "expr": "double", - "value": { - "typeValue": "double" - } - }, - { - "name": "null_type", - "expr": "type(null)", - "value": { - "typeValue": "null_type" - } - }, - { - "name": "null_type_denotation", - "expr": "null_type", - "value": { - "typeValue": "null_type" - } - }, - { - "name": "string", - "expr": "type('foo')", - "value": { - "typeValue": "string" - } - }, - { - "name": "string_denotation", - "expr": "string", - "value": { - "typeValue": "string" - } - }, - { - "name": "bytes", - "expr": "type(b'\\xff')", - "value": { - "typeValue": "bytes" - } - }, - { - "name": "bytes_denotation", - "expr": "bytes", - "value": { - "typeValue": "bytes" - } - }, - { - "name": "list", - "expr": "type([1, 2, 3])", - "value": { - "typeValue": "list" - } - }, - { - "name": "list_denotation", - "expr": "list", - "value": { - "typeValue": "list" - } - }, - { - "name": "lists_monomorphic", - "expr": "type([1, 2, 3]) == type(['one', 'two', 'three'])", - "value": { - "boolValue": true - } - }, - { - "name": "map", - "expr": "type({4: 16})", - "value": { - "typeValue": "map" - } - }, - { - "name": "map_denotation", - "expr": "map", - "value": { - "typeValue": "map" - } - }, - { - "name": "map_monomorphic", - "expr": "type({'one': 1}) == type({1: 'one'})", - "value": { - "boolValue": true - } - }, - { - "name": "eq_diff", - "expr": "type(7) == type(7u)", - "value": { - "boolValue": false - } - }, - { - "name": "neq_same", - "expr": "type(0.0) != type(-0.0)", - "value": { - "boolValue": false - } - }, - { - "name": "neq_diff", - "expr": "type(0.0) != type(0)", - "value": { - "boolValue": true - } - }, - { - "name": "meta", - "expr": "type(type(7)) == type(type(7u))", - "value": { - "boolValue": true - } - }, - { - "name": "type", - "expr": "type(int)", - "value": { - "typeValue": "type" - } - }, - { - "name": "type_denotation", - "expr": "type", - "value": { - "typeValue": "type" - } - }, - { - "name": "type_type", - "expr": "type(type)", - "value": { - "typeValue": "type" - } - } - ] - }, - { - "name": "uint", - "description": "Conversions to uint.", - "test": [ - { - "name": "int", - "expr": "uint(1729)", - "value": { - "uint64Value": "1729" - } - }, - { - "name": "int_max", - "expr": "uint(9223372036854775807)", - "value": { - "uint64Value": "9223372036854775807" - } - }, - { - "name": "int_neg", - "expr": "uint(-1)", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "double", - "expr": "uint(3.14159265)", - "value": { - "uint64Value": "3" - } - }, - { - "name": "double_truncate", - "expr": "uint(1.9)", - "value": { - "uint64Value": "1" - } - }, - { - "name": "double_half", - "expr": "uint(25.5)", - "value": { - "uint64Value": "25" - } - }, - { - "name": "double_big_exact", - "description": "Beyond exact range (2^53), but no loss of precision (2^55).", - "expr": "uint(double(36028797018963968u))", - "value": { - "uint64Value": "36028797018963968" - } - }, - { - "name": "double_big_precision", - "description": "Beyond exact range (2^53), but loses precision (2^55 + 1).", - "expr": "uint(double(36028797018963969u))", - "value": { - "uint64Value": "36028797018963968" - } - }, - { - "name": "double_uint_max_range", - "description": "The exact conversion of uint max as a double does not round trip.", - "expr": "int(18446744073709551615.0)", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "double_range_beyond_uint", - "expr": "uint(6.022e23)", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "string", - "expr": "uint('300')", - "value": { - "uint64Value": "300" - } - } - ] - }, - { - "name": "bool", - "description": "Conversions to bool", - "test": [ - { - "name": "string_1", - "expr": "bool('1')", - "value": { - "boolValue": true - } - }, - { - "name": "string_t", - "expr": "bool('t')", - "value": { - "boolValue": true - } - }, - { - "name": "string_true_lowercase", - "expr": "bool('true')", - "value": { - "boolValue": true - } - }, - { - "name": "string_true_uppercase", - "expr": "bool('TRUE')", - "value": { - "boolValue": true - } - }, - { - "name": "string_true_pascalcase", - "expr": "bool('True')", - "value": { - "boolValue": true - } - }, - { - "name": "string_0", - "expr": "bool('0')", - "value": { - "boolValue": false - } - }, - { - "name": "string_f", - "expr": "bool('f')", - "value": { - "boolValue": false - } - }, - { - "name": "string_false_lowercase", - "expr": "bool('false')", - "value": { - "boolValue": false - } - }, - { - "name": "string_false_uppercase", - "expr": "bool('FALSE')", - "value": { - "boolValue": false - } - }, - { - "name": "string_false_pascalcase", - "expr": "bool('False')", - "value": { - "boolValue": false - } - }, - { - "name": "string_true_badcase", - "expr": "bool('TrUe')", - "evalError": { - "errors": [ - { - "message": "Type conversion error" - } - ] - } - }, - { - "name": "string_false_badcase", - "expr": "bool('FaLsE')", - "evalError": { - "errors": [ - { - "message": "Type conversion error" - } - ] - } - } - ] - }, - { - "name": "identity", - "description": "Identity functions", - "test": [ - { - "name": "bool", - "expr": "bool(true)", - "value": { - "boolValue": true - } - }, - { - "name": "int", - "expr": "int(1)", - "value": { - "int64Value": "1" - } - }, - { - "name": "uint", - "expr": "uint(1u)", - "value": { - "uint64Value": "1" - } - }, - { - "name": "double", - "expr": "double(5.5)", - "value": { - "doubleValue": 5.5 - } - }, - { - "name": "string", - "expr": "string('hello')", - "value": { - "stringValue": "hello" - } - }, - { - "name": "bytes", - "expr": "bytes(b'abc')", - "value": { - "bytesValue": "YWJj" - } - }, - { - "name": "duration", - "expr": "duration(duration('100s')) == duration('100s')", - "value": { - "boolValue": true - } - }, - { - "name": "timestamp", - "expr": "timestamp(timestamp(1000000000)) == timestamp(1000000000)", - "value": { - "boolValue": true - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/dynamic.json b/packages/cel-spec/src/testdata/json/dynamic.json deleted file mode 100644 index 898b130e..00000000 --- a/packages/cel-spec/src/testdata/json/dynamic.json +++ /dev/null @@ -1,2854 +0,0 @@ -{ - "name": "dynamic", - "description": "Tests for 'dynamic' proto behavior, including JSON, wrapper, and Any messages.", - "section": [ - { - "name": "int32", - "description": "Tests for int32 conversion.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.Int32Value{value: -123}", - "value": { - "int64Value": "-123" - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.Int32Value{value: -123}.value", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_zero", - "expr": "google.protobuf.Int32Value{}", - "value": { - "int64Value": "0" - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.Int32Value" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.Int32Value", - "value": 2000000 - } - } - } - }, - "value": { - "int64Value": "2000000" - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_int32_wrapper: 432}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt32Wrapper": 432 - } - } - }, - { - "name": "field_assign_proto2_zero", - "expr": "TestAllTypes{single_int32_wrapper: 0}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt32Wrapper": 0 - } - } - }, - { - "name": "field_assign_proto2_max", - "expr": "TestAllTypes{single_int32_wrapper: 2147483647}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt32Wrapper": 2147483647 - } - } - }, - { - "name": "field_assign_proto2_min", - "expr": "TestAllTypes{single_int32_wrapper: -2147483648}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt32Wrapper": -2147483648 - } - } - }, - { - "name": "field_assign_proto2_range", - "expr": "TestAllTypes{single_int32_wrapper: 12345678900}", - "container": "cel.expr.conformance.proto2", - "evalError": { - "errors": [ - { - "message": "range error" - } - ] - } - }, - { - "name": "field_read_proto2", - "expr": "TestAllTypes{single_int32_wrapper: 642}.single_int32_wrapper", - "container": "cel.expr.conformance.proto2", - "value": { - "int64Value": "642" - } - }, - { - "name": "field_read_proto2_zero", - "expr": "TestAllTypes{single_int32_wrapper: 0}.single_int32_wrapper", - "container": "cel.expr.conformance.proto2", - "value": { - "int64Value": "0" - } - }, - { - "name": "field_read_proto2_unset", - "expr": "TestAllTypes{}.single_int32_wrapper", - "container": "cel.expr.conformance.proto2", - "value": { - "nullValue": null - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_int32_wrapper: -975}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32Wrapper": -975 - } - } - }, - { - "name": "field_assign_proto3_zero", - "expr": "TestAllTypes{single_int32_wrapper: 0}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32Wrapper": 0 - } - } - }, - { - "name": "field_assign_proto3_max", - "expr": "TestAllTypes{single_int32_wrapper: 2147483647}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32Wrapper": 2147483647 - } - } - }, - { - "name": "field_assign_proto3_min", - "expr": "TestAllTypes{single_int32_wrapper: -2147483648}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32Wrapper": -2147483648 - } - } - }, - { - "name": "field_assign_proto3_range", - "expr": "TestAllTypes{single_int32_wrapper: -998877665544332211}", - "container": "cel.expr.conformance.proto3", - "evalError": { - "errors": [ - { - "message": "range error" - } - ] - } - }, - { - "name": "field_read_proto3", - "expr": "TestAllTypes{single_int32_wrapper: 642}.single_int32_wrapper", - "container": "cel.expr.conformance.proto3", - "value": { - "int64Value": "642" - } - }, - { - "name": "field_read_proto3_zero", - "expr": "TestAllTypes{single_int32_wrapper: 0}.single_int32_wrapper", - "container": "cel.expr.conformance.proto3", - "value": { - "int64Value": "0" - } - }, - { - "name": "field_read_proto3_unset", - "expr": "TestAllTypes{}.single_int32_wrapper", - "container": "cel.expr.conformance.proto3", - "value": { - "nullValue": null - } - } - ] - }, - { - "name": "int64", - "description": "Tests for int64 conversion.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.Int64Value{value: -123}", - "value": { - "int64Value": "-123" - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.Int64Value{value: -123}.value", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_zero", - "expr": "google.protobuf.Int64Value{}", - "value": { - "int64Value": "0" - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.Int64Value" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.Int64Value", - "value": "2000000" - } - } - } - }, - "value": { - "int64Value": "2000000" - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_int64_wrapper: 432}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt64Wrapper": "432" - } - } - }, - { - "name": "field_assign_proto2_zero", - "expr": "TestAllTypes{single_int64_wrapper: 0}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt64Wrapper": "0" - } - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_int64_wrapper: -975}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt64Wrapper": "-975" - } - } - }, - { - "name": "field_assign_proto3_zero", - "expr": "TestAllTypes{single_int64_wrapper: 0}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt64Wrapper": "0" - } - } - } - ] - }, - { - "name": "uint32", - "description": "Tests for uint32 conversion.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.UInt32Value{value: 123u}", - "value": { - "uint64Value": "123" - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.UInt32Value{value: 123u}.value", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_zero", - "expr": "google.protobuf.UInt32Value{}", - "value": { - "uint64Value": "0" - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.UInt32Value" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.UInt32Value", - "value": 2000000 - } - } - } - }, - "value": { - "uint64Value": "2000000" - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_uint32_wrapper: 432u}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleUint32Wrapper": 432 - } - } - }, - { - "name": "field_assign_proto2_zero", - "expr": "TestAllTypes{single_uint32_wrapper: 0u}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleUint32Wrapper": 0 - } - } - }, - { - "name": "field_assign_proto2_max", - "expr": "TestAllTypes{single_uint32_wrapper: 4294967295u}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleUint32Wrapper": 4294967295 - } - } - }, - { - "name": "field_assign_proto2_range", - "expr": "TestAllTypes{single_uint32_wrapper: 6111222333u}", - "container": "cel.expr.conformance.proto2", - "evalError": { - "errors": [ - { - "message": "range error" - } - ] - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_uint32_wrapper: 975u}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleUint32Wrapper": 975 - } - } - }, - { - "name": "field_assign_proto3_zero", - "expr": "TestAllTypes{single_uint32_wrapper: 0u}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleUint32Wrapper": 0 - } - } - }, - { - "name": "field_assign_proto3_max", - "expr": "TestAllTypes{single_uint32_wrapper: 4294967295u}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleUint32Wrapper": 4294967295 - } - } - }, - { - "name": "field_assign_proto3_range", - "expr": "TestAllTypes{single_uint32_wrapper: 6111222333u}", - "container": "cel.expr.conformance.proto3", - "evalError": { - "errors": [ - { - "message": "range error" - } - ] - } - }, - { - "name": "field_read_proto2", - "expr": "TestAllTypes{single_uint32_wrapper: 258u}.single_uint32_wrapper", - "container": "cel.expr.conformance.proto2", - "value": { - "uint64Value": "258" - } - }, - { - "name": "field_read_proto2_zero", - "expr": "TestAllTypes{single_uint32_wrapper: 0u}.single_uint32_wrapper", - "container": "cel.expr.conformance.proto2", - "value": { - "uint64Value": "0" - } - }, - { - "name": "field_read_proto2_unset", - "expr": "TestAllTypes{}.single_uint32_wrapper", - "container": "cel.expr.conformance.proto2", - "value": { - "nullValue": null - } - } - ] - }, - { - "name": "uint64", - "description": "Tests for uint64 conversion.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.UInt64Value{value: 123u}", - "value": { - "uint64Value": "123" - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.UInt64Value{value: 123u}.value", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_zero", - "expr": "google.protobuf.UInt64Value{}", - "value": { - "uint64Value": "0" - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.UInt64Value" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.UInt64Value", - "value": "2000000" - } - } - } - }, - "value": { - "uint64Value": "2000000" - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_uint64_wrapper: 432u}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleUint64Wrapper": "432" - } - } - }, - { - "name": "field_assign_proto2_zero", - "expr": "TestAllTypes{single_uint64_wrapper: 0u}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleUint64Wrapper": "0" - } - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_uint64_wrapper: 975u}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleUint64Wrapper": "975" - } - } - }, - { - "name": "field_assign_proto3_zero", - "expr": "TestAllTypes{single_uint64_wrapper: 0u}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleUint64Wrapper": "0" - } - } - }, - { - "name": "field_read_proto2", - "expr": "TestAllTypes{single_uint64_wrapper: 5123123123u}.single_uint64_wrapper", - "container": "cel.expr.conformance.proto2", - "value": { - "uint64Value": "5123123123" - } - }, - { - "name": "field_read_proto2_zero", - "expr": "TestAllTypes{single_uint64_wrapper: 0u}.single_uint64_wrapper", - "container": "cel.expr.conformance.proto2", - "value": { - "uint64Value": "0" - } - }, - { - "name": "field_read_proto2_unset", - "expr": "TestAllTypes{}.single_uint64_wrapper", - "container": "cel.expr.conformance.proto2", - "value": { - "nullValue": null - } - } - ] - }, - { - "name": "float", - "description": "Tests for float conversion.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.FloatValue{value: -1.5e3}", - "value": { - "doubleValue": -1500 - } - }, - { - "name": "literal_not_double", - "description": "Use a number with no exact representation to make sure we actually narrow to a float.", - "expr": "google.protobuf.FloatValue{value: 1.333} == 1.333", - "value": { - "boolValue": false - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.FloatValue{value: 3.1416}.value", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_zero", - "expr": "google.protobuf.FloatValue{}", - "value": { - "doubleValue": 0 - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.FloatValue" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.FloatValue", - "value": -1250000 - } - } - } - }, - "value": { - "doubleValue": -1250000 - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_float_wrapper: 86.75}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleFloatWrapper": 86.75 - } - } - }, - { - "name": "field_assign_proto2_zero", - "expr": "TestAllTypes{single_float_wrapper: 0.0}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleFloatWrapper": 0 - } - } - }, - { - "name": "field_assign_proto2_subnorm", - "description": "Subnormal single floats range from ~1e-38 to ~1e-45.", - "expr": "TestAllTypes{single_float_wrapper: 1e-40}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleFloatWrapper": 1e-40 - } - } - }, - { - "name": "field_assign_proto2_round_to_zero", - "description": "Subnormal single floats range from ~1e-38 to ~1e-45.", - "expr": "TestAllTypes{single_float_wrapper: 1e-50}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleFloatWrapper": 0 - } - } - }, - { - "name": "field_assign_proto2_range", - "description": "Single float max is about 3.4e38", - "expr": "TestAllTypes{single_float_wrapper: 1.4e55}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleFloatWrapper": "Infinity" - } - } - }, - { - "name": "field_read_proto2", - "expr": "TestAllTypes{single_float_wrapper: -12.375}.single_float_wrapper", - "container": "cel.expr.conformance.proto2", - "value": { - "doubleValue": -12.375 - } - }, - { - "name": "field_read_proto2_zero", - "expr": "TestAllTypes{single_float_wrapper: 0.0}.single_float_wrapper", - "container": "cel.expr.conformance.proto2", - "value": { - "doubleValue": 0 - } - }, - { - "name": "field_read_proto2_unset", - "expr": "TestAllTypes{}.single_float_wrapper", - "container": "cel.expr.conformance.proto2", - "value": { - "nullValue": null - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_float_wrapper: -9.75}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleFloatWrapper": -9.75 - } - } - }, - { - "name": "field_assign_proto3_zero", - "expr": "TestAllTypes{single_float_wrapper: 0.0}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleFloatWrapper": 0 - } - } - }, - { - "name": "field_assign_proto2_subnorm", - "description": "Subnormal single floats range from ~1e-38 to ~1e-45.", - "expr": "TestAllTypes{single_float_wrapper: 1e-40}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleFloatWrapper": 1e-40 - } - } - }, - { - "name": "field_assign_proto3_round_to_zero", - "expr": "TestAllTypes{single_float_wrapper: -9.9e-100}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleFloatWrapper": -0 - } - } - }, - { - "name": "field_assign_proto3_range", - "description": "Single float min is about -3.4e38", - "expr": "TestAllTypes{single_float_wrapper: -9.9e100}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleFloatWrapper": "-Infinity" - } - } - }, - { - "name": "field_read_proto3", - "expr": "TestAllTypes{single_float_wrapper: 64.25}.single_float_wrapper", - "container": "cel.expr.conformance.proto3", - "value": { - "doubleValue": 64.25 - } - }, - { - "name": "field_read_proto3_zero", - "expr": "TestAllTypes{single_float_wrapper: 0.0}.single_float_wrapper", - "container": "cel.expr.conformance.proto3", - "value": { - "doubleValue": 0 - } - }, - { - "name": "field_read_proto3_unset", - "expr": "TestAllTypes{}.single_float_wrapper", - "container": "cel.expr.conformance.proto3", - "value": { - "nullValue": null - } - } - ] - }, - { - "name": "double", - "description": "Tests for double conversion.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.DoubleValue{value: -1.5e3}", - "value": { - "doubleValue": -1500 - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.DoubleValue{value: 3.1416}.value", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_zero", - "expr": "google.protobuf.DoubleValue{}", - "value": { - "doubleValue": 0 - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.DoubleValue" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.DoubleValue", - "value": -1250000 - } - } - } - }, - "value": { - "doubleValue": -1250000 - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_double_wrapper: 86.75}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleDoubleWrapper": 86.75 - } - } - }, - { - "name": "field_assign_proto2_zero", - "expr": "TestAllTypes{single_double_wrapper: 0.0}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleDoubleWrapper": 0 - } - } - }, - { - "name": "field_assign_proto2_range", - "expr": "TestAllTypes{single_double_wrapper: 1.4e55}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleDoubleWrapper": 1.4e55 - } - } - }, - { - "name": "field_read_proto2", - "expr": "TestAllTypes{single_double_wrapper: -12.375}.single_double_wrapper", - "container": "cel.expr.conformance.proto2", - "value": { - "doubleValue": -12.375 - } - }, - { - "name": "field_read_proto2_zero", - "expr": "TestAllTypes{single_int32_wrapper: 0}.single_int32_wrapper", - "container": "cel.expr.conformance.proto2", - "value": { - "int64Value": "0" - } - }, - { - "name": "field_read_proto2_unset", - "expr": "TestAllTypes{}.single_double_wrapper", - "container": "cel.expr.conformance.proto2", - "value": { - "nullValue": null - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_double_wrapper: -9.75}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleDoubleWrapper": -9.75 - } - } - }, - { - "name": "field_assign_proto3_zero", - "expr": "TestAllTypes{single_double_wrapper: 0.0}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleDoubleWrapper": 0 - } - } - }, - { - "name": "field_assign_proto3_range", - "expr": "TestAllTypes{single_double_wrapper: -9.9e100}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleDoubleWrapper": -9.9e100 - } - } - }, - { - "name": "field_read_proto3", - "expr": "TestAllTypes{single_double_wrapper: 64.25}.single_double_wrapper", - "container": "cel.expr.conformance.proto3", - "value": { - "doubleValue": 64.25 - } - }, - { - "name": "field_read_proto3_zero", - "expr": "TestAllTypes{single_double_wrapper: 0.0}.single_double_wrapper", - "container": "cel.expr.conformance.proto3", - "value": { - "doubleValue": 0 - } - }, - { - "name": "field_read_proto3_unset", - "expr": "TestAllTypes{}.single_double_wrapper", - "container": "cel.expr.conformance.proto3", - "value": { - "nullValue": null - } - } - ] - }, - { - "name": "bool", - "description": "Tests for bool conversion.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.BoolValue{value: true}", - "value": { - "boolValue": true - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.BoolValue{value: true}.value", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_empty", - "expr": "google.protobuf.BoolValue{}", - "value": { - "boolValue": false - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.BoolValue" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.BoolValue", - "value": true - } - } - } - }, - "value": { - "boolValue": true - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_bool_wrapper: true}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleBoolWrapper": true - } - } - }, - { - "name": "field_assign_proto2_false", - "expr": "TestAllTypes{single_bool_wrapper: false}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleBoolWrapper": false - } - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_bool_wrapper: true}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleBoolWrapper": true - } - } - }, - { - "name": "field_assign_proto3_false", - "expr": "TestAllTypes{single_bool_wrapper: false}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleBoolWrapper": false - } - } - } - ] - }, - { - "name": "string", - "description": "Tests for string conversion.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.StringValue{value: 'foo'}", - "value": { - "stringValue": "foo" - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.StringValue{value: 'foo'}.value", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_empty", - "expr": "google.protobuf.StringValue{}", - "value": { - "stringValue": "" - } - }, - { - "name": "literal_unicode", - "expr": "google.protobuf.StringValue{value: 'flambé'}", - "value": { - "stringValue": "flambé" - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.StringValue" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.StringValue", - "value": "bar" - } - } - } - }, - "value": { - "stringValue": "bar" - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_string_wrapper: 'baz'}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleStringWrapper": "baz" - } - } - }, - { - "name": "field_assign_proto2_empty", - "expr": "TestAllTypes{single_string_wrapper: ''}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleStringWrapper": "" - } - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_string_wrapper: 'bletch'}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleStringWrapper": "bletch" - } - } - }, - { - "name": "field_assign_proto3_empty", - "expr": "TestAllTypes{single_string_wrapper: ''}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleStringWrapper": "" - } - } - } - ] - }, - { - "name": "bytes", - "description": "Tests for bytes conversion.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.BytesValue{value: b'foo\\123'}", - "value": { - "bytesValue": "Zm9vUw==" - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.BytesValue{value: b'foo'}.value", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_empty", - "expr": "google.protobuf.BytesValue{}", - "value": { - "bytesValue": "" - } - }, - { - "name": "literal_unicode", - "expr": "google.protobuf.BytesValue{value: b'flambé'}", - "value": { - "bytesValue": "ZmxhbWLDqQ==" - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.BytesValue" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.BytesValue", - "value": "YmFy" - } - } - } - }, - "value": { - "bytesValue": "YmFy" - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_bytes_wrapper: b'baz'}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleBytesWrapper": "YmF6" - } - } - }, - { - "name": "field_assign_proto2_empty", - "expr": "TestAllTypes{single_bytes_wrapper: b''}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleBytesWrapper": "" - } - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_bytes_wrapper: b'bletch'}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleBytesWrapper": "YmxldGNo" - } - } - }, - { - "name": "field_assign_proto3_empty", - "expr": "TestAllTypes{single_bytes_wrapper: b''}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleBytesWrapper": "" - } - } - } - ] - }, - { - "name": "list", - "description": "Tests for list conversion.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.ListValue{values: [3.0, 'foo', null]}", - "value": { - "listValue": { - "values": [ - { - "doubleValue": 3 - }, - { - "stringValue": "foo" - }, - { - "nullValue": null - } - ] - } - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.ListValue{values: [3.0, 'foo', null]}.values", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_empty", - "expr": "google.protobuf.ListValue{values: []}", - "value": { - "listValue": {} - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.ListValue" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.ListValue", - "value": ["bar", ["a", "b"]] - } - } - } - }, - "value": { - "listValue": { - "values": [ - { - "stringValue": "bar" - }, - { - "listValue": { - "values": [ - { - "stringValue": "a" - }, - { - "stringValue": "b" - } - ] - } - } - ] - } - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{list_value: [1.0, 'one']}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "listValue": [1, "one"] - } - } - }, - { - "name": "field_assign_proto2_empty", - "expr": "TestAllTypes{list_value: []}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "listValue": [] - } - } - }, - { - "name": "field_read_proto2", - "expr": "TestAllTypes{list_value: [1.0, 'one']}.list_value", - "container": "cel.expr.conformance.proto2", - "value": { - "listValue": { - "values": [ - { - "doubleValue": 1 - }, - { - "stringValue": "one" - } - ] - } - } - }, - { - "name": "field_read_proto2_empty", - "expr": "TestAllTypes{list_value: []}.list_value", - "container": "cel.expr.conformance.proto2", - "value": { - "listValue": {} - } - }, - { - "name": "field_read_proto2_unset", - "description": "Not a wrapper type, so doesn't convert to null.", - "expr": "TestAllTypes{}.list_value", - "container": "cel.expr.conformance.proto2", - "value": { - "listValue": {} - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{list_value: [1.0, 'one']}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "listValue": [1, "one"] - } - } - }, - { - "name": "field_assign_proto3_empty", - "expr": "TestAllTypes{list_value: []}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "listValue": [] - } - } - }, - { - "name": "field_read_proto3", - "expr": "TestAllTypes{list_value: [1.0, 'one']}.list_value", - "container": "cel.expr.conformance.proto3", - "value": { - "listValue": { - "values": [ - { - "doubleValue": 1 - }, - { - "stringValue": "one" - } - ] - } - } - }, - { - "name": "field_read_proto3_empty", - "expr": "TestAllTypes{list_value: []}.list_value", - "container": "cel.expr.conformance.proto3", - "value": { - "listValue": {} - } - }, - { - "name": "field_read_proto3_unset", - "description": "Not a wrapper type, so doesn't convert to null.", - "expr": "TestAllTypes{}.list_value", - "container": "cel.expr.conformance.proto3", - "value": { - "listValue": {} - } - } - ] - }, - { - "name": "struct", - "description": "Tests for struct conversion.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.Struct{fields: {'uno': 1.0, 'dos': 2.0}}", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "uno" - }, - "value": { - "doubleValue": 1 - } - }, - { - "key": { - "stringValue": "dos" - }, - "value": { - "doubleValue": 2 - } - } - ] - } - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.Struct{fields: {'uno': 1.0, 'dos': 2.0}}.fields", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_empty", - "expr": "google.protobuf.Struct{fields: {}}", - "value": { - "mapValue": {} - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.Struct" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.Struct", - "value": { - "first": "Abraham", - "last": "Lincoln" - } - } - } - } - }, - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "first" - }, - "value": { - "stringValue": "Abraham" - } - }, - { - "key": { - "stringValue": "last" - }, - "value": { - "stringValue": "Lincoln" - } - } - ] - } - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_struct: {'un': 1.0, 'deux': 2.0}}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleStruct": { - "deux": 2, - "un": 1 - } - } - } - }, - { - "name": "field_assign_proto2_empty", - "expr": "TestAllTypes{single_struct: {}}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleStruct": {} - } - } - }, - { - "name": "field_assign_proto2_bad", - "expr": "TestAllTypes{single_struct: {1: 'uno'}}", - "disableCheck": true, - "container": "cel.expr.conformance.proto2", - "evalError": { - "errors": [ - { - "message": "bad key type" - } - ] - } - }, - { - "name": "field_read_proto2", - "expr": "TestAllTypes{single_struct: {'one': 1.0}}.single_struct", - "container": "cel.expr.conformance.proto2", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "one" - }, - "value": { - "doubleValue": 1 - } - } - ] - } - } - }, - { - "name": "field_read_proto2_empty", - "expr": "TestAllTypes{single_struct: {}}.single_struct", - "container": "cel.expr.conformance.proto2", - "value": { - "mapValue": {} - } - }, - { - "name": "field_read_proto2_unset", - "description": "Not a wrapper type, so doesn't convert to null.", - "expr": "TestAllTypes{}.single_struct", - "container": "cel.expr.conformance.proto2", - "value": { - "mapValue": {} - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_struct: {'un': 1.0, 'deux': 2.0}}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleStruct": { - "deux": 2, - "un": 1 - } - } - } - }, - { - "name": "field_assign_proto3_empty", - "expr": "TestAllTypes{single_struct: {}}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleStruct": {} - } - } - }, - { - "name": "field_assign_proto3_bad", - "expr": "TestAllTypes{single_struct: {1: 'uno'}}", - "disableCheck": true, - "container": "cel.expr.conformance.proto3", - "evalError": { - "errors": [ - { - "message": "bad key type" - } - ] - } - }, - { - "name": "field_read_proto3", - "expr": "TestAllTypes{single_struct: {'one': 1.0}}.single_struct", - "container": "cel.expr.conformance.proto3", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "one" - }, - "value": { - "doubleValue": 1 - } - } - ] - } - } - }, - { - "name": "field_read_proto3_empty", - "expr": "TestAllTypes{single_struct: {}}.single_struct", - "container": "cel.expr.conformance.proto3", - "value": { - "mapValue": {} - } - }, - { - "name": "field_read_proto3_unset", - "description": "Not a wrapper type, so doesn't convert to null.", - "expr": "TestAllTypes{}.single_struct", - "container": "cel.expr.conformance.proto3", - "value": { - "mapValue": {} - } - } - ] - }, - { - "name": "value_null", - "description": "Tests for null conversions.", - "test": [ - { - "name": "literal", - "expr": "Value{null_value: NullValue.NULL_VALUE}", - "container": "google.protobuf", - "value": { - "nullValue": null - } - }, - { - "name": "literal_no_field_access", - "expr": "Value{null_value: NullValue.NULL_VALUE}.null_value", - "disableCheck": true, - "container": "google.protobuf", - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_unset", - "expr": "google.protobuf.Value{}", - "value": { - "nullValue": null - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.Value" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.Value", - "value": null - } - } - } - }, - "value": { - "nullValue": null - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_value: null}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleValue": null - } - } - }, - { - "name": "field_read_proto2", - "expr": "TestAllTypes{single_value: null}.single_value", - "container": "cel.expr.conformance.proto2", - "value": { - "nullValue": null - } - }, - { - "name": "field_read_proto2_unset", - "expr": "TestAllTypes{}.single_value", - "container": "cel.expr.conformance.proto2", - "value": { - "nullValue": null - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_value: null}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleValue": null - } - } - }, - { - "name": "field_read_proto3", - "expr": "TestAllTypes{single_value: null}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "nullValue": null - } - }, - { - "name": "field_read_proto3_unset", - "expr": "TestAllTypes{}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "nullValue": null - } - } - ] - }, - { - "name": "value_number", - "description": "Tests for number conversions in Value.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.Value{number_value: 12.5}", - "value": { - "doubleValue": 12.5 - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.Value{number_value: 12.5}.number_value", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_zero", - "expr": "google.protobuf.Value{number_value: 0.0}", - "value": { - "doubleValue": 0 - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.Value" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.Value", - "value": -26.375 - } - } - } - }, - "value": { - "doubleValue": -26.375 - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_value: 7e23}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleValue": 7e23 - } - } - }, - { - "name": "field_assign_proto2_zero", - "expr": "TestAllTypes{single_value: 0.0}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleValue": 0 - } - } - }, - { - "name": "field_read_proto2", - "expr": "TestAllTypes{single_value: 7e23}.single_value", - "container": "cel.expr.conformance.proto2", - "value": { - "doubleValue": 7e23 - } - }, - { - "name": "field_read_proto2_zero", - "expr": "TestAllTypes{single_value: 0.0}.single_value", - "container": "cel.expr.conformance.proto2", - "value": { - "doubleValue": 0 - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_value: 7e23}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleValue": 7e23 - } - } - }, - { - "name": "field_assign_proto3_zero", - "expr": "TestAllTypes{single_value: 0.0}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleValue": 0 - } - } - }, - { - "name": "field_read_proto3", - "expr": "TestAllTypes{single_value: 7e23}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "doubleValue": 7e23 - } - }, - { - "name": "field_read_proto3_zero", - "expr": "TestAllTypes{single_value: 0.0}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "doubleValue": 0 - } - } - ] - }, - { - "name": "value_string", - "description": "Tests for string conversions in Value.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.Value{string_value: 'foo'}", - "value": { - "stringValue": "foo" - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.Value{string_value: 'foo'}.string_value", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_empty", - "expr": "google.protobuf.Value{string_value: ''}", - "value": { - "stringValue": "" - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.Value" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.Value", - "value": "bar" - } - } - } - }, - "value": { - "stringValue": "bar" - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_value: 'baz'}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleValue": "baz" - } - } - }, - { - "name": "field_assign_proto2_empty", - "expr": "TestAllTypes{single_value: ''}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleValue": "" - } - } - }, - { - "name": "field_read_proto2", - "expr": "TestAllTypes{single_value: 'bletch'}.single_value", - "container": "cel.expr.conformance.proto2", - "value": { - "stringValue": "bletch" - } - }, - { - "name": "field_read_proto2_zero", - "expr": "TestAllTypes{single_value: ''}.single_value", - "container": "cel.expr.conformance.proto2", - "value": { - "stringValue": "" - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_value: 'baz'}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleValue": "baz" - } - } - }, - { - "name": "field_assign_proto3_empty", - "expr": "TestAllTypes{single_value: ''}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleValue": "" - } - } - }, - { - "name": "field_read_proto3", - "expr": "TestAllTypes{single_value: 'bletch'}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "stringValue": "bletch" - } - }, - { - "name": "field_read_proto3_zero", - "expr": "TestAllTypes{single_value: ''}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "stringValue": "" - } - } - ] - }, - { - "name": "value_bool", - "description": "Tests for boolean conversions in Value.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.Value{bool_value: true}", - "value": { - "boolValue": true - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.Value{bool_value: true}.bool_value", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_false", - "expr": "google.protobuf.Value{bool_value: false}", - "value": { - "boolValue": false - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.Value" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.Value", - "value": true - } - } - } - }, - "value": { - "boolValue": true - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_value: true}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleValue": true - } - } - }, - { - "name": "field_assign_proto2_false", - "expr": "TestAllTypes{single_value: false}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleValue": false - } - } - }, - { - "name": "field_read_proto2", - "expr": "TestAllTypes{single_value: true}.single_value", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "field_read_proto2_false", - "expr": "TestAllTypes{single_value: false}.single_value", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_value: true}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleValue": true - } - } - }, - { - "name": "field_assign_proto3_false", - "expr": "TestAllTypes{single_value: false}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleValue": false - } - } - }, - { - "name": "field_read_proto3", - "expr": "TestAllTypes{single_value: true}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "field_read_proto3_false", - "expr": "TestAllTypes{single_value: false}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - } - ] - }, - { - "name": "value_struct", - "description": "Tests for struct conversions in Value.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.Value{struct_value: {'a': 1.0, 'b': 'two'}}", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "a" - }, - "value": { - "doubleValue": 1 - } - }, - { - "key": { - "stringValue": "b" - }, - "value": { - "stringValue": "two" - } - } - ] - } - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.Value{struct_value: {'a': 1.0, 'b': 'two'}}.struct_value", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_empty", - "expr": "google.protobuf.Value{struct_value: {}}", - "value": { - "mapValue": {} - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.Value" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.Value", - "value": { - "x": null, - "y": false - } - } - } - } - }, - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "x" - }, - "value": { - "nullValue": null - } - }, - { - "key": { - "stringValue": "y" - }, - "value": { - "boolValue": false - } - } - ] - } - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_value: {'un': 1.0, 'deux': 2.0}}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleValue": { - "deux": 2, - "un": 1 - } - } - } - }, - { - "name": "field_assign_proto2_empty", - "expr": "TestAllTypes{single_value: {}}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleValue": {} - } - } - }, - { - "name": "field_read_proto2", - "expr": "TestAllTypes{single_value: {'i': true}}.single_value", - "container": "cel.expr.conformance.proto2", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "i" - }, - "value": { - "boolValue": true - } - } - ] - } - } - }, - { - "name": "field_read_proto2_empty", - "expr": "TestAllTypes{single_value: {}}.single_value", - "container": "cel.expr.conformance.proto2", - "value": { - "mapValue": {} - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_value: {'un': 1.0, 'deux': 2.0}}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleValue": { - "deux": 2, - "un": 1 - } - } - } - }, - { - "name": "field_assign_proto3_empty", - "expr": "TestAllTypes{single_value: {}}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleValue": {} - } - } - }, - { - "name": "field_read_proto3", - "expr": "TestAllTypes{single_value: {'i': true}}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "i" - }, - "value": { - "boolValue": true - } - } - ] - } - } - }, - { - "name": "field_read_proto3_empty", - "expr": "TestAllTypes{single_value: {}}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "mapValue": {} - } - } - ] - }, - { - "name": "value_list", - "description": "Tests for list conversions in Value.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.Value{list_value: ['a', 3.0]}", - "value": { - "listValue": { - "values": [ - { - "stringValue": "a" - }, - { - "doubleValue": 3 - } - ] - } - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.Value{list_value: []}.list_value", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_empty", - "expr": "google.protobuf.Value{list_value: []}", - "value": { - "listValue": {} - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.Value" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.Value", - "value": [1, true, "hi"] - } - } - } - }, - "value": { - "listValue": { - "values": [ - { - "doubleValue": 1 - }, - { - "boolValue": true - }, - { - "stringValue": "hi" - } - ] - } - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_value: ['un', 1.0]}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleValue": ["un", 1] - } - } - }, - { - "name": "field_assign_proto2_empty", - "expr": "TestAllTypes{single_value: []}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleValue": [] - } - } - }, - { - "name": "field_read_proto2", - "expr": "TestAllTypes{single_value: ['i', true]}.single_value", - "container": "cel.expr.conformance.proto2", - "value": { - "listValue": { - "values": [ - { - "stringValue": "i" - }, - { - "boolValue": true - } - ] - } - } - }, - { - "name": "field_read_proto2_empty", - "expr": "TestAllTypes{single_value: []}.single_value", - "container": "cel.expr.conformance.proto2", - "value": { - "listValue": {} - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_value: ['un', 1.0]}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleValue": ["un", 1] - } - } - }, - { - "name": "field_assign_proto3_empty", - "expr": "TestAllTypes{single_value: []}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleValue": [] - } - } - }, - { - "name": "field_read_proto3", - "expr": "TestAllTypes{single_value: ['i', true]}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "listValue": { - "values": [ - { - "stringValue": "i" - }, - { - "boolValue": true - } - ] - } - } - }, - { - "name": "field_read_proto3_empty", - "expr": "TestAllTypes{single_value: []}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "listValue": {} - } - } - ] - }, - { - "name": "any", - "description": "Tests for Any conversion.", - "test": [ - { - "name": "literal", - "expr": "google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\x08\\x96\\x01'}", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt32": 150 - } - } - }, - { - "name": "literal_no_field_access", - "expr": "google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\x08\\x96\\x01'}.type_url", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_matching_overload" - } - ] - } - }, - { - "name": "literal_empty", - "expr": "google.protobuf.Any{}", - "evalError": { - "errors": [ - { - "message": "conversion" - } - ] - } - }, - { - "name": "var", - "expr": "x", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.Any" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.Any", - "value": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt32": 150 - } - } - } - } - }, - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt32": 150 - } - } - }, - { - "name": "field_assign_proto2", - "expr": "TestAllTypes{single_any: TestAllTypes{single_int32: 150}}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleAny": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt32": 150 - } - } - } - }, - { - "name": "field_read_proto2", - "expr": "TestAllTypes{single_any: TestAllTypes{single_int32: 150}}.single_any", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt32": 150 - } - } - }, - { - "name": "field_assign_proto3", - "expr": "TestAllTypes{single_any: TestAllTypes{single_int32: 150}}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleAny": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32": 150 - } - } - } - }, - { - "name": "field_read_proto3", - "expr": "TestAllTypes{single_any: TestAllTypes{single_int32: 150}}.single_any", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32": 150 - } - } - } - ] - }, - { - "name": "complex", - "description": "Tests combining various dynamic conversions.", - "test": [ - { - "name": "any_list_map", - "expr": "TestAllTypes{single_any: [{'almost': 'done'}]}.single_any", - "container": "cel.expr.conformance.proto3", - "value": { - "listValue": { - "values": [ - { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "almost" - }, - "value": { - "stringValue": "done" - } - } - ] - } - } - ] - } - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/encoders_ext.json b/packages/cel-spec/src/testdata/json/encoders_ext.json deleted file mode 100644 index 934a43da..00000000 --- a/packages/cel-spec/src/testdata/json/encoders_ext.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "name": "encoders_ext", - "description": "Tests for the encoders extension library.", - "section": [ - { - "name": "encode", - "test": [ - { - "name": "hello", - "expr": "base64.encode(b'hello')", - "value": { - "stringValue": "aGVsbG8=" - } - } - ] - }, - { - "name": "decode", - "test": [ - { - "name": "hello", - "expr": "base64.decode('aGVsbG8=')", - "value": { - "bytesValue": "aGVsbG8=" - } - }, - { - "name": "hello_without_padding", - "expr": "base64.decode('aGVsbG8')", - "value": { - "bytesValue": "aGVsbG8=" - } - } - ] - }, - { - "name": "round_trip", - "test": [ - { - "name": "hello", - "expr": "base64.decode(base64.encode(b'Hello World!'))", - "value": { - "bytesValue": "SGVsbG8gV29ybGQh" - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/enums.json b/packages/cel-spec/src/testdata/json/enums.json deleted file mode 100644 index 78834ced..00000000 --- a/packages/cel-spec/src/testdata/json/enums.json +++ /dev/null @@ -1,1006 +0,0 @@ -{ - "name": "enums", - "description": "Tests for enum types.", - "section": [ - { - "name": "legacy_proto2", - "description": "Legacy semantics where all enums are ints, proto2.", - "test": [ - { - "name": "literal_global", - "expr": "GlobalEnum.GAZ", - "container": "cel.expr.conformance.proto2", - "value": { - "int64Value": "2" - } - }, - { - "name": "literal_nested", - "expr": "TestAllTypes.NestedEnum.BAR", - "container": "cel.expr.conformance.proto2", - "value": { - "int64Value": "1" - } - }, - { - "name": "literal_zero", - "expr": "GlobalEnum.GOO", - "container": "cel.expr.conformance.proto2", - "value": { - "int64Value": "0" - } - }, - { - "name": "comparison", - "expr": "GlobalEnum.GAR == 1", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "arithmetic", - "expr": "TestAllTypes.NestedEnum.BAR + 3", - "container": "cel.expr.conformance.proto2", - "value": { - "int64Value": "4" - } - }, - { - "name": "type_global", - "expr": "type(GlobalEnum.GOO)", - "container": "cel.expr.conformance.proto2", - "value": { - "typeValue": "int" - } - }, - { - "name": "type_nested", - "expr": "type(TestAllTypes.NestedEnum.BAZ)", - "container": "cel.expr.conformance.proto2", - "value": { - "typeValue": "int" - } - }, - { - "name": "select_default", - "expr": "TestAllTypes{}.standalone_enum", - "container": "cel.expr.conformance.proto2", - "value": { - "int64Value": "0" - } - }, - { - "name": "field_type", - "expr": "type(TestAllTypes{}.standalone_enum)", - "container": "cel.expr.conformance.proto2", - "value": { - "typeValue": "int" - } - }, - { - "name": "assign_standalone_name", - "expr": "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.BAZ}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "standaloneEnum": "BAZ" - } - } - }, - { - "name": "assign_standalone_int", - "expr": "TestAllTypes{standalone_enum: 1}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "standaloneEnum": "BAR" - } - } - }, - { - "name": "assign_standalone_int_too_big", - "expr": "TestAllTypes{standalone_enum: 5000000000}", - "container": "cel.expr.conformance.proto2", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "assign_standalone_int_too_neg", - "expr": "TestAllTypes{standalone_enum: -7000000000}", - "container": "cel.expr.conformance.proto2", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "access_repeated_enum", - "expr": "TestAllTypes{}.repeated_nested_enum", - "container": "cel.expr.conformance.proto2", - "value": { - "listValue": {} - } - }, - { - "name": "assign_repeated_enum", - "expr": "TestAllTypes{ repeated_nested_enum: [ TestAllTypes.NestedEnum.FOO, TestAllTypes.NestedEnum.BAR]}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "repeatedNestedEnum": ["FOO", "BAR"] - } - } - }, - { - "name": "list_enum_as_list_int", - "expr": "0 in TestAllTypes{ repeated_nested_enum: [ TestAllTypes.NestedEnum.FOO, TestAllTypes.NestedEnum.BAR]}.repeated_nested_enum", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "enum_as_int", - "expr": "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.FOO}.standalone_enum in [0]", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "legacy_proto3", - "description": "Legacy semantics where all enums are ints, proto3", - "test": [ - { - "name": "literal_global", - "expr": "GlobalEnum.GAZ", - "container": "cel.expr.conformance.proto3", - "value": { - "int64Value": "2" - } - }, - { - "name": "literal_nested", - "expr": "TestAllTypes.NestedEnum.BAR", - "container": "cel.expr.conformance.proto3", - "value": { - "int64Value": "1" - } - }, - { - "name": "literal_zero", - "expr": "GlobalEnum.GOO", - "container": "cel.expr.conformance.proto3", - "value": { - "int64Value": "0" - } - }, - { - "name": "comparison", - "expr": "GlobalEnum.GAR == 1", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "arithmetic", - "expr": "TestAllTypes.NestedEnum.BAR + 3", - "container": "cel.expr.conformance.proto3", - "value": { - "int64Value": "4" - } - }, - { - "name": "type_global", - "expr": "type(GlobalEnum.GOO)", - "container": "cel.expr.conformance.proto3", - "value": { - "typeValue": "int" - } - }, - { - "name": "type_nested", - "expr": "type(TestAllTypes.NestedEnum.BAZ)", - "container": "cel.expr.conformance.proto3", - "value": { - "typeValue": "int" - } - }, - { - "name": "select_default", - "expr": "TestAllTypes{}.standalone_enum", - "container": "cel.expr.conformance.proto3", - "value": { - "int64Value": "0" - } - }, - { - "name": "select", - "expr": "x.standalone_enum", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "container": "cel.expr.conformance.proto3", - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "standaloneEnum": "BAZ" - } - } - } - }, - "value": { - "int64Value": "2" - } - }, - { - "name": "select_big", - "expr": "x.standalone_enum", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "container": "cel.expr.conformance.proto3", - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "standaloneEnum": 108 - } - } - } - }, - "value": { - "int64Value": "108" - } - }, - { - "name": "select_neg", - "expr": "x.standalone_enum", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "container": "cel.expr.conformance.proto3", - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "standaloneEnum": -3 - } - } - } - }, - "value": { - "int64Value": "-3" - } - }, - { - "name": "field_type", - "expr": "type(TestAllTypes{}.standalone_enum)", - "container": "cel.expr.conformance.proto3", - "value": { - "typeValue": "int" - } - }, - { - "name": "assign_standalone_name", - "expr": "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.BAZ}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "standaloneEnum": "BAZ" - } - } - }, - { - "name": "assign_standalone_int", - "expr": "TestAllTypes{standalone_enum: 1}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "standaloneEnum": "BAR" - } - } - }, - { - "name": "assign_standalone_int_big", - "expr": "TestAllTypes{standalone_enum: 99}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "standaloneEnum": 99 - } - } - }, - { - "name": "assign_standalone_int_neg", - "expr": "TestAllTypes{standalone_enum: -1}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "standaloneEnum": -1 - } - } - }, - { - "name": "assign_standalone_int_too_big", - "expr": "TestAllTypes{standalone_enum: 5000000000}", - "container": "cel.expr.conformance.proto3", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "assign_standalone_int_too_neg", - "expr": "TestAllTypes{standalone_enum: -7000000000}", - "container": "cel.expr.conformance.proto3", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "access_repeated_enum", - "expr": "TestAllTypes{}.repeated_nested_enum", - "container": "cel.expr.conformance.proto2", - "value": { - "listValue": {} - } - }, - { - "name": "assign_repeated_enum", - "expr": "TestAllTypes{ repeated_nested_enum: [ TestAllTypes.NestedEnum.FOO, TestAllTypes.NestedEnum.BAR]}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "repeatedNestedEnum": ["FOO", "BAR"] - } - } - }, - { - "name": "list_enum_as_list_int", - "expr": "0 in TestAllTypes{ repeated_nested_enum: [ TestAllTypes.NestedEnum.FOO, TestAllTypes.NestedEnum.BAR]}.repeated_nested_enum", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "enum_as_int", - "expr": "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.FOO}.standalone_enum in [0]", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "strong_proto2", - "description": "String semantics where enums are distinct types, proto2.", - "test": [ - { - "name": "literal_global", - "expr": "GlobalEnum.GAZ", - "container": "cel.expr.conformance.proto2", - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto2.GlobalEnum", - "value": 2 - } - } - }, - { - "name": "literal_nested", - "expr": "TestAllTypes.NestedEnum.BAR", - "container": "cel.expr.conformance.proto2", - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto2.TestAllTypes.NestedEnum", - "value": 1 - } - } - }, - { - "name": "literal_zero", - "expr": "GlobalEnum.GOO", - "container": "cel.expr.conformance.proto2", - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto2.GlobalEnum" - } - } - }, - { - "name": "comparison_true", - "expr": "GlobalEnum.GAR == GlobalEnum.GAR", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "comparison_false", - "expr": "GlobalEnum.GAR == GlobalEnum.GAZ", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "type_global", - "expr": "type(GlobalEnum.GOO)", - "container": "cel.expr.conformance.proto2", - "value": { - "typeValue": "cel.expr.conformance.proto2.GlobalEnum" - } - }, - { - "name": "type_nested", - "expr": "type(TestAllTypes.NestedEnum.BAZ)", - "container": "cel.expr.conformance.proto2", - "value": { - "typeValue": "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" - } - }, - { - "name": "select_default", - "expr": "TestAllTypes{}.standalone_enum", - "container": "cel.expr.conformance.proto2", - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" - } - } - }, - { - "name": "field_type", - "expr": "type(TestAllTypes{}.standalone_enum)", - "container": "cel.expr.conformance.proto2", - "value": { - "typeValue": "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" - } - }, - { - "name": "assign_standalone_name", - "expr": "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.BAZ}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "standaloneEnum": "BAZ" - } - } - }, - { - "name": "assign_standalone_int", - "expr": "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum(1)}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "standaloneEnum": "BAR" - } - } - }, - { - "name": "convert_symbol_to_int", - "expr": "int(GlobalEnum.GAZ)", - "container": "cel.expr.conformance.proto2", - "value": { - "int64Value": "2" - } - }, - { - "name": "convert_unnamed_to_int", - "description": "Disable check - missing way to declare enums.", - "expr": "int(x)", - "disableCheck": true, - "bindings": { - "x": { - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto2.GlobalEnum", - "value": 444 - } - } - } - }, - "value": { - "int64Value": "444" - } - }, - { - "name": "convert_int_inrange", - "expr": "TestAllTypes.NestedEnum(2)", - "container": "cel.expr.conformance.proto2", - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto2.TestAllTypes.NestedEnum", - "value": 2 - } - } - }, - { - "name": "convert_int_big", - "expr": "TestAllTypes.NestedEnum(20000)", - "container": "cel.expr.conformance.proto2", - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto2.TestAllTypes.NestedEnum", - "value": 20000 - } - } - }, - { - "name": "convert_int_neg", - "expr": "GlobalEnum(-33)", - "container": "cel.expr.conformance.proto2", - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto2.GlobalEnum", - "value": -33 - } - } - }, - { - "name": "convert_int_too_big", - "expr": "TestAllTypes.NestedEnum(5000000000)", - "container": "cel.expr.conformance.proto2", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "convert_int_too_neg", - "expr": "TestAllTypes.NestedEnum(-7000000000)", - "container": "cel.expr.conformance.proto2", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "convert_string", - "expr": "TestAllTypes.NestedEnum('BAZ')", - "container": "cel.expr.conformance.proto2", - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto2.TestAllTypes.NestedEnum", - "value": 2 - } - } - }, - { - "name": "convert_string_bad", - "expr": "TestAllTypes.NestedEnum('BLETCH')", - "container": "cel.expr.conformance.proto2", - "evalError": { - "errors": [ - { - "message": "invalid" - } - ] - } - } - ] - }, - { - "name": "strong_proto3", - "description": "String semantics where enums are distinct types, proto3.", - "test": [ - { - "name": "literal_global", - "expr": "GlobalEnum.GAZ", - "container": "cel.expr.conformance.proto3", - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto3.GlobalEnum", - "value": 2 - } - } - }, - { - "name": "literal_nested", - "expr": "TestAllTypes.NestedEnum.BAR", - "container": "cel.expr.conformance.proto3", - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto3.TestAllTypes.NestedEnum", - "value": 1 - } - } - }, - { - "name": "literal_zero", - "expr": "GlobalEnum.GOO", - "container": "cel.expr.conformance.proto3", - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto3.GlobalEnum" - } - } - }, - { - "name": "comparison_true", - "expr": "GlobalEnum.GAR == GlobalEnum.GAR", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "comparison_false", - "expr": "GlobalEnum.GAR == GlobalEnum.GAZ", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "type_global", - "expr": "type(GlobalEnum.GOO)", - "container": "cel.expr.conformance.proto3", - "value": { - "typeValue": "cel.expr.conformance.proto3.GlobalEnum" - } - }, - { - "name": "type_nested", - "expr": "type(TestAllTypes.NestedEnum.BAZ)", - "container": "cel.expr.conformance.proto3", - "value": { - "typeValue": "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" - } - }, - { - "name": "select_default", - "expr": "TestAllTypes{}.standalone_enum", - "container": "cel.expr.conformance.proto3", - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" - } - } - }, - { - "name": "select", - "expr": "x.standalone_enum", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "container": "cel.expr.conformance.proto3", - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "standaloneEnum": "BAZ" - } - } - } - }, - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto3.TestAllTypes.NestedEnum", - "value": 2 - } - } - }, - { - "name": "select_big", - "expr": "x.standalone_enum", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "container": "cel.expr.conformance.proto3", - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "standaloneEnum": 108 - } - } - } - }, - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto3.TestAllTypes.NestedEnum", - "value": 108 - } - } - }, - { - "name": "select_neg", - "expr": "x.standalone_enum", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "container": "cel.expr.conformance.proto3", - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "standaloneEnum": -3 - } - } - } - }, - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto3.TestAllTypes.NestedEnum", - "value": -3 - } - } - }, - { - "name": "field_type", - "expr": "type(TestAllTypes{}.standalone_enum)", - "container": "cel.expr.conformance.proto3", - "value": { - "typeValue": "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" - } - }, - { - "name": "assign_standalone_name", - "expr": "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.BAZ}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "standaloneEnum": "BAZ" - } - } - }, - { - "name": "assign_standalone_int", - "expr": "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum(1)}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "standaloneEnum": "BAR" - } - } - }, - { - "name": "assign_standalone_int_big", - "expr": "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum(99)}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "standaloneEnum": 99 - } - } - }, - { - "name": "assign_standalone_int_neg", - "expr": "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum(-1)}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "standaloneEnum": -1 - } - } - }, - { - "name": "convert_symbol_to_int", - "expr": "int(GlobalEnum.GAZ)", - "container": "cel.expr.conformance.proto3", - "value": { - "int64Value": "2" - } - }, - { - "name": "convert_unnamed_to_int", - "description": "Disable check - missing way to declare enums.", - "expr": "int(x)", - "disableCheck": true, - "bindings": { - "x": { - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto3.GlobalEnum", - "value": 444 - } - } - } - }, - "value": { - "int64Value": "444" - } - }, - { - "name": "convert_unnamed_to_int_select", - "expr": "int(x.standalone_enum)", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "standaloneEnum": -987 - } - } - } - }, - "value": { - "int64Value": "-987" - } - }, - { - "name": "convert_int_inrange", - "expr": "TestAllTypes.NestedEnum(2)", - "container": "cel.expr.conformance.proto3", - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto3.TestAllTypes.NestedEnum", - "value": 2 - } - } - }, - { - "name": "convert_int_big", - "expr": "TestAllTypes.NestedEnum(20000)", - "container": "cel.expr.conformance.proto3", - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto3.TestAllTypes.NestedEnum", - "value": 20000 - } - } - }, - { - "name": "convert_int_neg", - "expr": "GlobalEnum(-33)", - "container": "cel.expr.conformance.proto3", - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto3.GlobalEnum", - "value": -33 - } - } - }, - { - "name": "convert_int_too_big", - "expr": "TestAllTypes.NestedEnum(5000000000)", - "container": "cel.expr.conformance.proto3", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "convert_int_too_neg", - "expr": "TestAllTypes.NestedEnum(-7000000000)", - "container": "cel.expr.conformance.proto3", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "convert_string", - "expr": "TestAllTypes.NestedEnum('BAZ')", - "container": "cel.expr.conformance.proto3", - "value": { - "enumValue": { - "type": "cel.expr.conformance.proto3.TestAllTypes.NestedEnum", - "value": 2 - } - } - }, - { - "name": "convert_string_bad", - "expr": "TestAllTypes.NestedEnum('BLETCH')", - "container": "cel.expr.conformance.proto3", - "evalError": { - "errors": [ - { - "message": "invalid" - } - ] - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/fields.json b/packages/cel-spec/src/testdata/json/fields.json deleted file mode 100644 index 91d66d4e..00000000 --- a/packages/cel-spec/src/testdata/json/fields.json +++ /dev/null @@ -1,961 +0,0 @@ -{ - "name": "fields", - "description": "Tests for field access in maps.", - "section": [ - { - "name": "map_fields", - "description": "select an element in a map", - "test": [ - { - "name": "map_key_int64", - "expr": "{0:1,2:2,5:true}[5]", - "value": { - "boolValue": true - } - }, - { - "name": "map_key_uint64", - "expr": "{0u:1u,2u:'happy',5u:3u}[2u]", - "value": { - "stringValue": "happy" - } - }, - { - "name": "map_key_string", - "expr": "{'name':100u}['name']", - "value": { - "uint64Value": "100" - } - }, - { - "name": "map_key_bool", - "expr": "{true:5}[true]", - "value": { - "int64Value": "5" - } - }, - { - "name": "map_key_mixed_type", - "expr": "{true:1,2:2,5u:3}[true]", - "value": { - "int64Value": "1" - } - }, - { - "name": "map_key_mixed_numbers_double_key", - "expr": "{1u: 1.0, 2: 2.0, 3u: 3.0}[3.0]", - "value": { - "doubleValue": 3 - } - }, - { - "name": "map_key_mixed_numbers_lossy_double_key", - "expr": "{1u: 1.0, 2: 2.0, 3u: 3.0}[3.1]", - "evalError": { - "errors": [ - { - "message": "no such key" - } - ] - } - }, - { - "name": "map_key_mixed_numbers_uint_key", - "expr": "{1u: 1.0, 2: 2.0, 3u: 3.0}[2u]", - "value": { - "doubleValue": 2 - } - }, - { - "name": "map_key_mixed_numbers_int_key", - "expr": "{1u: 1.0, 2: 2.0, 3u: 3.0}[1]", - "value": { - "doubleValue": 1 - } - }, - { - "name": "map_field_access", - "expr": "x.name", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "mapType": { - "keyType": { - "primitive": "STRING" - }, - "valueType": { - "primitive": "INT64" - } - } - } - } - } - ], - "bindings": { - "x": { - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "name" - }, - "value": { - "int64Value": "1024" - } - } - ] - } - } - } - }, - "value": { - "int64Value": "1024" - } - }, - { - "name": "map_no_such_key", - "expr": "{0:1,2:2,5:3}[1]", - "evalError": { - "errors": [ - { - "message": "no such key" - } - ] - } - }, - { - "name": "map_no_such_key_or_false", - "expr": "dyn({0:1,2:2,5:3}[1]) || false", - "evalError": { - "errors": [ - { - "message": "no such key" - } - ] - } - }, - { - "name": "map_no_such_key_or_true", - "expr": "dyn({0:1,2:2,5:3}[1]) || true", - "value": { - "boolValue": true - } - }, - { - "name": "map_no_such_key_and_false", - "expr": "dyn({0:1,2:2,5:3}[1]) && false", - "value": { - "boolValue": false - } - }, - { - "name": "map_no_such_key_and_true", - "expr": "dyn({0:1,2:2,5:3}[1]) && true", - "evalError": { - "errors": [ - { - "message": "no such key" - } - ] - } - }, - { - "name": "map_bad_key_type", - "expr": "{0:1,2:2,5:3}[dyn(b'')]", - "evalError": { - "errors": [ - { - "message": "no such key" - } - ] - } - }, - { - "name": "map_bad_key_type_or_false", - "expr": "dyn({0:1,2:2,5:3}[dyn(b'')]) || false", - "evalError": { - "errors": [ - { - "message": "no such key" - } - ] - } - }, - { - "name": "map_bad_key_type_or_true", - "expr": "dyn({0:1,2:2,5:3}[dyn(b'')]) || true", - "value": { - "boolValue": true - } - }, - { - "name": "map_bad_key_type_and_false", - "expr": "dyn({0:1,2:2,5:3}[dyn(b'')]) && false", - "value": { - "boolValue": false - } - }, - { - "name": "map_bad_key_type_and_true", - "expr": "dyn({0:1,2:2,5:3}[dyn(b'')]) && true", - "evalError": { - "errors": [ - { - "message": "no such key" - } - ] - } - }, - { - "name": "map_field_select_no_such_key", - "expr": "x.name", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "mapType": { - "keyType": { - "primitive": "STRING" - }, - "valueType": { - "primitive": "STRING" - } - } - } - } - } - ], - "bindings": { - "x": { - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "holiday" - }, - "value": { - "stringValue": "field" - } - } - ] - } - } - } - }, - "evalError": { - "errors": [ - { - "message": "no such key: 'name'" - } - ] - } - }, - { - "name": "map_field_select_no_such_key_or_false", - "expr": "dyn(x.name) || false", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "mapType": { - "keyType": { - "primitive": "STRING" - }, - "valueType": { - "primitive": "STRING" - } - } - } - } - } - ], - "bindings": { - "x": { - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "holiday" - }, - "value": { - "stringValue": "field" - } - } - ] - } - } - } - }, - "evalError": { - "errors": [ - { - "message": "no such key: 'name'" - } - ] - } - }, - { - "name": "map_field_select_no_such_key_or_true", - "expr": "dyn(x.name) || true", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "mapType": { - "keyType": { - "primitive": "STRING" - }, - "valueType": { - "primitive": "STRING" - } - } - } - } - } - ], - "bindings": { - "x": { - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "holiday" - }, - "value": { - "stringValue": "field" - } - } - ] - } - } - } - }, - "value": { - "boolValue": true - } - }, - { - "name": "map_field_select_no_such_key_and_false", - "expr": "dyn(x.name) && false", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "mapType": { - "keyType": { - "primitive": "STRING" - }, - "valueType": { - "primitive": "STRING" - } - } - } - } - } - ], - "bindings": { - "x": { - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "holiday" - }, - "value": { - "stringValue": "field" - } - } - ] - } - } - } - }, - "value": { - "boolValue": false - } - }, - { - "name": "map_field_select_no_such_key_and_true", - "expr": "dyn(x.name) && true", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "mapType": { - "keyType": { - "primitive": "STRING" - }, - "valueType": { - "primitive": "STRING" - } - } - } - } - } - ], - "bindings": { - "x": { - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "holiday" - }, - "value": { - "stringValue": "field" - } - } - ] - } - } - } - }, - "evalError": { - "errors": [ - { - "message": "no such key: 'name'" - } - ] - } - }, - { - "name": "map_value_null", - "expr": "{true:null}[true]", - "value": { - "nullValue": null - } - }, - { - "name": "map_value_bool", - "expr": "{27:false}[27]", - "value": { - "boolValue": false - } - }, - { - "name": "map_value_string", - "expr": "{'n':'x'}['n']", - "value": { - "stringValue": "x" - } - }, - { - "name": "map_value_float", - "expr": "{3:15.15}[3]", - "value": { - "doubleValue": 15.15 - } - }, - { - "name": "map_value_uint64", - "expr": "{0u:1u,2u:2u,5u:3u}[0u]", - "value": { - "uint64Value": "1" - } - }, - { - "name": "map_value_int64", - "expr": "{true:1,false:2}[true]", - "value": { - "int64Value": "1" - } - }, - { - "name": "map_value_bytes", - "expr": "{0:b''}[0]", - "value": { - "bytesValue": "" - } - }, - { - "name": "map_value_list", - "expr": "{0u:[1]}[0u]", - "value": { - "listValue": { - "values": [ - { - "int64Value": "1" - } - ] - } - } - }, - { - "name": "map_value_map", - "expr": "{'map': {'k': 'v'}}['map']", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "k" - }, - "value": { - "stringValue": "v" - } - } - ] - } - } - }, - { - "name": "map_value_mix_type", - "expr": "{'map': {'k': 'v'}, 'list': [1]}['map']", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "k" - }, - "value": { - "stringValue": "v" - } - } - ] - } - } - } - ] - }, - { - "name": "map_has", - "description": "Has macro for map entries.", - "test": [ - { - "name": "has", - "expr": "has({'a': 1, 'b': 2}.a)", - "value": { - "boolValue": true - } - }, - { - "name": "has_not", - "expr": "has({'a': 1, 'b': 2}.c)", - "value": { - "boolValue": false - } - }, - { - "name": "has_empty", - "expr": "has({}.a)", - "value": { - "boolValue": false - } - } - ] - }, - { - "name": "quoted_map_fields", - "description": "Field accesses using the quote syntax", - "test": [ - { - "name": "field_access_slash", - "expr": "{'/api/v1': true, '/api/v2': false}.`/api/v1`", - "value": { - "boolValue": true - } - }, - { - "name": "field_access_dash", - "expr": "{'content-type': 'application/json', 'content-length': 145}.`content-type` == 'application/json'", - "value": { - "boolValue": true - } - }, - { - "name": "field_access_dot", - "expr": "{'foo.txt': 32, 'bar.csv': 1024}.`foo.txt`", - "value": { - "int64Value": "32" - } - }, - { - "name": "has_field_slash", - "expr": "has({'/api/v1': true, '/api/v2': false}.`/api/v3`)", - "value": { - "boolValue": false - } - }, - { - "name": "has_field_dash", - "expr": "has({'content-type': 'application/json', 'content-length': 145}.`content-type`)", - "value": { - "boolValue": true - } - }, - { - "name": "has_field_dot", - "expr": "has({'foo.txt': 32, 'bar.csv': 1024}.`foo.txt`)", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "qualified_identifier_resolution", - "description": "Tests for qualified identifier resolution.", - "test": [ - { - "name": "qualified_ident", - "expr": "a.b.c", - "typeEnv": [ - { - "name": "a.b.c", - "ident": { - "type": { - "primitive": "STRING" - } - } - } - ], - "bindings": { - "a.b.c": { - "value": { - "stringValue": "yeah" - } - } - }, - "value": { - "stringValue": "yeah" - } - }, - { - "name": "map_field_select", - "expr": "a.b.c", - "typeEnv": [ - { - "name": "a.b", - "ident": { - "type": { - "mapType": { - "keyType": { - "primitive": "STRING" - }, - "valueType": { - "primitive": "STRING" - } - } - } - } - } - ], - "bindings": { - "a.b": { - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "c" - }, - "value": { - "stringValue": "yeah" - } - } - ] - } - } - } - }, - "value": { - "stringValue": "yeah" - } - }, - { - "name": "qualified_identifier_resolution_unchecked", - "description": "namespace resolution should try to find the longest prefix for the evaluator.", - "expr": "a.b.c", - "disableCheck": true, - "typeEnv": [ - { - "name": "a.b.c", - "ident": { - "type": { - "primitive": "STRING" - } - } - }, - { - "name": "a.b", - "ident": { - "type": { - "mapType": { - "keyType": { - "primitive": "STRING" - }, - "valueType": { - "primitive": "STRING" - } - } - } - } - } - ], - "bindings": { - "a.b": { - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "c" - }, - "value": { - "stringValue": "oops" - } - } - ] - } - } - }, - "a.b.c": { - "value": { - "stringValue": "yeah" - } - } - }, - "value": { - "stringValue": "yeah" - } - }, - { - "name": "list_field_select_unsupported", - "expr": "a.b.pancakes", - "disableCheck": true, - "typeEnv": [ - { - "name": "a.b", - "ident": { - "type": { - "listType": { - "elemType": { - "primitive": "STRING" - } - } - } - } - } - ], - "bindings": { - "a.b": { - "value": { - "listValue": { - "values": [ - { - "stringValue": "pancakes" - } - ] - } - } - } - }, - "evalError": { - "errors": [ - { - "message": "type 'list_type: > ' does not support field selection" - } - ] - } - }, - { - "name": "int64_field_select_unsupported", - "expr": "a.pancakes", - "disableCheck": true, - "typeEnv": [ - { - "name": "a", - "ident": { - "type": { - "primitive": "INT64" - } - } - } - ], - "bindings": { - "a": { - "value": { - "int64Value": "15" - } - } - }, - "evalError": { - "errors": [ - { - "message": "type 'int64_type' does not support field selection" - } - ] - } - }, - { - "name": "ident_with_longest_prefix_check", - "description": "namespace resolution should try to find the longest prefix for the checker.", - "expr": "a.b.c", - "typeEnv": [ - { - "name": "a.b.c", - "ident": { - "type": { - "primitive": "STRING" - } - } - }, - { - "name": "a.b", - "ident": { - "type": { - "mapType": { - "keyType": { - "primitive": "STRING" - }, - "valueType": { - "primitive": "STRING" - } - } - } - } - } - ], - "bindings": { - "a.b": { - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "c" - }, - "value": { - "stringValue": "oops" - } - } - ] - } - } - }, - "a.b.c": { - "value": { - "stringValue": "yeah" - } - } - }, - "value": { - "stringValue": "yeah" - } - }, - { - "name": "map_key_float", - "description": "map should not support float as the key.", - "expr": "{3.3:15.15, 1.0: 5}[1.0]", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "unsupported key type" - } - ] - } - }, - { - "name": "map_key_null", - "description": "map should not support null as the key.", - "expr": "{null:false}[null]", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "unsupported key type" - } - ] - } - }, - { - "name": "map_value_repeat_key", - "description": "map should not support repeated key.", - "expr": "{true:1,false:2,true:3}[true]", - "evalError": { - "errors": [ - { - "message": "Failed with repeated key" - } - ] - } - }, - { - "name": "map_value_repeat_key_heterogeneous", - "description": "map should not support repeated key.", - "expr": "{0: 1, 0u: 2}[0.0]", - "evalError": { - "errors": [ - { - "message": "Failed with repeated key" - } - ] - } - } - ] - }, - { - "name": "in", - "description": "Tests for 'in' operator for maps.", - "test": [ - { - "name": "empty", - "expr": "7 in {}", - "value": { - "boolValue": false - } - }, - { - "name": "singleton", - "expr": "true in {true: 1}", - "value": { - "boolValue": true - } - }, - { - "name": "present", - "expr": "'George' in {'John': 'smart', 'Paul': 'cute', 'George': 'quiet', 'Ringo': 'funny'}", - "value": { - "boolValue": true - } - }, - { - "name": "absent", - "expr": "'spider' in {'ant': 6, 'fly': 6, 'centipede': 100}", - "value": { - "boolValue": false - } - }, - { - "name": "mixed_numbers_and_keys_present", - "expr": "3.0 in {1: 1, 2: 2, 3u: 3} && 2u in {1u: 1, 2: 2} && 1 in {1u: 1, 2: 2}", - "value": { - "boolValue": true - } - }, - { - "name": "mixed_numbers_and_keys_absent", - "expr": "3.1 in {1: 1, 2: 2, 3u: 3}", - "value": { - "boolValue": false - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/fp_math.json b/packages/cel-spec/src/testdata/json/fp_math.json deleted file mode 100644 index d59ac05e..00000000 --- a/packages/cel-spec/src/testdata/json/fp_math.json +++ /dev/null @@ -1,230 +0,0 @@ -{ - "name": "fp_math", - "description": "Tests for floating-point math.", - "section": [ - { - "name": "fp_math", - "description": "Simple tests for floating point.", - "test": [ - { - "name": "add_positive_positive", - "expr": "4.25 + 15.25", - "value": { - "doubleValue": 19.5 - } - }, - { - "name": "add_positive_negative", - "expr": "17.75 + (-7.75)", - "value": { - "doubleValue": 10 - } - }, - { - "name": "add_negative_negative", - "expr": "-4.125 + (-2.125)", - "value": { - "doubleValue": -6.25 - } - }, - { - "name": "sub_positive_positive", - "expr": "42.0 - 12.0", - "value": { - "doubleValue": 30 - } - }, - { - "name": "sub_positive_negative", - "expr": "42.875 - (-22.0)", - "value": { - "doubleValue": 64.875 - } - }, - { - "name": "sub_negative_negative", - "expr": "-4.875 - (-0.125)", - "value": { - "doubleValue": -4.75 - } - }, - { - "name": "multiply_positive_positive", - "expr": "42.5 * 0.2", - "value": { - "doubleValue": 8.5 - } - }, - { - "name": "multiply_positive_negative", - "expr": "40.75 * (-2.25)", - "value": { - "doubleValue": -91.6875 - } - }, - { - "name": "multiply_negative_negative", - "expr": "-3.0 * (-2.5)", - "value": { - "doubleValue": 7.5 - } - }, - { - "name": "divide_positive_positive", - "expr": "0.0625 / 0.002", - "value": { - "doubleValue": 31.25 - } - }, - { - "name": "divide_positive_negative", - "expr": "-2.0 / 2.0", - "value": { - "doubleValue": -1 - } - }, - { - "name": "divide_negative_negative", - "expr": "-8.875 / (-0.0625)", - "value": { - "doubleValue": 142 - } - }, - { - "name": "mod_not_support", - "expr": "47.5 % 5.5", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "found no matching overload for '_%_' applied to '(double, double)'" - } - ] - } - }, - { - "name": "negative", - "expr": "-(4.5)", - "value": { - "doubleValue": -4.5 - } - }, - { - "name": "double_negative", - "expr": "-(-1.25)", - "value": { - "doubleValue": 1.25 - } - }, - { - "name": "negative_zero", - "expr": "-(0.0)", - "value": { - "doubleValue": -0 - } - }, - { - "name": "divide_zero", - "expr": "15.75 / 0.0", - "value": { - "doubleValue": "Infinity" - } - }, - { - "name": "multiply_zero", - "expr": "15.36 * 0.0", - "value": { - "doubleValue": 0 - } - }, - { - "name": "add_left_identity", - "expr": "0.0 + 1.75", - "value": { - "doubleValue": 1.75 - } - }, - { - "name": "add_right_identity", - "expr": " 2.5 + 0.0", - "value": { - "doubleValue": 2.5 - } - }, - { - "name": "add_commutative", - "expr": "7.5 + 1.5 == 1.5 + 7.5", - "value": { - "boolValue": true - } - }, - { - "name": "add_associative", - "expr": "5.625 + (15.75 + 2.0) == (5.625 + 15.75) + 2.0", - "value": { - "boolValue": true - } - }, - { - "name": "mul_left_identity", - "expr": "1.0 * 45.25", - "value": { - "doubleValue": 45.25 - } - }, - { - "name": "mul_right_identity", - "expr": "-25.25 * 1.0", - "value": { - "doubleValue": -25.25 - } - }, - { - "name": "mul_commutative", - "expr": "1.5 * 25.875 == 25.875 * 1.5", - "value": { - "boolValue": true - } - }, - { - "name": "mul_associative", - "expr": "1.5 * (23.625 * 0.75) == (1.5 * 23.625) * 0.75", - "value": { - "boolValue": true - } - }, - { - "name": "add_mul_distribute", - "expr": "5.75 * (1.5 + 2.5) == 5.75 * 1.5 + 5.75 * 2.5", - "value": { - "boolValue": true - } - }, - { - "name": "fp_overflow_positive", - "description": "DBL_MAX(2^1023) times two", - "expr": "2.0 * 8.988466e+307 ", - "value": { - "doubleValue": "Infinity" - } - }, - { - "name": "fp_overflow_negative", - "description": "-DBL_MAX(-2^1023) times two", - "expr": "2.0 * -8.988466e+307 ", - "value": { - "doubleValue": "-Infinity" - } - }, - { - "name": "fp_underflow", - "description": "DBL_MIN(2^-1074) divided by two", - "expr": "1e-324 / 2.0", - "value": { - "doubleValue": 0 - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/integer_math.json b/packages/cel-spec/src/testdata/json/integer_math.json deleted file mode 100644 index 9b813a2e..00000000 --- a/packages/cel-spec/src/testdata/json/integer_math.json +++ /dev/null @@ -1,557 +0,0 @@ -{ - "name": "integer_math", - "description": "Tests for int and uint math.", - "section": [ - { - "name": "int64_math", - "description": "Simple tests for int64.", - "test": [ - { - "name": "add_positive_positive", - "expr": "40 + 2", - "value": { - "int64Value": "42" - } - }, - { - "name": "add_positive_negative", - "expr": "42 + (-7)", - "value": { - "int64Value": "35" - } - }, - { - "name": "add_negative_negative", - "expr": "-4 + (-2)", - "value": { - "int64Value": "-6" - } - }, - { - "name": "sub_positive_positive", - "expr": "42 - 12", - "value": { - "int64Value": "30" - } - }, - { - "name": "sub_positive_negative", - "expr": "42 - (-22)", - "value": { - "int64Value": "64" - } - }, - { - "name": "sub_negative_negative", - "expr": "-42 - (-12)", - "value": { - "int64Value": "-30" - } - }, - { - "name": "multiply_positive_positive", - "expr": "42 * 2", - "value": { - "int64Value": "84" - } - }, - { - "name": "multiply_positive_negative", - "expr": "40 * (-2)", - "value": { - "int64Value": "-80" - } - }, - { - "name": "multiply_negative_negative", - "expr": "-30 * (-2)", - "value": { - "int64Value": "60" - } - }, - { - "name": "divide_positive_positive", - "expr": "42 / 2", - "value": { - "int64Value": "21" - } - }, - { - "name": "divide_positive_negative", - "expr": "-20 / 2", - "value": { - "int64Value": "-10" - } - }, - { - "name": "divide_negative_negative", - "expr": "-80 / (-2)", - "value": { - "int64Value": "40" - } - }, - { - "name": "mod_positive_positive", - "expr": "47 % 5", - "value": { - "int64Value": "2" - } - }, - { - "name": "mod_positive_negative", - "expr": "43 % (-5)", - "value": { - "int64Value": "3" - } - }, - { - "name": "mod_negative_negative", - "expr": "-42 % (-5)", - "value": { - "int64Value": "-2" - } - }, - { - "name": "mod_negative_positive", - "expr": "-3 % 5", - "value": { - "int64Value": "-3" - } - }, - { - "name": "unary_minus_pos", - "expr": "-(42)", - "value": { - "int64Value": "-42" - } - }, - { - "name": "unary_minus_neg", - "expr": "-(-42)", - "value": { - "int64Value": "42" - } - }, - { - "name": "unary_minus_no_overload", - "expr": "-(42u)", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_such_overload" - } - ] - } - }, - { - "name": "unary_minus_not_bool", - "expr": "-false", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no_such_overload" - } - ] - } - }, - { - "name": "mod_zero", - "expr": "34 % 0", - "evalError": { - "errors": [ - { - "message": "modulus by zero" - } - ] - } - }, - { - "name": "negative_zero", - "expr": "-(0)", - "value": { - "int64Value": "0" - } - }, - { - "name": "double_negative", - "expr": "-(-42)", - "value": { - "int64Value": "42" - } - }, - { - "name": "divide_zero", - "expr": "15 / 0", - "evalError": { - "errors": [ - { - "message": "divide by zero" - } - ] - } - }, - { - "name": "multiply_zero", - "expr": "15 * 0", - "value": { - "int64Value": "0" - } - }, - { - "name": "add_left_identity", - "expr": "0 + 17", - "value": { - "int64Value": "17" - } - }, - { - "name": "add_right_identity", - "expr": " 29 + 0", - "value": { - "int64Value": "29" - } - }, - { - "name": "add_commutative", - "expr": "75 + 15 == 15 + 75", - "value": { - "boolValue": true - } - }, - { - "name": "add_associative", - "expr": "5 + (15 + 20) == (5 + 15) + 20", - "value": { - "boolValue": true - } - }, - { - "name": "mul_left_identity", - "expr": "1 * 45", - "value": { - "int64Value": "45" - } - }, - { - "name": "mul_right_identity", - "expr": "-25 * 1", - "value": { - "int64Value": "-25" - } - }, - { - "name": "mul_commutative", - "expr": "15 * 25 == 25 * 15", - "value": { - "boolValue": true - } - }, - { - "name": "mul_associative", - "expr": "15 * (23 * 88) == (15 * 23) * 88", - "value": { - "boolValue": true - } - }, - { - "name": "add_mul_distribute", - "expr": "5 * (15 + 25) == 5 * 15 + 5 * 25", - "value": { - "boolValue": true - } - }, - { - "name": "int64_overflow_positive", - "description": "LLONG_MAX plus one.", - "expr": "9223372036854775807 + 1", - "evalError": { - "errors": [ - { - "message": "return error for overflow" - } - ] - } - }, - { - "name": "int64_overflow_negative", - "description": "LLONG_MIN minus one.", - "expr": "-9223372036854775808 - 1", - "evalError": { - "errors": [ - { - "message": "return error for overflow" - } - ] - } - }, - { - "name": "int64_overflow_add_negative", - "description": "negative overflow via addition", - "expr": "-9223372036854775808 + (-1)", - "evalError": { - "errors": [ - { - "message": "return error for overflow" - } - ] - } - }, - { - "name": "int64_overflow_sub_positive", - "description": "positive overflow via subtraction", - "expr": "1 - (-9223372036854775807)", - "evalError": { - "errors": [ - { - "message": "return error for overflow" - } - ] - } - }, - { - "name": "int64_min_negate", - "description": "Negated LLONG_MIN is not representable.", - "expr": "-(-9223372036854775808)", - "evalError": { - "errors": [ - { - "message": "return error for overflow" - } - ] - } - }, - { - "name": "int64_min_negate_mul", - "description": "Negate LLONG_MIN via multiplication", - "expr": "(-9223372036854775808) * -1", - "evalError": { - "errors": [ - { - "message": "return error for overflow" - } - ] - } - }, - { - "name": "int64_min_negate_div", - "description": "Negate LLONG_MIN via division.", - "expr": "(-9223372036854775808)/-1", - "evalError": { - "errors": [ - { - "message": "return error for overflow" - } - ] - } - }, - { - "name": "int64_overflow_mul_positive", - "description": "Overflow via multiplication.", - "expr": "5000000000 * 5000000000", - "evalError": { - "errors": [ - { - "message": "return error for overflow" - } - ] - } - }, - { - "name": "int64_overflow_mul_negative", - "description": "Overflow via multiplication.", - "expr": "(-5000000000) * 5000000000", - "evalError": { - "errors": [ - { - "message": "return error for overflow" - } - ] - } - }, - { - "name": "uint64_overflow_positive", - "description": "ULLONG_MAX plus one.", - "expr": "18446744073709551615u + 1u", - "evalError": { - "errors": [ - { - "message": "return error for overflow" - } - ] - } - }, - { - "name": "uint64_overflow_negative", - "description": "zero minus one.", - "expr": "0u - 1u", - "evalError": { - "errors": [ - { - "message": "return error for overflow" - } - ] - } - }, - { - "name": "uint64_overflow_mul_positive", - "description": "Overflow via multiplication.", - "expr": "5000000000u * 5000000000u", - "evalError": { - "errors": [ - { - "message": "return error for overflow" - } - ] - } - } - ] - }, - { - "name": "uint64_math", - "description": "Simple tests for uint64.", - "test": [ - { - "name": "add", - "expr": "42u + 2u", - "value": { - "uint64Value": "44" - } - }, - { - "name": "sub", - "expr": "42u - 12u", - "value": { - "uint64Value": "30" - } - }, - { - "name": "multiply", - "expr": "40u * 2u", - "value": { - "uint64Value": "80" - } - }, - { - "name": "divide", - "expr": "60u / 2u", - "value": { - "uint64Value": "30" - } - }, - { - "name": "mod", - "expr": "42u % 5u", - "value": { - "uint64Value": "2" - } - }, - { - "name": "negative_no_overload", - "expr": "-(5u)", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "mod_zero", - "expr": "34u % 0u", - "evalError": { - "errors": [ - { - "message": "modulus by zero" - } - ] - } - }, - { - "name": "divide_zero", - "expr": "15u / 0u", - "evalError": { - "errors": [ - { - "message": "divide by zero" - } - ] - } - }, - { - "name": "multiply_zero", - "expr": "15u * 0u", - "value": { - "uint64Value": "0" - } - }, - { - "name": "add_left_identity", - "expr": "0u + 17u", - "value": { - "uint64Value": "17" - } - }, - { - "name": "add_right_identity", - "expr": " 29u + 0u", - "value": { - "uint64Value": "29" - } - }, - { - "name": "add_commutative", - "expr": "75u + 15u == 15u + 75u", - "value": { - "boolValue": true - } - }, - { - "name": "add_associative", - "expr": "5u + (15u + 20u) == (5u + 15u) + 20u", - "value": { - "boolValue": true - } - }, - { - "name": "mul_left_identity", - "expr": "1u * 45u", - "value": { - "uint64Value": "45" - } - }, - { - "name": "mul_right_identity", - "expr": "25u * 1u", - "value": { - "uint64Value": "25" - } - }, - { - "name": "mul_commutative", - "expr": "15u * 25u == 25u * 15u", - "value": { - "boolValue": true - } - }, - { - "name": "mul_associative", - "expr": "15u * (23u * 88u) == (15u * 23u) * 88u", - "value": { - "boolValue": true - } - }, - { - "name": "add_mul_distribute", - "expr": "5u * (15u + 25u) == 5u * 15u + 5u * 25u", - "value": { - "boolValue": true - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/lists.json b/packages/cel-spec/src/testdata/json/lists.json deleted file mode 100644 index b7f3fa2b..00000000 --- a/packages/cel-spec/src/testdata/json/lists.json +++ /dev/null @@ -1,358 +0,0 @@ -{ - "name": "lists", - "description": "Tests for list operations.", - "section": [ - { - "name": "concatenation", - "description": "Tests for list concatenation.", - "test": [ - { - "name": "list_append", - "expr": "[0, 1, 2] + [3, 4, 5] == [0, 1, 2, 3, 4, 5]", - "value": { - "boolValue": true - } - }, - { - "name": "list_not_commutative", - "expr": "[0, 1, 2] + [3, 4, 5] == [3, 4, 5, 0, 1, 2]", - "value": { - "boolValue": false - } - }, - { - "name": "list_repeat", - "expr": "[2] + [2]", - "value": { - "listValue": { - "values": [ - { - "int64Value": "2" - }, - { - "int64Value": "2" - } - ] - } - } - }, - { - "name": "empty_empty", - "expr": "[] + []", - "value": { - "listValue": {} - } - }, - { - "name": "left_unit", - "expr": "[] + [3, 4]", - "value": { - "listValue": { - "values": [ - { - "int64Value": "3" - }, - { - "int64Value": "4" - } - ] - } - } - }, - { - "name": "right_unit", - "expr": "[1, 2] + []", - "value": { - "listValue": { - "values": [ - { - "int64Value": "1" - }, - { - "int64Value": "2" - } - ] - } - } - } - ] - }, - { - "name": "index", - "description": "List indexing tests.", - "test": [ - { - "name": "zero_based", - "expr": "[7, 8, 9][0]", - "value": { - "int64Value": "7" - } - }, - { - "name": "zero_based_double", - "expr": "[7, 8, 9][dyn(0.0)]", - "value": { - "int64Value": "7" - } - }, - { - "name": "zero_based_double_error", - "expr": "[7, 8, 9][dyn(0.1)]", - "evalError": { - "errors": [ - { - "message": "invalid_argument" - } - ] - } - }, - { - "name": "zero_based_uint", - "expr": "[7, 8, 9][dyn(0u)]", - "value": { - "int64Value": "7" - } - }, - { - "name": "singleton", - "expr": "['foo'][0]", - "value": { - "stringValue": "foo" - } - }, - { - "name": "middle", - "expr": "[0, 1, 1, 2, 3, 5, 8, 13][4]", - "value": { - "int64Value": "3" - } - }, - { - "name": "last", - "expr": "['George', 'John', 'Paul', 'Ringo'][3]", - "value": { - "stringValue": "Ringo" - } - }, - { - "name": "index_out_of_bounds", - "expr": "[1, 2, 3][3]", - "evalError": { - "errors": [ - { - "message": "invalid_argument" - } - ] - } - }, - { - "name": "index_out_of_bounds_or_false", - "expr": "dyn([1, 2, 3][3]) || false", - "evalError": { - "errors": [ - { - "message": "invalid_argument" - } - ] - } - }, - { - "name": "index_out_of_bounds_or_true", - "expr": "dyn([1, 2, 3][3]) || true", - "value": { - "boolValue": true - } - }, - { - "name": "index_out_of_bounds_and_false", - "expr": "dyn([1, 2, 3][3]) && false", - "value": { - "boolValue": false - } - }, - { - "name": "index_out_of_bounds_and_true", - "expr": "dyn([1, 2, 3][3]) && true", - "evalError": { - "errors": [ - { - "message": "invalid_argument" - } - ] - } - }, - { - "name": "bad_index_type", - "expr": "[1, 2, 3][dyn('')]", - "evalError": { - "errors": [ - { - "message": "invalid_argument" - } - ] - } - }, - { - "name": "bad_index_type_or_false", - "expr": "dyn([1, 2, 3][dyn('')]) || false", - "evalError": { - "errors": [ - { - "message": "invalid_argument" - } - ] - } - }, - { - "name": "bad_index_type_or_true", - "expr": "dyn([1, 2, 3][dyn('')]) || true", - "value": { - "boolValue": true - } - }, - { - "name": "bad_index_type_and_false", - "expr": "dyn([1, 2, 3][dyn('')]) && false", - "value": { - "boolValue": false - } - }, - { - "name": "bad_index_type_and_true", - "expr": "dyn([1, 2, 3][dyn('')]) && true", - "evalError": { - "errors": [ - { - "message": "invalid_argument" - } - ] - } - } - ] - }, - { - "name": "in", - "description": "List membership tests.", - "test": [ - { - "name": "empty", - "expr": "7 in []", - "value": { - "boolValue": false - } - }, - { - "name": "singleton", - "expr": "4u in [4u]", - "value": { - "boolValue": true - } - }, - { - "name": "first", - "expr": "'alpha' in ['alpha', 'beta', 'gamma']", - "value": { - "boolValue": true - } - }, - { - "name": "middle", - "expr": "3 in [5, 4, 3, 2, 1]", - "value": { - "boolValue": true - } - }, - { - "name": "last", - "expr": "20u in [4u, 6u, 8u, 12u, 20u]", - "value": { - "boolValue": true - } - }, - { - "name": "double_in_ints", - "expr": "dyn(3.0) in [5, 4, 3, 2, 1]", - "value": { - "boolValue": true - } - }, - { - "name": "uint_in_ints", - "expr": "dyn(3u) in [5, 4, 3, 2, 1]", - "value": { - "boolValue": true - } - }, - { - "name": "int_in_doubles", - "expr": "dyn(3) in [5.0, 4.0, 3.0, 2.0, 1.0]", - "value": { - "boolValue": true - } - }, - { - "name": "uint_in_doubles", - "expr": "dyn(3u) in [5.0, 4.0, 3.0, 2.0, 1.0]", - "value": { - "boolValue": true - } - }, - { - "name": "int_in_uints", - "expr": "dyn(3) in [5u, 4u, 3u, 2u, 1u]", - "value": { - "boolValue": true - } - }, - { - "name": "double_in_uints", - "expr": "dyn(3.0) in [5u, 4u, 3u, 2u, 1u]", - "value": { - "boolValue": true - } - }, - { - "name": "missing", - "expr": "'hawaiian' in ['meat', 'veggie', 'margarita', 'cheese']", - "value": { - "boolValue": false - } - } - ] - }, - { - "name": "size", - "description": "List and map size tests.", - "test": [ - { - "name": "list_empty", - "expr": "size([])", - "value": { - "int64Value": "0" - } - }, - { - "name": "list", - "expr": "size([1, 2, 3])", - "value": { - "int64Value": "3" - } - }, - { - "name": "map_empty", - "expr": "size({})", - "value": { - "int64Value": "0" - } - }, - { - "name": "map", - "expr": "size({1: 'one', 2: 'two', 3: 'three'})", - "value": { - "int64Value": "3" - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/logic.json b/packages/cel-spec/src/testdata/json/logic.json deleted file mode 100644 index 87a43443..00000000 --- a/packages/cel-spec/src/testdata/json/logic.json +++ /dev/null @@ -1,285 +0,0 @@ -{ - "name": "logic", - "description": "Tests for logical special operators.", - "section": [ - { - "name": "conditional", - "description": "Tests for the conditional operator.", - "test": [ - { - "name": "true_case", - "expr": "true ? 1 : 2", - "value": { - "int64Value": "1" - } - }, - { - "name": "false_case", - "expr": "false ? 'foo' : 'bar'", - "value": { - "stringValue": "bar" - } - }, - { - "name": "error_case", - "expr": "2 / 0 > 4 ? 'baz' : 'quux'", - "evalError": { - "errors": [ - { - "message": "division by zero" - } - ] - } - }, - { - "name": "mixed_type", - "expr": "true ? 'cows' : 17", - "disableCheck": true, - "value": { - "stringValue": "cows" - } - }, - { - "name": "bad_type", - "expr": "'cows' ? false : 17", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no matching overload" - } - ] - } - } - ] - }, - { - "name": "AND", - "description": "Tests for logical AND.", - "test": [ - { - "name": "all_true", - "expr": "true && true", - "value": { - "boolValue": true - } - }, - { - "name": "all_false", - "expr": "false && false", - "value": { - "boolValue": false - } - }, - { - "name": "false_left", - "expr": "false && true", - "value": { - "boolValue": false - } - }, - { - "name": "false_right", - "expr": "true && false", - "value": { - "boolValue": false - } - }, - { - "name": "short_circuit_type_left", - "expr": "false && 32", - "disableCheck": true, - "value": { - "boolValue": false - } - }, - { - "name": "short_circuit_type_right", - "expr": "'horses' && false", - "disableCheck": true, - "value": { - "boolValue": false - } - }, - { - "name": "short_circuit_error_left", - "expr": "false && (2 / 0 > 3 ? false : true)", - "value": { - "boolValue": false - } - }, - { - "name": "short_circuit_error_right", - "expr": "(2 / 0 > 3 ? false : true) && false", - "value": { - "boolValue": false - } - }, - { - "name": "error_right", - "expr": "true && 1/0 != 0", - "evalError": { - "errors": [ - { - "message": "no matching overload" - } - ] - } - }, - { - "name": "error_left", - "expr": "1/0 != 0 && true", - "evalError": { - "errors": [ - { - "message": "no matching overload" - } - ] - } - }, - { - "name": "no_overload", - "expr": "'less filling' && 'tastes great'", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no matching overload" - } - ] - } - } - ] - }, - { - "name": "OR", - "description": "Tests for logical OR", - "test": [ - { - "name": "all_true", - "expr": "true || true", - "value": { - "boolValue": true - } - }, - { - "name": "all_false", - "expr": "false || false", - "value": { - "boolValue": false - } - }, - { - "name": "false_left", - "expr": "false || true", - "value": { - "boolValue": true - } - }, - { - "name": "false_right", - "expr": "true || false", - "value": { - "boolValue": true - } - }, - { - "name": "short_circuit_type_left", - "expr": "true || 32", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "short_circuit_type_right", - "expr": "'horses' || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "short_circuit_error_left", - "expr": "true || (2 / 0 > 3 ? false : true)", - "value": { - "boolValue": true - } - }, - { - "name": "short_circuit_error_right", - "expr": "(2 / 0 > 3 ? false : true) || true", - "value": { - "boolValue": true - } - }, - { - "name": "error_right", - "expr": "false || 1/0 != 0", - "evalError": { - "errors": [ - { - "message": "no matching overload" - } - ] - } - }, - { - "name": "error_left", - "expr": "1/0 != 0 || false", - "evalError": { - "errors": [ - { - "message": "no matching overload" - } - ] - } - }, - { - "name": "no_overload", - "expr": "'less filling' || 'tastes great'", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no matching overload" - } - ] - } - } - ] - }, - { - "name": "NOT", - "description": "Tests for logical NOT.", - "test": [ - { - "name": "not_true", - "expr": "!true", - "value": { - "boolValue": false - } - }, - { - "name": "not_false", - "expr": "!false", - "value": { - "boolValue": true - } - }, - { - "name": "no_overload", - "expr": "!0", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no matching overload" - } - ] - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/macros.json b/packages/cel-spec/src/testdata/json/macros.json deleted file mode 100644 index 42a0f688..00000000 --- a/packages/cel-spec/src/testdata/json/macros.json +++ /dev/null @@ -1,430 +0,0 @@ -{ - "name": "macros", - "description": "Tests for CEL macros.", - "section": [ - { - "name": "exists", - "description": "Tests for the .exists() macro, which is equivalent to joining the evaluated elements with logical-OR.", - "test": [ - { - "name": "list_elem_all_true", - "expr": "[1, 2, 3].exists(e, e > 0)", - "value": { - "boolValue": true - } - }, - { - "name": "list_elem_some_true", - "expr": "[1, 2, 3].exists(e, e == 2)", - "value": { - "boolValue": true - } - }, - { - "name": "list_elem_none_true", - "expr": "[1, 2, 3].exists(e, e > 3)", - "value": { - "boolValue": false - } - }, - { - "name": "list_elem_type_shortcircuit", - "description": "Exists filter is true for the last element.", - "expr": "[1, 'foo', 3].exists(e, e != '1')", - "value": { - "boolValue": true - } - }, - { - "name": "list_elem_type_exhaustive", - "description": "Exists filter is never true, but heterogenous equality ensure the result is false.", - "expr": "[1, 'foo', 3].exists(e, e == '10')", - "value": { - "boolValue": false - } - }, - { - "name": "list_elem_exists_error", - "expr": "[1, 2, 3].exists(e, e / 0 == 17)", - "evalError": { - "errors": [ - { - "message": "divide by zero" - } - ] - } - }, - { - "name": "list_empty", - "expr": "[].exists(e, e == 2)", - "value": { - "boolValue": false - } - }, - { - "name": "map_key", - "expr": "{'key1':1, 'key2':2}.exists(k, k == 'key2')", - "value": { - "boolValue": true - } - }, - { - "name": "not_map_key", - "expr": "!{'key1':1, 'key2':2}.exists(k, k == 'key3')", - "value": { - "boolValue": true - } - }, - { - "name": "map_key_type_shortcircuit", - "description": "Exists filter is true for the second key", - "expr": "{'key':1, 1:21}.exists(k, k != 2)", - "value": { - "boolValue": true - } - }, - { - "name": "map_key_type_exhaustive", - "description": "Exists filter is never true, but heterogeneous equality ensures the result is false.", - "expr": "!{'key':1, 1:42}.exists(k, k == 2)", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "all", - "description": "Tests for the .all() macro, which is equivalent to joining the evaluated elements with logical-AND.", - "test": [ - { - "name": "list_elem_all_true", - "expr": "[1, 2, 3].all(e, e > 0)", - "value": { - "boolValue": true - } - }, - { - "name": "list_elem_some_true", - "expr": "[1, 2, 3].all(e, e == 2)", - "value": { - "boolValue": false - } - }, - { - "name": "list_elem_none_true", - "expr": "[1, 2, 3].all(e, e == 17)", - "value": { - "boolValue": false - } - }, - { - "name": "list_elem_type_shortcircuit", - "expr": "[1, 'foo', 3].all(e, e == 1)", - "value": { - "boolValue": false - } - }, - { - "name": "list_elem_type_exhaustive", - "expr": "[1, 'foo', 3].all(e, e % 2 == 1)", - "evalError": { - "errors": [ - { - "message": "no_such_overload" - } - ] - } - }, - { - "name": "list_elem_error_shortcircuit", - "expr": "[1, 2, 3].all(e, 6 / (2 - e) == 6)", - "value": { - "boolValue": false - } - }, - { - "name": "list_elem_error_exhaustive", - "expr": "[1, 2, 3].all(e, e / 0 != 17)", - "evalError": { - "errors": [ - { - "message": "divide by zero" - } - ] - } - }, - { - "name": "list_empty", - "expr": "[].all(e, e > 0)", - "value": { - "boolValue": true - } - }, - { - "name": "map_key", - "expr": "{'key1':1, 'key2':2}.all(k, k == 'key2')", - "value": { - "boolValue": false - } - } - ] - }, - { - "name": "exists_one", - "description": "Tests for exists_one() macro. An expression 'L.exists_one(I, E)' is equivalent to 'size(L.filter(I, E)) == 1'.", - "test": [ - { - "name": "list_empty", - "expr": "[].exists_one(a, a == 7)", - "value": { - "boolValue": false - } - }, - { - "name": "list_one_true", - "expr": "[7].exists_one(a, a == 7)", - "value": { - "boolValue": true - } - }, - { - "name": "list_one_false", - "expr": "[8].exists_one(a, a == 7)", - "value": { - "boolValue": false - } - }, - { - "name": "list_none", - "expr": "[1, 2, 3].exists_one(x, x > 20)", - "value": { - "boolValue": false - } - }, - { - "name": "list_one", - "expr": "[6, 7, 8].exists_one(foo, foo % 5 == 2)", - "value": { - "boolValue": true - } - }, - { - "name": "list_many", - "expr": "[0, 1, 2, 3, 4].exists_one(n, n % 2 == 1)", - "value": { - "boolValue": false - } - }, - { - "name": "list_all", - "expr": "['foal', 'foo', 'four'].exists_one(n, n.startsWith('fo'))", - "value": { - "boolValue": false - } - }, - { - "name": "list_no_shortcircuit", - "description": "Errors invalidate everything, even if already false.", - "expr": "[3, 2, 1, 0].exists_one(n, 12 / n > 1)", - "evalError": { - "errors": [ - { - "message": "divide by zero" - } - ] - } - }, - { - "name": "map_one", - "expr": "{6: 'six', 7: 'seven', 8: 'eight'}.exists_one(foo, foo % 5 == 2)", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "map", - "description": "Tests for map() macro.", - "test": [ - { - "name": "list_empty", - "expr": "[].map(n, n / 2)", - "value": { - "listValue": {} - } - }, - { - "name": "list_one", - "expr": "[3].map(n, n * n)", - "value": { - "listValue": { - "values": [ - { - "int64Value": "9" - } - ] - } - } - }, - { - "name": "list_many", - "expr": "[2, 4, 6].map(n, n / 2)", - "value": { - "listValue": { - "values": [ - { - "int64Value": "1" - }, - { - "int64Value": "2" - }, - { - "int64Value": "3" - } - ] - } - } - }, - { - "name": "list_error", - "expr": "[2, 1, 0].map(n, 4 / n)", - "evalError": { - "errors": [ - { - "message": "divide by zero" - } - ] - } - }, - { - "name": "map_extract_keys", - "expr": "{'John': 'smart'}.map(key, key) == ['John']", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "filter", - "description": "Tests for filter() macro.", - "test": [ - { - "name": "list_empty", - "expr": "[].filter(n, n % 2 == 0)", - "value": { - "listValue": {} - } - }, - { - "name": "list_one_true", - "expr": "[2].filter(n, n == 2)", - "value": { - "listValue": { - "values": [ - { - "int64Value": "2" - } - ] - } - } - }, - { - "name": "list_one_false", - "expr": "[1].filter(n, n > 3)", - "value": { - "listValue": {} - } - }, - { - "name": "list_none", - "expr": "[1, 2, 3].filter(e, e > 3)", - "value": { - "listValue": {} - } - }, - { - "name": "list_some", - "expr": "[0, 1, 2, 3, 4].filter(x, x % 2 == 1)", - "value": { - "listValue": { - "values": [ - { - "int64Value": "1" - }, - { - "int64Value": "3" - } - ] - } - } - }, - { - "name": "list_all", - "expr": "[1, 2, 3].filter(n, n > 0)", - "value": { - "listValue": { - "values": [ - { - "int64Value": "1" - }, - { - "int64Value": "2" - }, - { - "int64Value": "3" - } - ] - } - } - }, - { - "name": "list_no_shortcircuit", - "expr": "[3, 2, 1, 0].filter(n, 12 / n > 4)", - "evalError": { - "errors": [ - { - "message": "divide by zero" - } - ] - } - }, - { - "name": "map_filter_keys", - "expr": "{'John': 'smart', 'Paul': 'cute', 'George': 'quiet', 'Ringo': 'funny'}.filter(key, key == 'Ringo') == ['Ringo']", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "nested", - "description": "Tests with nested macros.", - "test": [ - { - "name": "filter_all", - "expr": "['signer'].filter(signer, ['artifact'].all(artifact, true))", - "value": { - "listValue": { - "values": [ - { - "stringValue": "signer" - } - ] - } - } - }, - { - "name": "all_all", - "expr": "['signer'].all(signer, ['artifact'].all(artifact, true))", - "value": { - "boolValue": true - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/macros2.json b/packages/cel-spec/src/testdata/json/macros2.json deleted file mode 100644 index 93e60d0e..00000000 --- a/packages/cel-spec/src/testdata/json/macros2.json +++ /dev/null @@ -1,491 +0,0 @@ -{ - "name": "macros2", - "description": "Tests for CEL comprehensions v2", - "section": [ - { - "name": "exists", - "description": "Tests for the .exists() macro, which is equivalent to joining the evaluated elements with logical-OR.", - "test": [ - { - "name": "list_elem_all_true", - "expr": "[1, 2, 3].exists(i, v, i > -1 && v > 0)", - "value": { - "boolValue": true - } - }, - { - "name": "list_elem_some_true", - "expr": "[1, 2, 3].exists(i, v, i == 1 && v == 2)", - "value": { - "boolValue": true - } - }, - { - "name": "list_elem_none_true", - "expr": "[1, 2, 3].exists(i, v, i > 2 && v > 3)", - "value": { - "boolValue": false - } - }, - { - "name": "list_elem_type_shortcircuit", - "expr": "[1, 'foo', 3].exists(i, v, i == 1 && v != '1')", - "value": { - "boolValue": true - } - }, - { - "name": "list_elem_type_exhaustive", - "expr": "[1, 'foo', 3].exists(i, v, i == 3 || v == '10')", - "value": { - "boolValue": false - } - }, - { - "name": "list_elem_exists_error", - "expr": "[1, 2, 3].exists(i, v, v / i == 17)", - "evalError": { - "errors": [ - { - "message": "divide by zero" - } - ] - } - }, - { - "name": "list_empty", - "expr": "[].exists(i, v, i == 0 || v == 2)", - "value": { - "boolValue": false - } - }, - { - "name": "map_key", - "expr": "{'key1':1, 'key2':2}.exists(k, v, k == 'key2' && v == 2)", - "value": { - "boolValue": true - } - }, - { - "name": "not_map_key", - "expr": "!{'key1':1, 'key2':2}.exists(k, v, k == 'key3' || v == 3)", - "value": { - "boolValue": true - } - }, - { - "name": "map_key_type_shortcircuit", - "expr": "{'key':1, 1:21}.exists(k, v, k != 2 && v != 22)", - "value": { - "boolValue": true - } - }, - { - "name": "map_key_type_exhaustive", - "expr": "!{'key':1, 1:42}.exists(k, v, k == 2 && v == 43)", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "all", - "description": "Tests for the .all() macro, which is equivalent to joining the evaluated elements with logical-AND.", - "test": [ - { - "name": "list_elem_all_true", - "expr": "[1, 2, 3].all(i, v, i > -1 && v > 0)", - "value": { - "boolValue": true - } - }, - { - "name": "list_elem_some_true", - "expr": "[1, 2, 3].all(i, v, i == 1 && v == 2)", - "value": { - "boolValue": false - } - }, - { - "name": "list_elem_none_true", - "expr": "[1, 2, 3].all(i, v, i == 3 || v == 4)", - "value": { - "boolValue": false - } - }, - { - "name": "list_elem_type_shortcircuit", - "expr": "[1, 'foo', 3].all(i, v, i == 0 || v == 1)", - "value": { - "boolValue": false - } - }, - { - "name": "list_elem_type_exhaustive", - "expr": "[0, 'foo', 3].all(i, v, v % 2 == i)", - "value": { - "boolValue": false - } - }, - { - "name": "list_elem_type_error_exhaustive", - "expr": "[0, 'foo', 5].all(i, v, v % 3 == i)", - "evalError": { - "errors": [ - { - "message": "no_such_overload" - } - ] - } - }, - { - "name": "list_elem_error_shortcircuit", - "expr": "[1, 2, 3].all(i, v, 6 / (2 - v) == i)", - "value": { - "boolValue": false - } - }, - { - "name": "list_elem_error_exhaustive", - "expr": "[1, 2, 3].all(i, v, v / i != 17)", - "evalError": { - "errors": [ - { - "message": "divide by zero" - } - ] - } - }, - { - "name": "list_empty", - "expr": "[].all(i, v, i > -1 || v > 0)", - "value": { - "boolValue": true - } - }, - { - "name": "map_key", - "expr": "{'key1':1, 'key2':2}.all(k, v, k == 'key2' && v == 2)", - "value": { - "boolValue": false - } - } - ] - }, - { - "name": "existsOne", - "description": "Tests for existsOne() macro. An expression 'L.existsOne(I, E)' is equivalent to 'size(L.filter(I, E)) == 1'.", - "test": [ - { - "name": "list_empty", - "expr": "[].existsOne(i, v, i == 3 || v == 7)", - "value": { - "boolValue": false - } - }, - { - "name": "list_one_true", - "expr": "[7].existsOne(i, v, i == 0 && v == 7)", - "value": { - "boolValue": true - } - }, - { - "name": "list_one_false", - "expr": "[8].existsOne(i, v, i == 0 && v == 7)", - "value": { - "boolValue": false - } - }, - { - "name": "list_none", - "expr": "[1, 2, 3].existsOne(i, v, i > 2 || v > 3)", - "value": { - "boolValue": false - } - }, - { - "name": "list_one", - "expr": "[5, 7, 8].existsOne(i, v, v % 5 == i)", - "value": { - "boolValue": true - } - }, - { - "name": "list_many", - "expr": "[0, 1, 2, 3, 4].existsOne(i, v, v % 2 == i)", - "value": { - "boolValue": false - } - }, - { - "name": "list_all", - "expr": "['foal', 'foo', 'four'].existsOne(i, v, i > -1 && v.startsWith('fo'))", - "value": { - "boolValue": false - } - }, - { - "name": "list_no_shortcircuit", - "expr": "[3, 2, 1, 0].existsOne(i, v, v / i > 1)", - "evalError": { - "errors": [ - { - "message": "divide by zero" - } - ] - } - }, - { - "name": "map_one", - "expr": "{6: 'six', 7: 'seven', 8: 'eight'}.existsOne(k, v, k % 5 == 2 && v == 'seven')", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "transformList", - "description": "Tests for transformList() macro.", - "test": [ - { - "name": "empty", - "expr": "[].transformList(i, v, i / v)", - "value": { - "listValue": {} - } - }, - { - "name": "empty_filter", - "expr": "[].transformList(i, v, i > v, i / v)", - "value": { - "listValue": {} - } - }, - { - "name": "one", - "expr": "[3].transformList(i, v, v * v + i)", - "value": { - "listValue": { - "values": [ - { - "int64Value": "9" - } - ] - } - } - }, - { - "name": "one_filter", - "expr": "[3].transformList(i, v, i == 0 && v == 3, v * v + i)", - "value": { - "listValue": { - "values": [ - { - "int64Value": "9" - } - ] - } - } - }, - { - "name": "many", - "expr": "[2, 4, 6].transformList(i, v, v / 2 + i)", - "value": { - "listValue": { - "values": [ - { - "int64Value": "1" - }, - { - "int64Value": "3" - }, - { - "int64Value": "5" - } - ] - } - } - }, - { - "name": "many_filter", - "expr": "[2, 4, 6].transformList(i, v, i != 1 && v != 4, v / 2 + i)", - "value": { - "listValue": { - "values": [ - { - "int64Value": "1" - }, - { - "int64Value": "5" - } - ] - } - } - }, - { - "name": "error", - "expr": "[2, 1, 0].transformList(i, v, v / i)", - "evalError": { - "errors": [ - { - "message": "divide by zero" - } - ] - } - }, - { - "name": "error_filter", - "expr": "[2, 1, 0].transformList(i, v, v / i > 0, v)", - "evalError": { - "errors": [ - { - "message": "divide by zero" - } - ] - } - } - ] - }, - { - "name": "transformMap", - "description": "Tests for transformMap() macro.", - "test": [ - { - "name": "empty", - "expr": "{}.transformMap(k, v, k + v)", - "value": { - "mapValue": {} - } - }, - { - "name": "empty_filter", - "expr": "{}.transformMap(k, v, k == 'foo' && v == 'bar', k + v)", - "value": { - "mapValue": {} - } - }, - { - "name": "one", - "expr": "{'foo': 'bar'}.transformMap(k, v, k + v)", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "foo" - }, - "value": { - "stringValue": "foobar" - } - } - ] - } - } - }, - { - "name": "one_filter", - "expr": "{'foo': 'bar'}.transformMap(k, v, k == 'foo' && v == 'bar', k + v)", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "foo" - }, - "value": { - "stringValue": "foobar" - } - } - ] - } - } - }, - { - "name": "many", - "expr": "{'foo': 'bar', 'baz': 'bux', 'hello': 'world'}.transformMap(k, v, k + v)", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "foo" - }, - "value": { - "stringValue": "foobar" - } - }, - { - "key": { - "stringValue": "baz" - }, - "value": { - "stringValue": "bazbux" - } - }, - { - "key": { - "stringValue": "hello" - }, - "value": { - "stringValue": "helloworld" - } - } - ] - } - } - }, - { - "name": "many_filter", - "expr": "{'foo': 'bar', 'baz': 'bux', 'hello': 'world'}.transformMap(k, v, k != 'baz' && v != 'bux', k + v)", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "foo" - }, - "value": { - "stringValue": "foobar" - } - }, - { - "key": { - "stringValue": "hello" - }, - "value": { - "stringValue": "helloworld" - } - } - ] - } - } - }, - { - "name": "error", - "expr": "{'foo': 2, 'bar': 1, 'baz': 0}.transformMap(k, v, 4 / v)", - "evalError": { - "errors": [ - { - "message": "divide by zero" - } - ] - } - }, - { - "name": "error_filter", - "expr": "{'foo': 2, 'bar': 1, 'baz': 0}.transformMap(k, v, k == 'baz' && 4 / v == 0, v)", - "evalError": { - "errors": [ - { - "message": "divide by zero" - } - ] - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/math_ext.json b/packages/cel-spec/src/testdata/json/math_ext.json deleted file mode 100644 index ac4a16fb..00000000 --- a/packages/cel-spec/src/testdata/json/math_ext.json +++ /dev/null @@ -1,1323 +0,0 @@ -{ - "name": "math_ext", - "description": "Tests for the math extension library.", - "section": [ - { - "name": "greatest_int_result", - "test": [ - { - "name": "unary_negative", - "expr": "math.greatest(-5)", - "value": { - "int64Value": "-5" - } - }, - { - "name": "unary_positive", - "expr": "math.greatest(5)", - "value": { - "int64Value": "5" - } - }, - { - "name": "binary_same_args", - "expr": "math.greatest(1, 1)", - "value": { - "int64Value": "1" - } - }, - { - "name": "binary_with_decimal", - "expr": "math.greatest(1, 1.0) == 1" - }, - { - "name": "binary_with_uint", - "expr": "math.greatest(1, 1u) == 1" - }, - { - "name": "binary_first_arg_greater", - "expr": "math.greatest(3, -3)", - "value": { - "int64Value": "3" - } - }, - { - "name": "binary_second_arg_greater", - "expr": "math.greatest(-7, 5)", - "value": { - "int64Value": "5" - } - }, - { - "name": "binary_first_arg_int_max", - "expr": "math.greatest(9223372036854775807, 1)", - "value": { - "int64Value": "9223372036854775807" - } - }, - { - "name": "binary_second_arg_int_max", - "expr": "math.greatest(1, 9223372036854775807)", - "value": { - "int64Value": "9223372036854775807" - } - }, - { - "name": "binary_first_arg_int_min", - "expr": "math.greatest(-9223372036854775808, 1)", - "value": { - "int64Value": "1" - } - }, - { - "name": "binary_second_arg_int_min", - "expr": "math.greatest(1, -9223372036854775808)", - "value": { - "int64Value": "1" - } - }, - { - "name": "ternary_same_args", - "expr": "math.greatest(1, 1, 1) == 1" - }, - { - "name": "ternary_with_decimal", - "expr": "math.greatest(1, 1.0, 1.0) == 1" - }, - { - "name": "ternary_with_uint", - "expr": "math.greatest(1, 1u, 1u) == 1" - }, - { - "name": "ternary_first_arg_greatest", - "expr": "math.greatest(10, 1, 3) == 10" - }, - { - "name": "ternary_third_arg_greatest", - "expr": "math.greatest(1, 3, 10) == 10" - }, - { - "name": "ternary_with_negatives", - "expr": "math.greatest(-1, -2, -3) == -1" - }, - { - "name": "ternary_int_max", - "expr": "math.greatest(9223372036854775807, 1, 5) == 9223372036854775807" - }, - { - "name": "ternary_int_min", - "expr": "math.greatest(-9223372036854775807, -1, -5) == -1" - }, - { - "name": "quaternary_mixed", - "expr": "math.greatest(5.4, 10, 3u, -5.0, 9223372036854775807) == 9223372036854775807" - }, - { - "name": "quaternary_mixed_array", - "expr": "math.greatest([5.4, 10, 3u, -5.0, 3.5]) == 10" - }, - { - "name": "quaternary_mixed_dyn_array", - "expr": "math.greatest([dyn(5.4), dyn(10), dyn(3u), dyn(-5.0), dyn(3.5)]) == 10" - } - ] - }, - { - "name": "greatest_double_result", - "test": [ - { - "name": "unary_negative", - "expr": "math.greatest(-5.0)", - "value": { - "doubleValue": -5 - } - }, - { - "name": "unary_positive", - "expr": "math.greatest(5.0)", - "value": { - "doubleValue": 5 - } - }, - { - "name": "binary_same_args", - "expr": "math.greatest(1.0, 1.0)", - "value": { - "doubleValue": 1 - } - }, - { - "name": "binary_with_int", - "expr": "math.greatest(1.0, 1) == 1.0" - }, - { - "name": "binary_with_uint", - "expr": "math.greatest(1.0, 1u) == 1.0" - }, - { - "name": "binary_first_arg_greater", - "expr": "math.greatest(5.0, -7.0)", - "value": { - "doubleValue": 5 - } - }, - { - "name": "binary_second_arg_greater", - "expr": "math.greatest(-3.0, 3.0)", - "value": { - "doubleValue": 3 - } - }, - { - "name": "binary_first_arg_double_max", - "expr": "math.greatest(1.797693e308, 1)", - "value": { - "doubleValue": 1.797693e308 - } - }, - { - "name": "binary_second_arg_double_max", - "expr": "math.greatest(1, 1.797693e308)", - "value": { - "doubleValue": 1.797693e308 - } - }, - { - "name": "binary_first_arg_double_min", - "expr": "math.greatest(-1.797693e308, 1.5)", - "value": { - "doubleValue": 1.5 - } - }, - { - "name": "binary_second_arg_double_min", - "expr": "math.greatest(1.5, -1.797693e308)", - "value": { - "doubleValue": 1.5 - } - }, - { - "name": "ternary_same_args", - "expr": "math.greatest(1.0, 1.0, 1.0) == 1.0" - }, - { - "name": "ternary_with_int", - "expr": "math.greatest(1.0, 1, 1) == 1.0" - }, - { - "name": "ternary_with_uint", - "expr": "math.greatest(1.0, 1u, 1u) == 1.0" - }, - { - "name": "ternary_first_arg_greatest", - "expr": "math.greatest(10.5, 1.5, 3.5) == 10.5" - }, - { - "name": "ternary_third_arg_greatest", - "expr": "math.greatest(1.5, 3.5, 10.5) == 10.5" - }, - { - "name": "ternary_with_negatives", - "expr": "math.greatest(-1.5, -2.5, -3.5) == -1.5" - }, - { - "name": "ternary_double_max", - "expr": "math.greatest(1.797693e308, 1, 5) == 1.797693e308" - }, - { - "name": "ternary_double_min", - "expr": "math.greatest(-1.797693e308, -1, -5) == -1" - }, - { - "name": "quaternary_mixed", - "expr": "math.greatest(5.4, 10, 3u, -5.0, 1.797693e308) == 1.797693e308" - }, - { - "name": "quaternary_mixed_array", - "expr": "math.greatest([5.4, 10.5, 3u, -5.0, 3.5]) == 10.5" - }, - { - "name": "quaternary_mixed_dyn_array", - "expr": "math.greatest([dyn(5.4), dyn(10.5), dyn(3u), dyn(-5.0), dyn(3.5)]) == 10.5" - } - ] - }, - { - "name": "greatest_uint_result", - "test": [ - { - "name": "unary", - "expr": "math.greatest(5u)", - "value": { - "uint64Value": "5" - } - }, - { - "name": "binary_same_args", - "expr": "math.greatest(1u, 1u)", - "value": { - "uint64Value": "1" - } - }, - { - "name": "binary_with_decimal", - "expr": "math.greatest(1u, 1.0) == 1" - }, - { - "name": "binary_with_int", - "expr": "math.greatest(1u, 1) == 1u" - }, - { - "name": "binary_first_arg_greater", - "expr": "math.greatest(5u, -7)", - "value": { - "uint64Value": "5" - } - }, - { - "name": "binary_second_arg_greater", - "expr": "math.greatest(-3, 3u)", - "value": { - "uint64Value": "3" - } - }, - { - "name": "binary_first_arg_uint_max", - "expr": "math.greatest(18446744073709551615u, 1u)", - "value": { - "uint64Value": "18446744073709551615" - } - }, - { - "name": "binary_second_arg_uint_max", - "expr": "math.greatest(1u, 18446744073709551615u)", - "value": { - "uint64Value": "18446744073709551615" - } - }, - { - "name": "ternary_same_args", - "expr": "math.greatest(1u, 1u, 1u) == 1u" - }, - { - "name": "ternary_with_decimal", - "expr": "math.greatest(1u, 1.0, 1.0) == 1u" - }, - { - "name": "ternary_with_int", - "expr": "math.greatest(1u, 1, 1) == 1u" - }, - { - "name": "ternary_first_arg_greatest", - "expr": "math.greatest(10u, 1u, 3u) == 10u" - }, - { - "name": "ternary_third_arg_greatest", - "expr": "math.greatest(1u, 3u, 10u) == 10u" - }, - { - "name": "ternary_int_max", - "expr": "math.greatest(18446744073709551615u, 1u, 5u) == 18446744073709551615u" - }, - { - "name": "quaternary_mixed", - "expr": "math.greatest(5.4, 10, 3u, -5.0, 18446744073709551615u) == 18446744073709551615u" - }, - { - "name": "quaternary_mixed_array", - "expr": "math.greatest([5.4, 10u, 3u, -5.0, 3.5]) == 10u" - }, - { - "name": "quaternary_mixed_dyn_array", - "expr": "math.greatest([dyn(5.4), dyn(10u), dyn(3u), dyn(-5.0), dyn(3.5)]) == 10u" - } - ] - }, - { - "name": "least_int_result", - "test": [ - { - "name": "unary_negative", - "expr": "math.least(-5)", - "value": { - "int64Value": "-5" - } - }, - { - "name": "unary_positive", - "expr": "math.least(5)", - "value": { - "int64Value": "5" - } - }, - { - "name": "binary_same_args", - "expr": "math.least(1, 1)", - "value": { - "int64Value": "1" - } - }, - { - "name": "binary_with_decimal", - "expr": "math.least(1, 1.0) == 1" - }, - { - "name": "binary_with_uint", - "expr": "math.least(1, 1u) == 1" - }, - { - "name": "binary_first_arg_least", - "expr": "math.least(-3, 3)", - "value": { - "int64Value": "-3" - } - }, - { - "name": "binary_second_arg_least", - "expr": "math.least(5, -7)", - "value": { - "int64Value": "-7" - } - }, - { - "name": "binary_first_arg_int_max", - "expr": "math.least(9223372036854775807, 1)", - "value": { - "int64Value": "1" - } - }, - { - "name": "binary_second_arg_int_max", - "expr": "math.least(1, 9223372036854775807)", - "value": { - "int64Value": "1" - } - }, - { - "name": "binary_first_arg_int_min", - "expr": "math.least(-9223372036854775808, 1)", - "value": { - "int64Value": "-9223372036854775808" - } - }, - { - "name": "binary_second_arg_int_min", - "expr": "math.least(1, -9223372036854775808)", - "value": { - "int64Value": "-9223372036854775808" - } - }, - { - "name": "ternary_same_args", - "expr": "math.least(1, 1, 1) == 1" - }, - { - "name": "ternary_with_decimal", - "expr": "math.least(1, 1.0, 1.0) == 1" - }, - { - "name": "ternary_with_uint", - "expr": "math.least(1, 1u, 1u) == 1" - }, - { - "name": "ternary_first_arg_least", - "expr": "math.least(0, 1, 3) == 0" - }, - { - "name": "ternary_third_arg_least", - "expr": "math.least(1, 3, 0) == 0" - }, - { - "name": "ternary_with_negatives", - "expr": "math.least(-1, -2, -3) == -3" - }, - { - "name": "ternary_int_max", - "expr": "math.least(9223372036854775807, 1, 5) == 1" - }, - { - "name": "ternary_int_min", - "expr": "math.least(-9223372036854775808, -1, -5) == -9223372036854775808" - }, - { - "name": "quaternary_mixed", - "expr": "math.least(5.4, 10, 3u, -5.0, 9223372036854775807) == -5.0" - }, - { - "name": "quaternary_mixed_array", - "expr": "math.least([5.4, 10, 3u, -5.0, 3.5]) == -5.0" - }, - { - "name": "quaternary_mixed_dyn_array", - "expr": "math.least([dyn(5.4), dyn(10), dyn(3u), dyn(-5.0), dyn(3.5)]) == -5.0" - } - ] - }, - { - "name": "least_double_result", - "test": [ - { - "name": "unary_negative", - "expr": "math.least(-5.5)", - "value": { - "doubleValue": -5.5 - } - }, - { - "name": "unary_positive", - "expr": "math.least(5.5)", - "value": { - "doubleValue": 5.5 - } - }, - { - "name": "binary_same_args", - "expr": "math.least(1.5, 1.5)", - "value": { - "doubleValue": 1.5 - } - }, - { - "name": "binary_with_int", - "expr": "math.least(1.0, 1) == 1" - }, - { - "name": "binary_with_uint", - "expr": "math.least(1, 1u) == 1" - }, - { - "name": "binary_first_arg_least", - "expr": "math.least(-3.5, 3.5)", - "value": { - "doubleValue": -3.5 - } - }, - { - "name": "binary_second_arg_least", - "expr": "math.least(5.5, -7.5)", - "value": { - "doubleValue": -7.5 - } - }, - { - "name": "binary_first_arg_double_max", - "expr": "math.least(1.797693e308, 1.5)", - "value": { - "doubleValue": 1.5 - } - }, - { - "name": "binary_second_arg_double_max", - "expr": "math.least(1.5, 1.797693e308)", - "value": { - "doubleValue": 1.5 - } - }, - { - "name": "binary_first_arg_double_min", - "expr": "math.least(-1.797693e308, 1.5)", - "value": { - "doubleValue": -1.797693e308 - } - }, - { - "name": "binary_second_arg_double_min", - "expr": "math.least(1.5, -1.797693e308)", - "value": { - "doubleValue": -1.797693e308 - } - }, - { - "name": "ternary_same_args", - "expr": "math.least(1.5, 1.5, 1.5) == 1.5" - }, - { - "name": "ternary_with_int", - "expr": "math.least(1.0, 1, 1) == 1.0" - }, - { - "name": "ternary_with_uint", - "expr": "math.least(1.0, 1u, 1u) == 1" - }, - { - "name": "ternary_first_arg_least", - "expr": "math.least(0.5, 1.5, 3.5) == 0.5" - }, - { - "name": "ternary_third_arg_least", - "expr": "math.least(1.5, 3.5, 0.5) == 0.5" - }, - { - "name": "ternary_with_negatives", - "expr": "math.least(-1.5, -2.5, -3.5) == -3.5" - }, - { - "name": "ternary_double_max", - "expr": "math.least(1.797693e308, 1, 5) == 1" - }, - { - "name": "ternary_double_min", - "expr": "math.least(-1.797693e308, -1, -5) == -1.797693e308" - }, - { - "name": "quaternary_mixed", - "expr": "math.least(5.4, 10, 3u, -5.0, 1.797693e308) == -5.0" - }, - { - "name": "quaternary_mixed_array", - "expr": "math.least([5.4, 10.5, 3u, -5.0, 3.5]) == -5.0" - }, - { - "name": "quaternary_mixed_dyn_array", - "expr": "math.least([dyn(5.4), dyn(10.5), dyn(3u), dyn(-5.0), dyn(3.5)]) == -5.0" - } - ] - }, - { - "name": "least_uint_result", - "test": [ - { - "name": "unary", - "expr": "math.least(5u)", - "value": { - "uint64Value": "5" - } - }, - { - "name": "binary_same_args", - "expr": "math.least(1u, 1u)", - "value": { - "uint64Value": "1" - } - }, - { - "name": "binary_with_decimal", - "expr": "math.least(1u, 1.0) == 1u" - }, - { - "name": "binary_with_int", - "expr": "math.least(1u, 1) == 1u" - }, - { - "name": "binary_first_arg_least", - "expr": "math.least(1u, 3u)", - "value": { - "uint64Value": "1" - } - }, - { - "name": "binary_second_arg_least", - "expr": "math.least(5u, 2u)", - "value": { - "uint64Value": "2" - } - }, - { - "name": "binary_first_arg_uint_max", - "expr": "math.least(18446744073709551615u, 1u)", - "value": { - "uint64Value": "1" - } - }, - { - "name": "binary_second_arg_uint_max", - "expr": "math.least(1u, 18446744073709551615u)", - "value": { - "uint64Value": "1" - } - }, - { - "name": "ternary_same_args", - "expr": "math.least(1u, 1u, 1u) == 1u" - }, - { - "name": "ternary_with_decimal", - "expr": "math.least(1u, 1.0, 1.0) == 1u" - }, - { - "name": "ternary_with_int", - "expr": "math.least(1u, 1, 1) == 1u" - }, - { - "name": "ternary_first_arg_least", - "expr": "math.least(1u, 10u, 3u) == 1u" - }, - { - "name": "ternary_third_arg_least", - "expr": "math.least(10u, 3u, 1u) == 1u" - }, - { - "name": "ternary_uint_max", - "expr": "math.least(18446744073709551615u, 1u, 5u) == 1u" - }, - { - "name": "quaternary_mixed", - "expr": "math.least(5.4, 10, 3u, 1u, 18446744073709551615u) == 1u" - }, - { - "name": "quaternary_mixed_array", - "expr": "math.least([5.4, 10u, 3u, 1u, 3.5]) == 1u" - }, - { - "name": "quaternary_mixed_dyn_array", - "expr": "math.least([dyn(5.4), dyn(10u), dyn(3u), dyn(1u), dyn(3.5)]) == 1u" - } - ] - }, - { - "name": "ceil", - "test": [ - { - "name": "negative", - "expr": "math.ceil(-1.2)", - "value": { - "doubleValue": -1 - } - }, - { - "name": "positive", - "expr": "math.ceil(1.2)", - "value": { - "doubleValue": 2 - } - }, - { - "name": "dyn_error", - "expr": "math.ceil(dyn(1))", - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - } - ] - }, - { - "name": "floor", - "test": [ - { - "name": "negative", - "expr": "math.floor(-1.2)", - "value": { - "doubleValue": -2 - } - }, - { - "name": "positive", - "expr": "math.floor(1.2)", - "value": { - "doubleValue": 1 - } - }, - { - "name": "dyn_error", - "expr": "math.floor(dyn(1))", - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - } - ] - }, - { - "name": "round", - "test": [ - { - "name": "negative_down", - "expr": "math.round(-1.6)", - "value": { - "doubleValue": -2 - } - }, - { - "name": "negative_up", - "expr": "math.round(-1.4)", - "value": { - "doubleValue": -1 - } - }, - { - "name": "negative_mid", - "expr": "math.round(-1.5)", - "value": { - "doubleValue": -2 - } - }, - { - "name": "positive_down", - "expr": "math.round(1.2)", - "value": { - "doubleValue": 1 - } - }, - { - "name": "positive_up", - "expr": "math.round(1.5)", - "value": { - "doubleValue": 2 - } - }, - { - "name": "nan", - "expr": "math.isNaN(math.round(0.0/0.0))" - }, - { - "name": "dyn_error", - "expr": "math.round(dyn(1))", - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - } - ] - }, - { - "name": "trunc", - "test": [ - { - "name": "negative", - "expr": "math.trunc(-1.2)", - "value": { - "doubleValue": -1 - } - }, - { - "name": "positive", - "expr": "math.trunc(1.2)", - "value": { - "doubleValue": 1 - } - }, - { - "name": "nan", - "expr": "math.isNaN(math.trunc(0.0/0.0))" - }, - { - "name": "dyn_error", - "expr": "math.trunc(dyn(1))", - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - } - ] - }, - { - "name": "abs", - "test": [ - { - "name": "uint", - "expr": "math.abs(1u)", - "value": { - "uint64Value": "1" - } - }, - { - "name": "positive_int", - "expr": "math.abs(1)", - "value": { - "int64Value": "1" - } - }, - { - "name": "negative_int", - "expr": "math.abs(-11)", - "value": { - "int64Value": "11" - } - }, - { - "name": "positive_double", - "expr": "math.abs(1.5)", - "value": { - "doubleValue": 1.5 - } - }, - { - "name": "negative_double", - "expr": "math.abs(-11.5)", - "value": { - "doubleValue": 11.5 - } - }, - { - "name": "int_overflow", - "expr": "math.abs(-9223372036854775808)", - "evalError": { - "errors": [ - { - "message": "overflow" - } - ] - } - } - ] - }, - { - "name": "sign", - "test": [ - { - "name": "positive_uint", - "expr": "math.sign(100u)", - "value": { - "uint64Value": "1" - } - }, - { - "name": "zero_uint", - "expr": "math.sign(0u)", - "value": { - "uint64Value": "0" - } - }, - { - "name": "positive_int", - "expr": "math.sign(100)", - "value": { - "int64Value": "1" - } - }, - { - "name": "negative_int", - "expr": "math.sign(-11)", - "value": { - "int64Value": "-1" - } - }, - { - "name": "zero_int", - "expr": "math.sign(0)", - "value": { - "int64Value": "0" - } - }, - { - "name": "positive_double", - "expr": "math.sign(100.5)", - "value": { - "doubleValue": 1 - } - }, - { - "name": "negative_double", - "expr": "math.sign(-32.0)", - "value": { - "doubleValue": -1 - } - }, - { - "name": "zero_double", - "expr": "math.sign(0.0)", - "value": { - "doubleValue": 0 - } - }, - { - "name": "dyn_error", - "expr": "math.sign(dyn(true))", - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - } - ] - }, - { - "name": "isNaN", - "test": [ - { - "name": "true", - "expr": "math.isNaN(0.0/0.0)" - }, - { - "name": "false", - "expr": "!math.isNaN(1.0/0.0)" - }, - { - "name": "dyn_error", - "expr": "math.isNaN(dyn(true))", - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - } - ] - }, - { - "name": "isInf", - "test": [ - { - "name": "true", - "expr": "math.isInf(1.0/0.0)" - }, - { - "name": "false", - "expr": "!math.isInf(0.0/0.0)" - }, - { - "name": "dyn_error", - "expr": "math.isInf(dyn(true))", - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - } - ] - }, - { - "name": "isFinite", - "test": [ - { - "name": "true", - "expr": "math.isFinite(1.0/1.5)" - }, - { - "name": "false_nan", - "expr": "!math.isFinite(0.0/0.0)" - }, - { - "name": "false_inf", - "expr": "!math.isFinite(-1.0/0.0)" - }, - { - "name": "dyn_error", - "expr": "math.isFinite(dyn(true))", - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - } - ] - }, - { - "name": "bit_and", - "test": [ - { - "name": "int_int_non_intersect", - "expr": "math.bitAnd(1, 2)", - "value": { - "int64Value": "0" - } - }, - { - "name": "int_int_intersect", - "expr": "math.bitAnd(1, 3)", - "value": { - "int64Value": "1" - } - }, - { - "name": "int_int_intersect_neg", - "expr": "math.bitAnd(1, -1)", - "value": { - "int64Value": "1" - } - }, - { - "name": "uint_uint_non_intersect", - "expr": "math.bitAnd(1u, 2u)", - "value": { - "uint64Value": "0" - } - }, - { - "name": "uint_uint_intersect", - "expr": "math.bitAnd(1u, 3u)", - "value": { - "uint64Value": "1" - } - }, - { - "name": "int_dyn_error", - "expr": "math.bitAnd(2u, dyn(''))", - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - } - ] - }, - { - "name": "bit_or", - "test": [ - { - "name": "int_int_positive", - "expr": "math.bitOr(1, 2)", - "value": { - "int64Value": "3" - } - }, - { - "name": "int_int_positive_negative", - "expr": "math.bitOr(4, -2)", - "value": { - "int64Value": "-2" - } - }, - { - "name": "uint_uint", - "expr": "math.bitOr(1u, 4u)", - "value": { - "uint64Value": "5" - } - }, - { - "name": "dyn_int_error", - "expr": "math.bitOr(dyn(1.2), 1)", - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - } - ] - }, - { - "name": "bit_xor", - "test": [ - { - "name": "int_int_positive", - "expr": "math.bitXor(1, 3)", - "value": { - "int64Value": "2" - } - }, - { - "name": "int_int_positive_negative", - "expr": "math.bitXor(4, -2)", - "value": { - "int64Value": "-6" - } - }, - { - "name": "uint_uint", - "expr": "math.bitXor(1u, 3u)", - "value": { - "uint64Value": "2" - } - }, - { - "name": "dyn_dyn_error", - "expr": "math.bitXor(dyn([]), dyn([1]))", - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - } - ] - }, - { - "name": "bit_not", - "test": [ - { - "name": "int_positive", - "expr": "math.bitNot(1)", - "value": { - "int64Value": "-2" - } - }, - { - "name": "int_negative", - "expr": "math.bitNot(-1)", - "value": { - "int64Value": "0" - } - }, - { - "name": "int_zero", - "expr": "math.bitNot(0)", - "value": { - "int64Value": "-1" - } - }, - { - "name": "uint_positive", - "expr": "math.bitNot(1u)", - "value": { - "uint64Value": "18446744073709551614" - } - }, - { - "name": "uint_zero", - "expr": "math.bitNot(0u)", - "value": { - "uint64Value": "18446744073709551615" - } - }, - { - "name": "dyn_error", - "expr": "math.bitNot(dyn(''))", - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - } - ] - }, - { - "name": "bit_shift_left", - "test": [ - { - "name": "int", - "expr": "math.bitShiftLeft(1, 2)", - "value": { - "int64Value": "4" - } - }, - { - "name": "int_large_shift", - "expr": "math.bitShiftLeft(1, 200)", - "value": { - "int64Value": "0" - } - }, - { - "name": "int_negative_large_shift", - "expr": "math.bitShiftLeft(-1, 200)", - "value": { - "int64Value": "0" - } - }, - { - "name": "uint", - "expr": "math.bitShiftLeft(1u, 2)", - "value": { - "uint64Value": "4" - } - }, - { - "name": "uint_large_shift", - "expr": "math.bitShiftLeft(1u, 200)", - "value": { - "uint64Value": "0" - } - }, - { - "name": "bad_shift", - "expr": "math.bitShiftLeft(1u, -1)", - "evalError": { - "errors": [ - { - "message": "negative offset" - } - ] - } - }, - { - "name": "dyn_int_error", - "expr": "math.bitShiftLeft(dyn(4.3), 1)", - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - } - ] - }, - { - "name": "bit_shift_right", - "test": [ - { - "name": "int", - "expr": "math.bitShiftRight(1024, 2)", - "value": { - "int64Value": "256" - } - }, - { - "name": "int_large_shift", - "expr": "math.bitShiftRight(1024, 64)", - "value": { - "int64Value": "0" - } - }, - { - "name": "int_negative", - "expr": "math.bitShiftRight(-1024, 3)", - "value": { - "int64Value": "2305843009213693824" - } - }, - { - "name": "int_negative_large_shift", - "expr": "math.bitShiftRight(-1024, 64)", - "value": { - "int64Value": "0" - } - }, - { - "name": "uint", - "expr": "math.bitShiftRight(1024u, 2)", - "value": { - "uint64Value": "256" - } - }, - { - "name": "uint_large_shift", - "expr": "math.bitShiftRight(1024u, 200)", - "value": { - "uint64Value": "0" - } - }, - { - "name": "bad_shift", - "expr": "math.bitShiftRight(1u, -1)", - "evalError": { - "errors": [ - { - "message": "negative offset" - } - ] - } - }, - { - "name": "dyn_int_error", - "expr": "math.bitShiftRight(dyn(b'123'), 1)", - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/namespace.json b/packages/cel-spec/src/testdata/json/namespace.json deleted file mode 100644 index b5e34691..00000000 --- a/packages/cel-spec/src/testdata/json/namespace.json +++ /dev/null @@ -1,119 +0,0 @@ -{ - "name": "namespace", - "description": "Uses of qualified identifiers and namespaces.", - "section": [ - { - "name": "qualified", - "description": "Qualified variable lookups.", - "test": [ - { - "name": "self_eval_qualified_lookup", - "expr": "x.y", - "typeEnv": [ - { - "name": "x.y", - "ident": { - "type": { - "primitive": "BOOL" - } - } - } - ], - "bindings": { - "x.y": { - "value": { - "boolValue": true - } - } - }, - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "namespace", - "description": "Namespaced identifiers.", - "test": [ - { - "name": "self_eval_container_lookup", - "expr": "y", - "typeEnv": [ - { - "name": "x.y", - "ident": { - "type": { - "primitive": "BOOL" - } - } - }, - { - "name": "y", - "ident": { - "type": { - "primitive": "STRING" - } - } - } - ], - "container": "x", - "bindings": { - "x.y": { - "value": { - "boolValue": true - } - }, - "y": { - "value": { - "stringValue": "false" - } - } - }, - "value": { - "boolValue": true - } - }, - { - "name": "self_eval_container_lookup_unchecked", - "expr": "y", - "disableCheck": true, - "typeEnv": [ - { - "name": "x.y", - "ident": { - "type": { - "primitive": "BOOL" - } - } - }, - { - "name": "y", - "ident": { - "type": { - "primitive": "BOOL" - } - } - } - ], - "container": "x", - "bindings": { - "x.y": { - "value": { - "boolValue": true - } - }, - "y": { - "value": { - "boolValue": false - } - } - }, - "value": { - "boolValue": true - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/optionals.json b/packages/cel-spec/src/testdata/json/optionals.json deleted file mode 100644 index 2c2471b3..00000000 --- a/packages/cel-spec/src/testdata/json/optionals.json +++ /dev/null @@ -1,606 +0,0 @@ -{ - "name": "optionals", - "description": "Tests for optionals.", - "section": [ - { - "name": "optionals", - "test": [ - { - "name": "null", - "expr": "optional.of(null).hasValue()", - "value": { - "boolValue": true - } - }, - { - "name": "null_non_zero_value", - "expr": "optional.ofNonZeroValue(null).hasValue()", - "value": { - "boolValue": false - } - }, - { - "name": "none_or_none_or_value", - "expr": "optional.none().or(optional.none()).orValue(42)", - "value": { - "int64Value": "42" - } - }, - { - "name": "none_optMap_hasValue", - "expr": "optional.none().optMap(y, y + 1).hasValue()", - "value": { - "boolValue": false - } - }, - { - "name": "empty_map_optFlatMap_hasValue", - "expr": "{}.?key.optFlatMap(k, k.?subkey).hasValue()", - "value": { - "boolValue": false - } - }, - { - "name": "map_empty_submap_optFlatMap_hasValue", - "expr": "{'key': {}}.?key.optFlatMap(k, k.?subkey).hasValue()", - "value": { - "boolValue": false - } - }, - { - "name": "map_null_entry_hasValue", - "expr": "{'null_key': dyn(null)}.?null_key.hasValue()", - "value": { - "boolValue": true - } - }, - { - "name": "map_null_entry_no_such_key", - "expr": "{'null_key': dyn(null)}.?null_key.invalid.hasValue()", - "evalError": { - "errors": [ - { - "message": "no such key" - } - ] - } - }, - { - "name": "map_absent_key_absent_field_none", - "expr": "{true: dyn(0)}[?false].absent.hasValue()", - "value": { - "boolValue": false - } - }, - { - "name": "map_present_key_invalid_field", - "expr": "{true: dyn(0)}[?true].absent.hasValue()", - "evalError": { - "errors": [ - { - "message": "no such key" - } - ] - } - }, - { - "name": "map_undefined_entry_hasValue", - "expr": "{}.?null_key.invalid.hasValue()", - "value": { - "boolValue": false - } - }, - { - "name": "map_submap_subkey_optFlatMap_value", - "expr": "{'key': {'subkey': 'subvalue'}}.?key.optFlatMap(k, k.?subkey).value()", - "value": { - "stringValue": "subvalue" - } - }, - { - "name": "map_submap_optFlatMap_value", - "expr": "{'key': {'subkey': ''}}.?key.optFlatMap(k, k.?subkey).value()", - "value": { - "stringValue": "" - } - }, - { - "name": "map_optindex_optFlatMap_optional_ofNonZeroValue_hasValue", - "expr": "{'key': {'subkey': ''}}.?key.optFlatMap(k, optional.ofNonZeroValue(k.subkey)).hasValue()", - "value": { - "boolValue": false - } - }, - { - "name": "optional_of_optMap_value", - "expr": "optional.of(42).optMap(y, y + 1).value()", - "value": { - "int64Value": "43" - } - }, - { - "name": "optional_ofNonZeroValue_or_optional_value", - "expr": "optional.ofNonZeroValue(42).or(optional.of(20)).value() == 42", - "value": { - "boolValue": true - } - }, - { - "name": "ternary_optional_hasValue", - "expr": "(has({}.x) ? optional.of({}.x) : optional.none()).hasValue()", - "value": { - "boolValue": false - } - }, - { - "name": "map_optindex_hasValue", - "expr": "{}.?x.hasValue()", - "value": { - "boolValue": false - } - }, - { - "name": "has_map_optindex", - "expr": "has({}.?x.y)", - "value": { - "boolValue": false - } - }, - { - "name": "has_map_optindex_field", - "expr": "has({'x': {'y': 'z'}}.?x.y)", - "value": { - "boolValue": true - } - }, - { - "name": "type", - "expr": "type(optional.none()) == optional_type", - "value": { - "boolValue": true - } - }, - { - "name": "optional_chaining_1", - "expr": "optional.ofNonZeroValue('').or(optional.of({'c': {'dashed-index': 'goodbye'}}.c['dashed-index'])).orValue('default value')", - "value": { - "stringValue": "goodbye" - } - }, - { - "name": "optional_chaining_2", - "expr": "{'c': {'dashed-index': 'goodbye'}}.c[?'dashed-index'].orValue('default value')", - "value": { - "stringValue": "goodbye" - } - }, - { - "name": "optional_chaining_3", - "expr": "{'c': {}}.c[?'missing-index'].orValue('default value')", - "value": { - "stringValue": "default value" - } - }, - { - "name": "optional_chaining_4", - "expr": "optional.of({'c': {'index': 'goodbye'}}).c.index.orValue('default value')", - "value": { - "stringValue": "goodbye" - } - }, - { - "name": "optional_chaining_5", - "expr": "optional.of({'c': {}}).c.missing.or(optional.none()[0]).orValue('default value')", - "value": { - "stringValue": "default value" - } - }, - { - "name": "optional_chaining_6", - "expr": "optional.of({'c': {}}).c.missing.or(optional.of(['list-value'])[0]).orValue('default value')", - "value": { - "stringValue": "list-value" - } - }, - { - "name": "optional_chaining_7", - "expr": "optional.of({'c': {'index': 'goodbye'}}).c['index'].orValue('default value')", - "value": { - "stringValue": "goodbye" - } - }, - { - "name": "optional_chaining_8", - "expr": "optional.of({'c': {}}).c['missing'].orValue('default value')", - "value": { - "stringValue": "default value" - } - }, - { - "name": "optional_chaining_9", - "expr": "has(optional.of({'c': {'entry': 'hello world'}}).c) && !has(optional.of({'c': {'entry': 'hello world'}}).c.missing)", - "value": { - "boolValue": true - } - }, - { - "name": "optional_chaining_10", - "expr": "optional.ofNonZeroValue({'c': {'dashed-index': 'goodbye'}}.a.z).orValue({'c': {'dashed-index': 'goodbye'}}.c['dashed-index'])", - "evalError": { - "errors": [ - { - "message": "no such key" - } - ] - } - }, - { - "name": "optional_chaining_11", - "expr": "{'c': {'dashed-index': 'goodbye'}}.?c.missing.or({'c': {'dashed-index': 'goodbye'}}.?c['dashed-index']).orValue('').size()", - "value": { - "int64Value": "7" - } - }, - { - "name": "optional_chaining_12", - "expr": "{?'nested_map': optional.ofNonZeroValue({?'map': {'c': {'dashed-index': 'goodbye'}}.?c})}", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "nested_map" - }, - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "map" - }, - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "dashed-index" - }, - "value": { - "stringValue": "goodbye" - } - } - ] - } - } - } - ] - } - } - } - ] - } - } - }, - { - "name": "optional_chaining_13", - "expr": "{?'nested_map': optional.ofNonZeroValue({?'map': {}.?c}), 'singleton': true}", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "singleton" - }, - "value": { - "boolValue": true - } - } - ] - } - } - }, - { - "name": "optional_chaining_14", - "expr": "[?{}.?c, ?optional.of(42), ?optional.none()]", - "value": { - "listValue": { - "values": [ - { - "int64Value": "42" - } - ] - } - } - }, - { - "name": "optional_chaining_15", - "expr": "[?optional.ofNonZeroValue({'c': []}.?c.orValue(dyn({})))]", - "value": { - "listValue": {} - } - }, - { - "name": "optional_chaining_16", - "expr": "optional.ofNonZeroValue({?'nested_map': optional.ofNonZeroValue({?'map': optional.of({}).?c})}).hasValue()", - "value": { - "boolValue": false - } - }, - { - "name": "has_optional_ofNonZeroValue_struct_optional_ofNonZeroValue_map_optindex_field", - "expr": "has(TestAllTypes{?single_double_wrapper: optional.ofNonZeroValue(0.0)}.single_double_wrapper)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "optional_ofNonZeroValue_struct_optional_ofNonZeroValue_map_optindex_field", - "expr": "optional.ofNonZeroValue(TestAllTypes{?single_double_wrapper: optional.ofNonZeroValue(0.0)}).hasValue()", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "struct_map_optindex_field", - "expr": "TestAllTypes{?map_string_string: {'nested': {}}[?'nested']}.map_string_string", - "container": "cel.expr.conformance.proto2", - "value": { - "mapValue": {} - } - }, - { - "name": "struct_optional_ofNonZeroValue_map_optindex_field", - "expr": "TestAllTypes{?map_string_string: optional.ofNonZeroValue({'nested': {}}[?'nested'].orValue({}))}.map_string_string", - "container": "cel.expr.conformance.proto2", - "value": { - "mapValue": {} - } - }, - { - "name": "struct_map_optindex_field_nested", - "expr": "TestAllTypes{?map_string_string: {'nested': {'hello': 'world'}}[?'nested']}.map_string_string", - "container": "cel.expr.conformance.proto2", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "hello" - }, - "value": { - "stringValue": "world" - } - } - ] - } - } - }, - { - "name": "struct_list_optindex_field", - "expr": "TestAllTypes{repeated_string: ['greetings', ?{'nested': {'hello': 'world'}}.nested.?hello]}.repeated_string", - "container": "cel.expr.conformance.proto2", - "value": { - "listValue": { - "values": [ - { - "stringValue": "greetings" - }, - { - "stringValue": "world" - } - ] - } - } - }, - { - "name": "optional_empty_map_optindex_hasValue", - "expr": "optional.of({}).?c.hasValue()", - "value": { - "boolValue": false - } - }, - { - "name": "empty_struct_optindex_hasValue", - "expr": "TestAllTypes{}.?repeated_string.hasValue()", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "optional_empty_struct_optindex_hasValue", - "expr": "optional.of(TestAllTypes{}).?repeated_string.hasValue()", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "optional_none_optselect_hasValue", - "expr": "optional.none().?repeated_string.hasValue()", - "value": { - "boolValue": false - } - }, - { - "name": "struct_optindex_value", - "expr": "TestAllTypes{repeated_string: ['foo']}.?repeated_string.value()", - "container": "cel.expr.conformance.proto2", - "value": { - "listValue": { - "values": [ - { - "stringValue": "foo" - } - ] - } - } - }, - { - "name": "optional_struct_optindex_value", - "expr": "optional.of(TestAllTypes{repeated_string: ['foo']}).?repeated_string.value()", - "container": "cel.expr.conformance.proto2", - "value": { - "listValue": { - "values": [ - { - "stringValue": "foo" - } - ] - } - } - }, - { - "name": "optional_struct_optindex_index_value", - "expr": "optional.of(TestAllTypes{repeated_string: ['foo']}).?repeated_string[0].value()", - "container": "cel.expr.conformance.proto2", - "value": { - "stringValue": "foo" - } - }, - { - "name": "empty_list_optindex_hasValue", - "expr": "[][?0].hasValue()", - "value": { - "boolValue": false - } - }, - { - "name": "optional_empty_list_optindex_hasValue", - "expr": "optional.of([])[?0].hasValue()", - "value": { - "boolValue": false - } - }, - { - "name": "optional_none_optindex_hasValue", - "expr": "optional.none()[?0].hasValue()", - "value": { - "boolValue": false - } - }, - { - "name": "list_optindex_value", - "expr": "['foo'][?0].value()", - "value": { - "stringValue": "foo" - } - }, - { - "name": "optional_list_optindex_value", - "expr": "optional.of(['foo'])[?0].value()", - "value": { - "stringValue": "foo" - } - }, - { - "name": "map_key_mixed_type_optindex_value", - "expr": "{true: 1, 2: 2, 5u: 3}[?true].value()", - "value": { - "int64Value": "1" - } - }, - { - "name": "map_key_mixed_numbers_double_key_optindex_value", - "expr": "{1u: 1.0, 2: 2.0, 3u: 3.0}[?3.0].value()", - "value": { - "doubleValue": 3 - } - }, - { - "name": "map_key_mixed_numbers_uint_key_optindex_value", - "expr": "{1u: 1.0, 2: 2.0, 3u: 3.0}[?2u].value()", - "value": { - "doubleValue": 2 - } - }, - { - "name": "map_key_mixed_numbers_int_key_optindex_value", - "expr": "{1u: 1.0, 2: 2.0, 3u: 3.0}[?1].value()", - "value": { - "doubleValue": 1 - } - }, - { - "name": "optional_eq_none_none", - "expr": "optional.none() == optional.none()", - "value": { - "boolValue": true - } - }, - { - "name": "optional_eq_none_int", - "expr": "optional.none() == optional.of(1)", - "value": { - "boolValue": false - } - }, - { - "name": "optional_eq_int_none", - "expr": "optional.of(1) == optional.none()", - "value": { - "boolValue": false - } - }, - { - "name": "optional_eq_int_int", - "expr": "optional.of(1) == optional.of(1)", - "value": { - "boolValue": true - } - }, - { - "name": "optional_ne_none_none", - "expr": "optional.none() != optional.none()", - "value": { - "boolValue": false - } - }, - { - "name": "optional_ne_none_int", - "expr": "optional.none() != optional.of(1)", - "value": { - "boolValue": true - } - }, - { - "name": "optional_ne_int_none", - "expr": "optional.of(1) != optional.none()", - "value": { - "boolValue": true - } - }, - { - "name": "optional_ne_int_int", - "expr": "optional.of(1) != optional.of(1)", - "value": { - "boolValue": false - } - }, - { - "name": "map_optional_has", - "expr": "has({'foo': optional.none()}.foo)", - "value": { - "boolValue": true - } - }, - { - "name": "map_optional_select_has", - "expr": "has({'foo': optional.none()}.foo.bar)", - "value": { - "boolValue": false - } - }, - { - "name": "map_optional_entry_has", - "expr": "has({?'foo': optional.none()}.foo)", - "value": { - "boolValue": false - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/parse.json b/packages/cel-spec/src/testdata/json/parse.json deleted file mode 100644 index ad6d58f5..00000000 --- a/packages/cel-spec/src/testdata/json/parse.json +++ /dev/null @@ -1,1783 +0,0 @@ -{ - "name": "parse", - "description": "End-to-end parsing tests.", - "section": [ - { - "name": "nest", - "description": "Deep parse trees which all implementations must support.", - "test": [ - { - "name": "list_index", - "description": "Member = Member '[' Expr ']'. Nested indices are supported up to 12 times.", - "expr": "a[a[a[a[a[a[a[a[a[a[a[a[0]]]]]]]]]]]]", - "typeEnv": [ - { - "name": "a", - "ident": { - "type": { - "listType": { - "elemType": { - "primitive": "INT64" - } - } - } - } - } - ], - "bindings": { - "a": { - "value": { - "listValue": { - "values": [ - { - "int64Value": "0" - } - ] - } - } - } - }, - "value": { - "int64Value": "0" - } - }, - { - "name": "message_literal", - "description": "Member = Member '{' [FieldInits] '}'. Nested messages supported up to 12 levels deep.", - "expr": "NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{payload: TestAllTypes{single_int64: 137}}}}}}}}}}}}.payload.single_int64", - "container": "cel.expr.conformance.proto3", - "value": { - "int64Value": "0" - } - }, - { - "name": "funcall", - "description": "Primary = ['.'] IDENT ['(' [ExprList] ')']. Nested function calls supported up to 12 levels deep.", - "expr": "int(uint(int(uint(int(uint(int(uint(int(uint(int(uint(7))))))))))))", - "value": { - "int64Value": "7" - } - }, - { - "name": "list_literal", - "description": "Primary = '[' [ExprList] ']'. Nested list literals up to 12 levels deep.", - "expr": "size([[[[[[[[[[[[0]]]]]]]]]]]])", - "value": { - "int64Value": "1" - } - }, - { - "name": "map_literal", - "description": "Primary = '{' [MapInits] '}'. Nested map literals up to 12 levels deep.", - "expr": "size({0: {0: {0: {0: {0: {0: {0: {0: {0: {0: {0: {0: 'foo'}}}}}}}}}}}})", - "value": { - "int64Value": "1" - } - }, - { - "name": "parens", - "description": "Primary = '(' Expr ')'", - "expr": "((((((((((((((((((((((((((((((((7))))))))))))))))))))))))))))))))", - "value": { - "int64Value": "7" - } - } - ] - }, - { - "name": "repeat", - "description": "Repetitive parse trees which all implementations must support.", - "test": [ - { - "name": "conditional", - "description": "Expr = ConditionalOr ['?' ConditionalOr ':' Expr]. Chained ternary operators up to 24 levels.", - "expr": "true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : false", - "value": { - "boolValue": true - } - }, - { - "name": "or", - "description": "ConditionalOr = [ConditionalOr '||'] ConditionalAnd. Logical OR statements with 32 conditions.", - "expr": "false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || true", - "value": { - "boolValue": true - } - }, - { - "name": "and", - "description": "ConditionalAnd = [ConditionalAnd '&&'] Relation. Logical AND statements with 32 conditions.", - "expr": "true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && false", - "value": { - "boolValue": false - } - }, - { - "name": "add_sub", - "description": "Addition = [Addition ('+' | '-')] Multiplication. Addition operators are supported up to 24 times consecutively.", - "expr": "3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3", - "value": { - "int64Value": "3" - } - }, - { - "name": "mul_div", - "description": "Multiplication = [Multiplication ('*' | '/' | '%')] Unary. Multiplication operators are supported up to 24 times consecutively.", - "expr": "4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4", - "value": { - "int64Value": "4" - } - }, - { - "name": "not", - "description": "Unary = '!' {'!'} Member", - "expr": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!true", - "value": { - "boolValue": true - } - }, - { - "name": "unary_neg", - "description": "Unary = '-' {'-'} Member", - "expr": "--------------------------------19", - "value": { - "int64Value": "19" - } - }, - { - "name": "select", - "description": "Member = Member '.' IDENT ['(' [ExprList] ')']. Selection is supported up to 12 times consecutively.", - "expr": "NestedTestAllTypes{}.child.child.child.child.child.child.child.child.child.child.payload.single_int32", - "container": "cel.expr.conformance.proto3", - "value": { - "int64Value": "0" - } - }, - { - "name": "index", - "description": "Member = Member '[' Expr ']'. Indexing is supported up to 12 times consecutively.", - "expr": "[[[[[[[[[[[['foo']]]]]]]]]]]][0][0][0][0][0][0][0][0][0][0][0][0]", - "value": { - "stringValue": "foo" - } - }, - { - "name": "list_literal", - "description": "Primary = '[' [ExprList] ']'. List literals with up to 32 elements.", - "expr": "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31][17]", - "value": { - "int64Value": "17" - } - }, - { - "name": "map_literal", - "description": "Primary = '{' [MapInits] '}'. Map literals with up to 32 entries.", - "expr": "{0: 'zero', 1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten', 11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', 15: 'fifteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 19: 'nineteen', 20: 'twenty', 21: 'twenty-one', 22: 'twenty-two', 23: 'twenty-three', 24: 'twenty-four', 25: 'twenty-five', 26: 'twenty-six', 27: 'twenty-seven', 28: 'twenty-eight', 29: 'twenty-nine', 30: 'thirty', 31: 'thirty-one'}[17]", - "value": { - "stringValue": "seventeen" - } - }, - { - "name": "message_literal", - "description": "Member = Member '{' [FieldInits] '}'. Message literals with up to 32 fields.", - "expr": "TestAllTypes{single_int32: 5, single_int64: 10, single_uint32: 15u, single_uint64: 20u, single_sint32: 25, single_sint64: 30, single_fixed32: 35u, single_fixed64: 40u, single_float: 45.0, single_double: 50.0, single_bool: true, single_string: 'sixty', single_bytes: b'sixty-five', single_value: 70.0, single_int64_wrapper: 75, single_int32_wrapper: 80, single_double_wrapper: 85.0, single_float_wrapper: 90.0, single_uint64_wrapper: 95u, single_uint32_wrapper: 100u, single_string_wrapper: 'one hundred five', single_bool_wrapper: true, repeated_int32: [115], repeated_int64: [120], repeated_uint32: [125u], repeated_uint64: [130u], repeated_sint32: [135], repeated_sint64: [140], repeated_fixed32: [145u], repeated_fixed64: [150u], repeated_sfixed32: [155], repeated_float: [160.0]}.single_sint64", - "container": "cel.expr.conformance.proto3", - "value": { - "int64Value": "30" - } - } - ] - }, - { - "name": "string_literals", - "description": "Check that string literals are properly parsed", - "test": [ - { - "name": "single_quoted", - "expr": "'hello'", - "value": { - "stringValue": "hello" - } - }, - { - "name": "double_quoted", - "expr": "\"hello\"", - "value": { - "stringValue": "hello" - } - }, - { - "name": "triple_single_quoted", - "expr": "'''hello'''", - "value": { - "stringValue": "hello" - } - }, - { - "name": "triple_double_quoted", - "expr": "\"\"\"hello\"\"\"", - "value": { - "stringValue": "hello" - } - }, - { - "name": "single_quoted_escaped_punctuation", - "expr": "' \\\\ \\? \\\" \\' \\` '", - "value": { - "stringValue": " \\ ? \" ' ` " - } - }, - { - "name": "double_quoted_escaped_punctuation", - "expr": "\" \\\\ \\? \\\" \\' \\` \"", - "value": { - "stringValue": " \\ ? \" ' ` " - } - }, - { - "name": "triple_single_quoted_escaped_punctuation", - "expr": "''' \\\\ \\? \\\" \\' \\` '''", - "value": { - "stringValue": " \\ ? \" ' ` " - } - }, - { - "name": "triple_double_quoted_escaped_punctuation", - "expr": "\"\"\" \\\\ \\? \\\" \\' \\` \"\"\"", - "value": { - "stringValue": " \\ ? \" ' ` " - } - }, - { - "name": "triple_single_quoted_unescaped_punctuation", - "expr": "''' ? \" ' ` '''", - "value": { - "stringValue": " ? \" ' ` " - } - }, - { - "name": "triple_double_quoted_unescaped_punctuation", - "expr": "\"\"\" ? \" ' ` \"\"\"", - "value": { - "stringValue": " ? \" ' ` " - } - }, - { - "name": "single_quoted_escaped_special_control_characters", - "expr": "' \\a \\b \\f \\t \\v '", - "value": { - "stringValue": " \u0007 \b \f \t \u000b " - } - }, - { - "name": "double_quoted_escaped_special_control_characters", - "expr": "\" \\a \\b \\f \\t \\v \"", - "value": { - "stringValue": " \u0007 \b \f \t \u000b " - } - }, - { - "name": "single_quoted_unescaped_special_control_characters", - "expr": "' \u0007 \b \f \t \u000b '", - "value": { - "stringValue": " \u0007 \b \f \t \u000b " - } - }, - { - "name": "double_quoted_unescaped_special_control_characters", - "expr": "\" \u0007 \b \f \t \u000b \"", - "value": { - "stringValue": " \u0007 \b \f \t \u000b " - } - }, - { - "name": "triple_single_quoted_escaped_special_control_characters", - "expr": "''' \\a \\b \\f \\t \\v '''", - "value": { - "stringValue": " \u0007 \b \f \t \u000b " - } - }, - { - "name": "triple_double_quoted_escaped_special_control_characters", - "expr": "\"\"\" \\a \\b \\f \\t \\v \"\"\"", - "value": { - "stringValue": " \u0007 \b \f \t \u000b " - } - }, - { - "name": "triple_single_quoted_unescaped_special_control_characters", - "expr": "''' \u0007 \b \f \t \u000b '''", - "value": { - "stringValue": " \u0007 \b \f \t \u000b " - } - }, - { - "name": "triple_double_quoted_unescaped_special_control_characters", - "expr": "\"\"\" \u0007 \b \f \t \u000b \"\"\"", - "value": { - "stringValue": " \u0007 \b \f \t \u000b " - } - }, - { - "name": "single_quoted_escaped_line_feed", - "expr": "' \\n '", - "value": { - "stringValue": " \n " - } - }, - { - "name": "double_quoted_escaped_line_feed", - "expr": "\" \\n \"", - "value": { - "stringValue": " \n " - } - }, - { - "name": "triple_single_quoted_escaped_line_feed", - "expr": "''' \\n '''", - "value": { - "stringValue": " \n " - } - }, - { - "name": "triple_double_quoted_escaped_line_feed", - "expr": "\"\"\" \\n \"\"\"", - "value": { - "stringValue": " \n " - } - }, - { - "name": "triple_single_quoted_unescaped_line_feed", - "expr": "''' \n '''", - "value": { - "stringValue": " \n " - } - }, - { - "name": "triple_double_quoted_unescaped_line_feed", - "expr": "\"\"\" \n \"\"\"", - "value": { - "stringValue": " \n " - } - }, - { - "name": "single_quoted_escaped_carriage_return", - "expr": "' \\r '", - "value": { - "stringValue": " \r " - } - }, - { - "name": "double_quoted_escaped_carriage_return", - "expr": "\" \\r \"", - "value": { - "stringValue": " \r " - } - }, - { - "name": "triple_single_quoted_escaped_carriage_return", - "expr": "''' \\r '''", - "value": { - "stringValue": " \r " - } - }, - { - "name": "triple_double_quoted_escaped_carriage_return", - "expr": "\"\"\" \\r \"\"\"", - "value": { - "stringValue": " \r " - } - }, - { - "name": "single_quoted_escaped_windows_line_end", - "expr": "' \\r\\n '", - "value": { - "stringValue": " \r\n " - } - }, - { - "name": "double_quoted_escaped_windows_line_end", - "expr": "\" \\r\\n \"", - "value": { - "stringValue": " \r\n " - } - }, - { - "name": "triple_single_quoted_escaped_windows_line_end", - "expr": "''' \\r\\n '''", - "value": { - "stringValue": " \r\n " - } - }, - { - "name": "triple_double_quoted_escaped_windows_line_end", - "expr": "\"\"\" \\r\\n \"\"\"", - "value": { - "stringValue": " \r\n " - } - }, - { - "name": "single_quoted_escaped_all_control_characters", - "expr": "' \\x01 \\x02 \\x03 \\x04 \\x05 \\x06 \\x07 \\x08 \\x09 \\x0B \\x0C \\x0E \\x0F \\x10 \\x11 \\x12 \\x13 \\x14 \\x15 \\x16 \\x17 \\x18 \\x19 \\x1A \\x1B \\x1C \\x1D \\x1E \\x1f \\x7F '", - "value": { - "stringValue": " \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t \u000b \f \u000e \u000f \u0010 \u0011 \u0012 \u0013 \u0014 \u0015 \u0016 \u0017 \u0018 \u0019 \u001a \u001b \u001c \u001d \u001e \u001f  " - } - }, - { - "name": "double_quoted_escaped_all_control_characters", - "expr": "\" \\x01 \\x02 \\x03 \\x04 \\x05 \\x06 \\x07 \\x08 \\x09 \\x0B \\x0C \\x0E \\x0F \\x10 \\x11 \\x12 \\x13 \\x14 \\x15 \\x16 \\x17 \\x18 \\x19 \\x1A \\x1B \\x1C \\x1D \\x1E \\x1f \\x7F \"", - "value": { - "stringValue": " \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t \u000b \f \u000e \u000f \u0010 \u0011 \u0012 \u0013 \u0014 \u0015 \u0016 \u0017 \u0018 \u0019 \u001a \u001b \u001c \u001d \u001e \u001f  " - } - }, - { - "name": "single_quoted_unescaped_all_control_characters", - "expr": "' \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t \u000b \f \u000e \u000f \u0010 \u0011 \u0012 \u0013 \u0014 \u0015 \u0016 \u0017 \u0018 \u0019 \u001a \u001b \u001c \u001d \u001e \u001f  '", - "value": { - "stringValue": " \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t \u000b \f \u000e \u000f \u0010 \u0011 \u0012 \u0013 \u0014 \u0015 \u0016 \u0017 \u0018 \u0019 \u001a \u001b \u001c \u001d \u001e \u001f  " - } - }, - { - "name": "double_quoted_unescaped_all_control_characters", - "expr": "\" \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t \u000b \f \u000e \u000f \u0010 \u0011 \u0012 \u0013 \u0014 \u0015 \u0016 \u0017 \u0018 \u0019 \u001a \u001b \u001c \u001d \u001e \u001f  \"", - "value": { - "stringValue": " \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t \u000b \f \u000e \u000f \u0010 \u0011 \u0012 \u0013 \u0014 \u0015 \u0016 \u0017 \u0018 \u0019 \u001a \u001b \u001c \u001d \u001e \u001f  " - } - }, - { - "name": "triple_single_quoted_escaped_all_control_characters", - "expr": "''' \\x01 \\x02 \\x03 \\x04 \\x05 \\x06 \\x07 \\x08 \\x09 \\x0B \\x0C \\x0E \\x0F \\x10 \\x11 \\x12 \\x13 \\x14 \\x15 \\x16 \\x17 \\x18 \\x19 \\x1A \\x1B \\x1C \\x1D \\x1E \\x1f \\x7F '''", - "value": { - "stringValue": " \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t \u000b \f \u000e \u000f \u0010 \u0011 \u0012 \u0013 \u0014 \u0015 \u0016 \u0017 \u0018 \u0019 \u001a \u001b \u001c \u001d \u001e \u001f  " - } - }, - { - "name": "triple_double_quoted_escaped_all_control_characters", - "expr": "\"\"\" \\x01 \\x02 \\x03 \\x04 \\x05 \\x06 \\x07 \\x08 \\x09 \\x0B \\x0C \\x0E \\x0F \\x10 \\x11 \\x12 \\x13 \\x14 \\x15 \\x16 \\x17 \\x18 \\x19 \\x1A \\x1B \\x1C \\x1D \\x1E \\x1f \\x7F \"\"\"", - "value": { - "stringValue": " \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t \u000b \f \u000e \u000f \u0010 \u0011 \u0012 \u0013 \u0014 \u0015 \u0016 \u0017 \u0018 \u0019 \u001a \u001b \u001c \u001d \u001e \u001f  " - } - }, - { - "name": "triple_single_quoted_unescaped_all_control_characters", - "expr": "''' \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t \u000b \f \u000e \u000f \u0010 \u0011 \u0012 \u0013 \u0014 \u0015 \u0016 \u0017 \u0018 \u0019 \u001a \u001b \u001c \u001d \u001e \u001f  '''", - "value": { - "stringValue": " \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t \u000b \f \u000e \u000f \u0010 \u0011 \u0012 \u0013 \u0014 \u0015 \u0016 \u0017 \u0018 \u0019 \u001a \u001b \u001c \u001d \u001e \u001f  " - } - }, - { - "name": "triple_double_quoted_unescaped_all_control_characters", - "expr": "\"\"\" \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t \u000b \f \u000e \u000f \u0010 \u0011 \u0012 \u0013 \u0014 \u0015 \u0016 \u0017 \u0018 \u0019 \u001a \u001b \u001c \u001d \u001e \u001f  \"\"\"", - "value": { - "stringValue": " \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t \u000b \f \u000e \u000f \u0010 \u0011 \u0012 \u0013 \u0014 \u0015 \u0016 \u0017 \u0018 \u0019 \u001a \u001b \u001c \u001d \u001e \u001f  " - } - }, - { - "name": "single_quoted_octal_escapes", - "expr": "' \\000 \\012 \\177 '", - "value": { - "stringValue": " \u0000 \n  " - } - }, - { - "name": "double_quoted_octal_escapes", - "expr": "\" \\000 \\012 \\177 \"", - "value": { - "stringValue": " \u0000 \n  " - } - }, - { - "name": "triple_single_quoted_octal_escapes", - "expr": "''' \\000 \\012 \\177 '''", - "value": { - "stringValue": " \u0000 \n  " - } - }, - { - "name": "triple_double_quoted_octal_escapes", - "expr": "\"\"\" \\000 \\012 \\177 \"\"\"", - "value": { - "stringValue": " \u0000 \n  " - } - }, - { - "name": "single_quoted_lower_x_escapes", - "expr": "' \\x00 \\x0A \\x7F '", - "value": { - "stringValue": " \u0000 \n  " - } - }, - { - "name": "double_quoted_lower_x_escapes", - "expr": "\" \\x00 \\x0A \\x7F \"", - "value": { - "stringValue": " \u0000 \n  " - } - }, - { - "name": "triple_single_quoted_lower_x_escapes", - "expr": "''' \\x00 \\x0A \\x7F '''", - "value": { - "stringValue": " \u0000 \n  " - } - }, - { - "name": "triple_double_quoted_lower_x_escapes", - "expr": "\"\"\" \\x00 \\x0A \\x7F \"\"\"", - "value": { - "stringValue": " \u0000 \n  " - } - }, - { - "name": "single_quoted_upper_x_escapes", - "expr": "' \\X00 \\X0A \\X7F '", - "value": { - "stringValue": " \u0000 \n  " - } - }, - { - "name": "double_quoted_upper_x_escapes", - "expr": "\" \\X00 \\X0A \\X7F \"", - "value": { - "stringValue": " \u0000 \n  " - } - }, - { - "name": "triple_single_quoted_upper_x_escapes", - "expr": "''' \\X00 \\X0A \\X7F '''", - "value": { - "stringValue": " \u0000 \n  " - } - }, - { - "name": "triple_double_quoted_upper_x_escapes", - "expr": "\"\"\" \\X00 \\X0A \\X7F \"\"\"", - "value": { - "stringValue": " \u0000 \n  " - } - }, - { - "name": "single_quoted_lower_u_escapes", - "expr": "' \\u0000 \\u000A \\u007F \\u0100 \\uFFFB '", - "value": { - "stringValue": " \u0000 \n  Ā  " - } - }, - { - "name": "double_quoted_lower_u_escapes", - "expr": "\" \\u0000 \\u000A \\u007F \\u0100 \\uFFFB \"", - "value": { - "stringValue": " \u0000 \n  Ā  " - } - }, - { - "name": "triple_single_quoted_lower_u_escapes", - "expr": "''' \\u0000 \\u000A \\u007F \\u0100 \\uFFFB '''", - "value": { - "stringValue": " \u0000 \n  Ā  " - } - }, - { - "name": "triple_double_quoted_lower_u_escapes", - "expr": "\"\"\" \\u0000 \\u000A \\u007F \\u0100 \\uFFFB \"\"\"", - "value": { - "stringValue": " \u0000 \n  Ā  " - } - }, - { - "name": "single_quoted_upper_u_escapes", - "expr": "' \\U00000000 \\U0000000A \\U0000007F \\U00000100 \\U0000FFFB \\U00010000 \\U0001F62C '", - "value": { - "stringValue": " \u0000 \n  Ā  𐀀 😬 " - } - }, - { - "name": "double_quoted_upper_u_escapes", - "expr": "\" \\U00000000 \\U0000000A \\U0000007F \\U00000100 \\U0000FFFB \\U00010000 \\U0001F62C \"", - "value": { - "stringValue": " \u0000 \n  Ā  𐀀 😬 " - } - }, - { - "name": "triple_single_quoted_upper_u_escapes", - "expr": "''' \\U00000000 \\U0000000A \\U0000007F \\U00000100 \\U0000FFFB \\U00010000 \\U0001F62C '''", - "value": { - "stringValue": " \u0000 \n  Ā  𐀀 😬 " - } - }, - { - "name": "triple_double_quoted_upper_u_escapes", - "expr": "\"\"\" \\U00000000 \\U0000000A \\U0000007F \\U00000100 \\U0000FFFB \\U00010000 \\U0001F62C \"\"\"", - "value": { - "stringValue": " \u0000 \n  Ā  𐀀 😬 " - } - }, - { - "name": "mixed_case_hex_single_quoted_escapes", - "expr": "' \\x4a \\x4B \\X4c \\X4D \\u01aB \\U000001aB '", - "value": { - "stringValue": " J K L M ƫ ƫ " - } - }, - { - "name": "mixed_case_hex_double_quoted_escapes", - "expr": "\" \\x4a \\x4B \\X4c \\X4D \\u01aB \\U000001aB \"", - "value": { - "stringValue": " J K L M ƫ ƫ " - } - }, - { - "name": "mixed_case_hex_triple_single_quoted_escapes", - "expr": "''' \\x4a \\x4B \\X4c \\X4D \\u01aB \\U000001aB '''", - "value": { - "stringValue": " J K L M ƫ ƫ " - } - }, - { - "name": "mixed_case_hex_triple_double_quoted_escapes", - "expr": "\"\"\" \\x4a \\x4B \\X4c \\X4D \\u01aB \\U000001aB \"\"\"", - "value": { - "stringValue": " J K L M ƫ ƫ " - } - }, - { - "name": "unassigned_code_point_single_quoted_escapes", - "expr": "' \\U00088888 '", - "value": { - "stringValue": " 򈢈 " - } - }, - { - "name": "unassigned_code_point_double_quoted_escapes", - "expr": "\" \\U00088888 \"", - "value": { - "stringValue": " 򈢈 " - } - }, - { - "name": "unassigned_code_point_triple_single_quoted_escapes", - "expr": "''' \\U00088888 '''", - "value": { - "stringValue": " 򈢈 " - } - }, - { - "name": "unassigned_code_point_triple_double_quoted_escapes", - "expr": "\"\"\" \\U00088888 \"\"\"", - "value": { - "stringValue": " 򈢈 " - } - }, - { - "name": "unassigned_code_point_single_quoted_unescaped", - "expr": "' 򈢈 '", - "value": { - "stringValue": " 򈢈 " - } - }, - { - "name": "unassigned_code_point_double_quoted_unescaped", - "expr": "\" 򈢈 \"", - "value": { - "stringValue": " 򈢈 " - } - }, - { - "name": "unassigned_code_point_triple_single_quoted_unescaped", - "expr": "''' 򈢈 '''", - "value": { - "stringValue": " 򈢈 " - } - }, - { - "name": "unassigned_code_point_triple_double_quoted_unescaped", - "expr": "\"\"\" 򈢈 \"\"\"", - "value": { - "stringValue": " 򈢈 " - } - }, - { - "name": "raw_single_quoted_escapes", - "expr": "r' \\\\ \\? \\\" \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 '", - "value": { - "stringValue": " \\\\ \\? \\\" \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " - } - }, - { - "name": "raw_double_quoted_escapes", - "expr": "r\" \\\\ \\? \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 \"", - "value": { - "stringValue": " \\\\ \\? \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " - } - }, - { - "name": "raw_triple_single_quoted_escapes", - "expr": "r''' \\\\ \\? \\\" \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 '''", - "value": { - "stringValue": " \\\\ \\? \\\" \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " - } - }, - { - "name": "raw_triple_double_quoted_escapes", - "expr": "r\"\"\" \\\\ \\? \\\" \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 \"\"\"", - "value": { - "stringValue": " \\\\ \\? \\\" \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " - } - }, - { - "name": "upper_raw_single_quoted_escapes", - "expr": "R' \\\\ \\? \\\" \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 '", - "value": { - "stringValue": " \\\\ \\? \\\" \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " - } - }, - { - "name": "upper_raw_double_quoted_escapes", - "expr": "R\" \\\\ \\? \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 \"", - "value": { - "stringValue": " \\\\ \\? \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " - } - }, - { - "name": "upper_raw_triple_single_quoted_escapes", - "expr": "R''' \\\\ \\? \\\" \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 '''", - "value": { - "stringValue": " \\\\ \\? \\\" \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " - } - }, - { - "name": "upper_raw_triple_double_quoted_escapes", - "expr": "R\"\"\" \\\\ \\? \\\" \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 \"\"\"", - "value": { - "stringValue": " \\\\ \\? \\\" \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " - } - } - ] - }, - { - "name": "bytes_literals", - "description": "Check that bytes literals are properly parsed", - "test": [ - { - "name": "single_quoted", - "expr": "b'hello'", - "value": { - "bytesValue": "aGVsbG8=" - } - }, - { - "name": "double_quoted", - "expr": "b\"hello\"", - "value": { - "bytesValue": "aGVsbG8=" - } - }, - { - "name": "triple_single_quoted", - "expr": "b'''hello'''", - "value": { - "bytesValue": "aGVsbG8=" - } - }, - { - "name": "triple_double_quoted", - "expr": "b\"\"\"hello\"\"\"", - "value": { - "bytesValue": "aGVsbG8=" - } - }, - { - "name": "single_quoted_escaped_punctuation", - "expr": "b' \\\\ \\? \\\" \\' \\` '", - "value": { - "bytesValue": "IFwgPyAiICcgYCA=" - } - }, - { - "name": "double_quoted_escaped_punctuation", - "expr": "b\" \\\\ \\? \\\" \\' \\` \"", - "value": { - "bytesValue": "IFwgPyAiICcgYCA=" - } - }, - { - "name": "triple_single_quoted_escaped_punctuation", - "expr": "b''' \\\\ \\? \\\" \\' \\` '''", - "value": { - "bytesValue": "IFwgPyAiICcgYCA=" - } - }, - { - "name": "triple_double_quoted_escaped_punctuation", - "expr": "b\"\"\" \\\\ \\? \\\" \\' \\` \"\"\"", - "value": { - "bytesValue": "IFwgPyAiICcgYCA=" - } - }, - { - "name": "triple_single_quoted_unescaped_punctuation", - "expr": "b''' ? \" ' ` '''", - "value": { - "bytesValue": "ID8gIiAnIGAg" - } - }, - { - "name": "triple_double_quoted_unescaped_punctuation", - "expr": "b\"\"\" ? \" ' ` \"\"\"", - "value": { - "bytesValue": "ID8gIiAnIGAg" - } - }, - { - "name": "single_quoted_escaped_special_control_characters", - "expr": "b' \\a \\b \\f \\t \\v '", - "value": { - "bytesValue": "IAcgCCAMIAkgCyA=" - } - }, - { - "name": "double_quoted_escaped_special_control_characters", - "expr": "b\" \\a \\b \\f \\t \\v \"", - "value": { - "bytesValue": "IAcgCCAMIAkgCyA=" - } - }, - { - "name": "single_quoted_unescaped_special_control_characters", - "expr": "b' \u0007 \b \f \t \u000b '", - "value": { - "bytesValue": "IAcgCCAMIAkgCyA=" - } - }, - { - "name": "double_quoted_unescaped_special_control_characters", - "expr": "b\" \u0007 \b \f \t \u000b \"", - "value": { - "bytesValue": "IAcgCCAMIAkgCyA=" - } - }, - { - "name": "triple_single_quoted_escaped_special_control_characters", - "expr": "b''' \\a \\b \\f \\t \\v '''", - "value": { - "bytesValue": "IAcgCCAMIAkgCyA=" - } - }, - { - "name": "triple_double_quoted_escaped_special_control_characters", - "expr": "b\"\"\" \\a \\b \\f \\t \\v \"\"\"", - "value": { - "bytesValue": "IAcgCCAMIAkgCyA=" - } - }, - { - "name": "triple_single_quoted_unescaped_special_control_characters", - "expr": "b''' \u0007 \b \f \t \u000b '''", - "value": { - "bytesValue": "IAcgCCAMIAkgCyA=" - } - }, - { - "name": "triple_double_quoted_unescaped_special_control_characters", - "expr": "b\"\"\" \u0007 \b \f \t \u000b \"\"\"", - "value": { - "bytesValue": "IAcgCCAMIAkgCyA=" - } - }, - { - "name": "single_quoted_escaped_line_feed", - "expr": "b' \\n '", - "value": { - "bytesValue": "IAog" - } - }, - { - "name": "double_quoted_escaped_line_feed", - "expr": "b\" \\n \"", - "value": { - "bytesValue": "IAog" - } - }, - { - "name": "triple_single_quoted_escaped_line_feed", - "expr": "b''' \\n '''", - "value": { - "bytesValue": "IAog" - } - }, - { - "name": "triple_double_quoted_escaped_line_feed", - "expr": "b\"\"\" \\n \"\"\"", - "value": { - "bytesValue": "IAog" - } - }, - { - "name": "triple_single_quoted_unescaped_line_feed", - "expr": "b''' \n '''", - "value": { - "bytesValue": "IAog" - } - }, - { - "name": "triple_double_quoted_unescaped_line_feed", - "expr": "b\"\"\" \n \"\"\"", - "value": { - "bytesValue": "IAog" - } - }, - { - "name": "single_quoted_escaped_carriage_return", - "expr": "b' \\r '", - "value": { - "bytesValue": "IA0g" - } - }, - { - "name": "double_quoted_escaped_carriage_return", - "expr": "b\" \\r \"", - "value": { - "bytesValue": "IA0g" - } - }, - { - "name": "triple_single_quoted_escaped_carriage_return", - "expr": "b''' \\r '''", - "value": { - "bytesValue": "IA0g" - } - }, - { - "name": "triple_double_quoted_escaped_carriage_return", - "expr": "b\"\"\" \\r \"\"\"", - "value": { - "bytesValue": "IA0g" - } - }, - { - "name": "single_quoted_escaped_windows_line_end", - "expr": "b' \\r\\n '", - "value": { - "bytesValue": "IA0KIA==" - } - }, - { - "name": "double_quoted_escaped_windows_line_end", - "expr": "b\" \\r\\n \"", - "value": { - "bytesValue": "IA0KIA==" - } - }, - { - "name": "triple_single_quoted_escaped_windows_line_end", - "expr": "b''' \\r\\n '''", - "value": { - "bytesValue": "IA0KIA==" - } - }, - { - "name": "triple_double_quoted_escaped_windows_line_end", - "expr": "b\"\"\" \\r\\n \"\"\"", - "value": { - "bytesValue": "IA0KIA==" - } - }, - { - "name": "single_quoted_escaped_all_control_characters", - "expr": "b' \\x01 \\x02 \\x03 \\x04 \\x05 \\x06 \\x07 \\x08 \\x09 \\x0B \\x0C \\x0E \\x0F \\x10 \\x11 \\x12 \\x13 \\x14 \\x15 \\x16 \\x17 \\x18 \\x19 \\x1A \\x1B \\x1C \\x1D \\x1E \\x1f \\x7F '", - "value": { - "bytesValue": "IAEgAiADIAQgBSAGIAcgCCAJIAsgDCAOIA8gECARIBIgEyAUIBUgFiAXIBggGSAaIBsgHCAdIB4gHyB/IA==" - } - }, - { - "name": "double_quoted_escaped_all_control_characters", - "expr": "b\" \\x01 \\x02 \\x03 \\x04 \\x05 \\x06 \\x07 \\x08 \\x09 \\x0B \\x0C \\x0E \\x0F \\x10 \\x11 \\x12 \\x13 \\x14 \\x15 \\x16 \\x17 \\x18 \\x19 \\x1A \\x1B \\x1C \\x1D \\x1E \\x1f \\x7F \"", - "value": { - "bytesValue": "IAEgAiADIAQgBSAGIAcgCCAJIAsgDCAOIA8gECARIBIgEyAUIBUgFiAXIBggGSAaIBsgHCAdIB4gHyB/IA==" - } - }, - { - "name": "single_quoted_unescaped_all_control_characters", - "expr": "b' \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t \u000b \f \u000e \u000f \u0010 \u0011 \u0012 \u0013 \u0014 \u0015 \u0016 \u0017 \u0018 \u0019 \u001a \u001b \u001c \u001d \u001e \u001f  '", - "value": { - "bytesValue": "IAEgAiADIAQgBSAGIAcgCCAJIAsgDCAOIA8gECARIBIgEyAUIBUgFiAXIBggGSAaIBsgHCAdIB4gHyB/IA==" - } - }, - { - "name": "double_quoted_unescaped_all_control_characters", - "expr": "b\" \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t \u000b \f \u000e \u000f \u0010 \u0011 \u0012 \u0013 \u0014 \u0015 \u0016 \u0017 \u0018 \u0019 \u001a \u001b \u001c \u001d \u001e \u001f  \"", - "value": { - "bytesValue": "IAEgAiADIAQgBSAGIAcgCCAJIAsgDCAOIA8gECARIBIgEyAUIBUgFiAXIBggGSAaIBsgHCAdIB4gHyB/IA==" - } - }, - { - "name": "triple_single_quoted_escaped_all_control_characters", - "expr": "b''' \\x01 \\x02 \\x03 \\x04 \\x05 \\x06 \\x07 \\x08 \\x09 \\x0B \\x0C \\x0E \\x0F \\x10 \\x11 \\x12 \\x13 \\x14 \\x15 \\x16 \\x17 \\x18 \\x19 \\x1A \\x1B \\x1C \\x1D \\x1E \\x1f \\x7F '''", - "value": { - "bytesValue": "IAEgAiADIAQgBSAGIAcgCCAJIAsgDCAOIA8gECARIBIgEyAUIBUgFiAXIBggGSAaIBsgHCAdIB4gHyB/IA==" - } - }, - { - "name": "triple_double_quoted_escaped_all_control_characters", - "expr": "b\"\"\" \\x01 \\x02 \\x03 \\x04 \\x05 \\x06 \\x07 \\x08 \\x09 \\x0B \\x0C \\x0E \\x0F \\x10 \\x11 \\x12 \\x13 \\x14 \\x15 \\x16 \\x17 \\x18 \\x19 \\x1A \\x1B \\x1C \\x1D \\x1E \\x1f \\x7F \"\"\"", - "value": { - "bytesValue": "IAEgAiADIAQgBSAGIAcgCCAJIAsgDCAOIA8gECARIBIgEyAUIBUgFiAXIBggGSAaIBsgHCAdIB4gHyB/IA==" - } - }, - { - "name": "triple_single_quoted_unescaped_all_control_characters", - "expr": "b''' \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t \u000b \f \u000e \u000f \u0010 \u0011 \u0012 \u0013 \u0014 \u0015 \u0016 \u0017 \u0018 \u0019 \u001a \u001b \u001c \u001d \u001e \u001f  '''", - "value": { - "bytesValue": "IAEgAiADIAQgBSAGIAcgCCAJIAsgDCAOIA8gECARIBIgEyAUIBUgFiAXIBggGSAaIBsgHCAdIB4gHyB/IA==" - } - }, - { - "name": "triple_double_quoted_unescaped_all_control_characters", - "expr": "b\"\"\" \u0001 \u0002 \u0003 \u0004 \u0005 \u0006 \u0007 \b \t \u000b \f \u000e \u000f \u0010 \u0011 \u0012 \u0013 \u0014 \u0015 \u0016 \u0017 \u0018 \u0019 \u001a \u001b \u001c \u001d \u001e \u001f  \"\"\"", - "value": { - "bytesValue": "IAEgAiADIAQgBSAGIAcgCCAJIAsgDCAOIA8gECARIBIgEyAUIBUgFiAXIBggGSAaIBsgHCAdIB4gHyB/IA==" - } - }, - { - "name": "single_quoted_octal_escapes", - "expr": "b' \\000 \\012 \\177 \\377 '", - "value": { - "bytesValue": "IAAgCiB/IP8g" - } - }, - { - "name": "double_quoted_octal_escapes", - "expr": "b\" \\000 \\012 \\177 \\377 \"", - "value": { - "bytesValue": "IAAgCiB/IP8g" - } - }, - { - "name": "triple_single_quoted_octal_escapes", - "expr": "b''' \\000 \\012 \\177 \\377 '''", - "value": { - "bytesValue": "IAAgCiB/IP8g" - } - }, - { - "name": "triple_double_quoted_octal_escapes", - "expr": "b\"\"\" \\000 \\012 \\177 \\377 \"\"\"", - "value": { - "bytesValue": "IAAgCiB/IP8g" - } - }, - { - "name": "single_quoted_lower_x_escapes", - "expr": "b' \\x00 \\x0A \\x7F \\xFF '", - "value": { - "bytesValue": "IAAgCiB/IP8g" - } - }, - { - "name": "double_quoted_lower_x_escapes", - "expr": "b\" \\x00 \\x0A \\x7F \\xFF \"", - "value": { - "bytesValue": "IAAgCiB/IP8g" - } - }, - { - "name": "triple_single_quoted_lower_x_escapes", - "expr": "b''' \\x00 \\x0A \\x7F \\xFF '''", - "value": { - "bytesValue": "IAAgCiB/IP8g" - } - }, - { - "name": "triple_double_quoted_lower_x_escapes", - "expr": "b\"\"\" \\x00 \\x0A \\x7F \\xFF \"\"\"", - "value": { - "bytesValue": "IAAgCiB/IP8g" - } - }, - { - "name": "single_quoted_upper_x_escapes", - "expr": "b' \\X00 \\X0A \\X7F \\XFF '", - "value": { - "bytesValue": "IAAgCiB/IP8g" - } - }, - { - "name": "double_quoted_upper_x_escapes", - "expr": "b\" \\X00 \\X0A \\X7F \\XFF \"", - "value": { - "bytesValue": "IAAgCiB/IP8g" - } - }, - { - "name": "triple_single_quoted_upper_x_escapes", - "expr": "b''' \\X00 \\X0A \\X7F \\XFF '''", - "value": { - "bytesValue": "IAAgCiB/IP8g" - } - }, - { - "name": "triple_double_quoted_upper_x_escapes", - "expr": "b\"\"\" \\X00 \\X0A \\X7F \\XFF \"\"\"", - "value": { - "bytesValue": "IAAgCiB/IP8g" - } - }, - { - "name": "mixed_case_hex_single_quoted_escapes", - "expr": "B' \\x4a \\x4B \\X4c \\X4D '", - "value": { - "bytesValue": "IEogSyBMIE0g" - } - }, - { - "name": "mixed_case_hex_double_quoted_escapes", - "expr": "B\" \\x4a \\x4B \\X4c \\X4D \"", - "value": { - "bytesValue": "IEogSyBMIE0g" - } - }, - { - "name": "mixed_case_hex_triple_single_quoted_escapes", - "expr": "B''' \\x4a \\x4B \\X4c \\X4D '''", - "value": { - "bytesValue": "IEogSyBMIE0g" - } - }, - { - "name": "mixed_case_hex_triple_double_quoted_escapes", - "expr": "B\"\"\" \\x4a \\x4B \\X4c \\X4D \"\"\"", - "value": { - "bytesValue": "IEogSyBMIE0g" - } - }, - { - "name": "raw_single_quoted_escapes", - "expr": "br' \\\\ \\? \\\" \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 '", - "value": { - "bytesValue": "IFxcIFw/IFwiIFxgIFxhIFxiIFxmIFx0IFx2IFxuIFxyIFwwMDAgXHgwMCBcWDAwIFx1MDAwMCBcVTAwMDAwMDAwIA==" - } - }, - { - "name": "raw_double_quoted_escapes", - "expr": "br\" \\\\ \\? \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 \"", - "value": { - "bytesValue": "IFxcIFw/IFwnIFxgIFxhIFxiIFxmIFx0IFx2IFxuIFxyIFwwMDAgXHgwMCBcWDAwIFx1MDAwMCBcVTAwMDAwMDAwIA==" - } - }, - { - "name": "raw_triple_single_quoted_escapes", - "expr": "br''' \\\\ \\? \\\" \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 '''", - "value": { - "bytesValue": "IFxcIFw/IFwiIFwnIFxgIFxhIFxiIFxmIFx0IFx2IFxuIFxyIFwwMDAgXHgwMCBcWDAwIFx1MDAwMCBcVTAwMDAwMDAwIA==" - } - }, - { - "name": "raw_triple_double_quoted_escapes", - "expr": "br\"\"\" \\\\ \\? \\\" \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 \"\"\"", - "value": { - "bytesValue": "IFxcIFw/IFwiIFwnIFxgIFxhIFxiIFxmIFx0IFx2IFxuIFxyIFwwMDAgXHgwMCBcWDAwIFx1MDAwMCBcVTAwMDAwMDAwIA==" - } - }, - { - "name": "upper_raw_single_quoted_escapes", - "expr": "bR' \\\\ \\? \\\" \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 '", - "value": { - "bytesValue": "IFxcIFw/IFwiIFxgIFxhIFxiIFxmIFx0IFx2IFxuIFxyIFwwMDAgXHgwMCBcWDAwIFx1MDAwMCBcVTAwMDAwMDAwIA==" - } - }, - { - "name": "upper_raw_double_quoted_escapes", - "expr": "bR\" \\\\ \\? \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 \"", - "value": { - "bytesValue": "IFxcIFw/IFwnIFxgIFxhIFxiIFxmIFx0IFx2IFxuIFxyIFwwMDAgXHgwMCBcWDAwIFx1MDAwMCBcVTAwMDAwMDAwIA==" - } - }, - { - "name": "upper_raw_triple_single_quoted_escapes", - "expr": "bR''' \\\\ \\? \\\" \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 '''", - "value": { - "bytesValue": "IFxcIFw/IFwiIFwnIFxgIFxhIFxiIFxmIFx0IFx2IFxuIFxyIFwwMDAgXHgwMCBcWDAwIFx1MDAwMCBcVTAwMDAwMDAwIA==" - } - }, - { - "name": "upper_raw_triple_double_quoted_escapes", - "expr": "bR\"\"\" \\\\ \\? \\\" \\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 \"\"\"", - "value": { - "bytesValue": "IFxcIFw/IFwiIFwnIFxgIFxhIFxiIFxmIFx0IFx2IFxuIFxyIFwwMDAgXHgwMCBcWDAwIFx1MDAwMCBcVTAwMDAwMDAwIA==" - } - } - ] - }, - { - "name": "whitespace", - "description": "Check that whitespace is ignored by the grammar.", - "test": [ - { - "name": "spaces", - "description": "Check that spaces are ignored.", - "expr": "[ . cel. expr .conformance. proto3. TestAllTypes { single_int64 : int ( 17 ) } . single_int64 ] [ 0 ] == ( 18 - 1 ) && ! false ? 1 : 2", - "value": { - "int64Value": "1" - } - }, - { - "name": "tabs", - "description": "Check that tabs (`\\t`) are ignored.", - "expr": "[\t.\tcel.\texpr\t.conformance.\tproto3.\tTestAllTypes\t{\tsingle_int64\t:\tint\t(\t17\t)\t}\t.\tsingle_int64\t]\t[\t0\t]\t==\t(\t18\t-\t1\t)\t&&\t!\tfalse\t?\t1\t:\t2", - "value": { - "int64Value": "1" - } - }, - { - "name": "new_lines", - "description": "Check that new lines (`\\n`) are ignored.", - "expr": "[\n.\ncel.\nexpr\n.conformance.\nproto3.\nTestAllTypes\n{\nsingle_int64\n:\nint\n(\n17\n)\n}\n.\nsingle_int64\n]\n[\n0\n]\n==\n(\n18\n-\n1\n)\n&&\n!\nfalse\n?\n1\n:\n2", - "value": { - "int64Value": "1" - } - }, - { - "name": "new_pages", - "description": "Check that new pages (`\\f`) are ignored.", - "expr": "[\f.\fcel.\fexpr\f.conformance.\fproto3.\fTestAllTypes\f{\fsingle_int64\f:\fint\f(\f17\f)\f}\f.\fsingle_int64\f]\f[\f0\f]\f==\f(\f18\f-\f1\f)\f&&\f!\ffalse\f?\f1\f:\f2", - "value": { - "int64Value": "1" - } - }, - { - "name": "carriage_returns", - "description": "Check that carriage returns (`\\r`) are ignored.", - "expr": "[\r.\rcel.\rexpr\r.conformance.\rproto3.\rTestAllTypes\r{\rsingle_int64\r:\rint\r(\r17\r)\r}\r.\rsingle_int64\r]\r[\r0\r]\r==\r(\r18\r-\r1\r)\r&&\r!\rfalse\r?\r1\r:\r2", - "value": { - "int64Value": "1" - } - } - ] - }, - { - "name": "comments", - "description": "Check that comments are ignored by the grammar. Note that carriage returns alone cannot terminate comments.", - "test": [ - { - "name": "new_line_terminated", - "description": "Check that new-line-terminated comments are ignored.", - "expr": "[// @\n.// @\ncel.// @\nexpr// @\n.conformance.// @\nproto3.// @\nTestAllTypes// @\n{// @\nsingle_int64// @\n:// @\nint// @\n(// @\n17// @\n)// @\n}// @\n.// @\nsingle_int64// @\n]// @\n[// @\n0// @\n]// @\n==// @\n(// @\n18// @\n-// @\n1// @\n)// @\n&&// @\n!// @\nfalse// @\n?// @\n1// @\n:// @\n2", - "value": { - "int64Value": "1" - } - } - ] - }, - { - "name": "selectors", - "description": "Check that reserved identifiers are permitted as selectors as long as they are not language keywords", - "test": [ - { - "name": "as", - "description": "Check that `as` can be used as a selector.", - "expr": "{ 'as': 1 }.as", - "value": { - "int64Value": "1" - } - }, - { - "name": "break", - "description": "Check that `break` can be used as a selector.", - "expr": "{ 'break': 1 }.break", - "value": { - "int64Value": "1" - } - }, - { - "name": "const", - "description": "Check that `const` can be used as a selector.", - "expr": "{ 'const': 1 }.const", - "value": { - "int64Value": "1" - } - }, - { - "name": "continue", - "description": "Check that `continue` can be used as a selector.", - "expr": "{ 'continue': 1 }.continue", - "value": { - "int64Value": "1" - } - }, - { - "name": "else", - "description": "Check that `else` can be used as a selector.", - "expr": "{ 'else': 1 }.else", - "value": { - "int64Value": "1" - } - }, - { - "name": "for", - "description": "Check that `for` can be used as a selector.", - "expr": "{ 'for': 1 }.for", - "value": { - "int64Value": "1" - } - }, - { - "name": "function", - "description": "Check that `function` can be used as a selector.", - "expr": "{ 'function': 1 }.function", - "value": { - "int64Value": "1" - } - }, - { - "name": "if", - "description": "Check that `if` can be used as a selector.", - "expr": "{ 'if': 1 }.if", - "value": { - "int64Value": "1" - } - }, - { - "name": "import", - "description": "Check that `import` can be used as a selector.", - "expr": "{ 'import': 1 }.import", - "value": { - "int64Value": "1" - } - }, - { - "name": "let", - "description": "Check that `let` can be used as a selector.", - "expr": "{ 'let': 1 }.let", - "value": { - "int64Value": "1" - } - }, - { - "name": "loop", - "description": "Check that `loop` can be used as a selector.", - "expr": "{ 'loop': 1 }.loop", - "value": { - "int64Value": "1" - } - }, - { - "name": "package", - "description": "Check that `package` can be used as a selector.", - "expr": "{ 'package': 1 }.package", - "value": { - "int64Value": "1" - } - }, - { - "name": "namespace", - "description": "Check that `namespace` can be used as a selector.", - "expr": "{ 'namespace': 1 }.namespace", - "value": { - "int64Value": "1" - } - }, - { - "name": "return", - "description": "Check that `return` can be used as a selector.", - "expr": "{ 'return': 1 }.return", - "value": { - "int64Value": "1" - } - }, - { - "name": "var", - "description": "Check that `var` can be used as a selector.", - "expr": "{ 'var': 1 }.var", - "value": { - "int64Value": "1" - } - }, - { - "name": "void", - "description": "Check that `void` can be used as a selector.", - "expr": "{ 'void': 1 }.void", - "value": { - "int64Value": "1" - } - }, - { - "name": "while", - "description": "Check that `while` can be used as a selector.", - "expr": "{ 'while': 1 }.while", - "value": { - "int64Value": "1" - } - } - ] - }, - { - "name": "receiver_function_names", - "description": "Check that reserved identifiers are permitted as receiver function names as long as they are not language keywords", - "test": [ - { - "name": "as", - "description": "Check that `as` can be used as a receiver function.", - "expr": "a.as() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "break", - "description": "Check that `break` can be used as a receiver function.", - "expr": "a.break() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "const", - "description": "Check that `const` can be used as a receiver function.", - "expr": "a.const() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "continue", - "description": "Check that `continue` can be used as a receiver function.", - "expr": "a.continue() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "else", - "description": "Check that `else` can be used as a receiver function.", - "expr": "a.else() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "for", - "description": "Check that `for` can be used as a receiver function.", - "expr": "a.for() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "function", - "description": "Check that `function` can be used as a receiver function.", - "expr": "a.function() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "if", - "description": "Check that `if` can be used as a receiver function.", - "expr": "a.if() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "import", - "description": "Check that `import` can be used as a receiver function.", - "expr": "a.import() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "let", - "description": "Check that `let` can be used as a receiver function.", - "expr": "a.let() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "loop", - "description": "Check that `loop` can be used as a receiver function.", - "expr": "a.loop() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "package", - "description": "Check that `package` can be used as a receiver function.", - "expr": "a.package() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "namespace", - "description": "Check that `namespace` can be used as a receiver function.", - "expr": "a.namespace() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "return", - "description": "Check that `return` can be used as a receiver function.", - "expr": "a.return() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "var", - "description": "Check that `var` can be used as a receiver function.", - "expr": "a.var() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "void", - "description": "Check that `void` can be used as a receiver function.", - "expr": "a.void() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - }, - { - "name": "while", - "description": "Check that `while` can be used as a receiver function.", - "expr": "a.while() || true", - "disableCheck": true, - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "struct_field_names", - "description": "Check that reserved identifiers are permitted as struct field names as long as they are not language keywords", - "test": [ - { - "name": "as", - "description": "Check that `as` can be used as a struct field name.", - "expr": "TestAllTypes{ as: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "as": true - } - } - }, - { - "name": "break", - "description": "Check that `break` can be used as a struct field name.", - "expr": "TestAllTypes{ break: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "break": true - } - } - }, - { - "name": "const", - "description": "Check that `const` can be used as a struct field name.", - "expr": "TestAllTypes{ const: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "const": true - } - } - }, - { - "name": "continue", - "description": "Check that `continue` can be used as a struct field name.", - "expr": "TestAllTypes{ continue: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "continue": true - } - } - }, - { - "name": "else", - "description": "Check that `else` can be used as a struct field name.", - "expr": "TestAllTypes{ else: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "else": true - } - } - }, - { - "name": "for", - "description": "Check that `for` can be used as a struct field name.", - "expr": "TestAllTypes{ for: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "for": true - } - } - }, - { - "name": "function", - "description": "Check that `function` can be used as a struct field name.", - "expr": "TestAllTypes{ function: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "function": true - } - } - }, - { - "name": "if", - "description": "Check that `if` can be used as a struct field name.", - "expr": "TestAllTypes{ if: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "if": true - } - } - }, - { - "name": "import", - "description": "Check that `import` can be used as a struct field name.", - "expr": "TestAllTypes{ import: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "import": true - } - } - }, - { - "name": "let", - "description": "Check that `let` can be used as a struct field name.", - "expr": "TestAllTypes{ let: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "let": true - } - } - }, - { - "name": "loop", - "description": "Check that `loop` can be used as a struct field name.", - "expr": "TestAllTypes{ loop: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "loop": true - } - } - }, - { - "name": "package", - "description": "Check that `package` can be used as a struct field name.", - "expr": "TestAllTypes{ package: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "package": true - } - } - }, - { - "name": "namespace", - "description": "Check that `namespace` can be used as a struct field name.", - "expr": "TestAllTypes{ namespace: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "namespace": true - } - } - }, - { - "name": "return", - "description": "Check that `return` can be used as a struct field name.", - "expr": "TestAllTypes{ return: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "return": true - } - } - }, - { - "name": "var", - "description": "Check that `var` can be used as a struct field name.", - "expr": "TestAllTypes{ var: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "var": true - } - } - }, - { - "name": "void", - "description": "Check that `void` can be used as a struct field name.", - "expr": "TestAllTypes{ void: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "void": true - } - } - }, - { - "name": "while", - "description": "Check that `while` can be used as a struct field name.", - "expr": "TestAllTypes{ while: true }", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "while": true - } - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/plumbing.json b/packages/cel-spec/src/testdata/json/plumbing.json deleted file mode 100644 index dd03f865..00000000 --- a/packages/cel-spec/src/testdata/json/plumbing.json +++ /dev/null @@ -1,110 +0,0 @@ -{ - "name": "plumbing", - "description": "Check that the ConformanceService server can accept all arguments and return all responses.", - "section": [ - { - "name": "min", - "description": "Minimal programs.", - "test": [ - { - "name": "min_program", - "description": "Smallest functionality: expr in, result out.", - "expr": "17", - "value": { - "int64Value": "17" - } - } - ] - }, - { - "name": "eval_results", - "description": "All evaluation result kinds.", - "test": [ - { - "name": "error_result", - "description": "Check that error results go through.", - "expr": "1 / 0", - "evalError": { - "errors": [ - { - "message": "foo" - } - ] - } - }, - { - "name": "eval_map_results", - "description": "Check that map literals results are order independent.", - "expr": "{\"k1\":\"v1\",\"k\":\"v\"}", - "value": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "k" - }, - "value": { - "stringValue": "v" - } - }, - { - "key": { - "stringValue": "k1" - }, - "value": { - "stringValue": "v1" - } - } - ] - } - } - } - ] - }, - { - "name": "check_inputs", - "description": "All inputs to Check phase.", - "test": [ - { - "name": "skip_check", - "description": "Make sure we can skip type checking.", - "expr": "[17, 'pancakes']", - "disableCheck": true, - "value": { - "listValue": { - "values": [ - { - "int64Value": "17" - }, - { - "stringValue": "pancakes" - } - ] - } - } - } - ] - }, - { - "name": "eval_inputs", - "description": "All inputs to Eval phase.", - "test": [ - { - "name": "one_ignored_value_arg", - "description": "Check that value bindings can be given, even if ignored.", - "expr": "'foo'", - "bindings": { - "x": { - "value": { - "int64Value": "17" - } - } - }, - "value": { - "stringValue": "foo" - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/proto2.json b/packages/cel-spec/src/testdata/json/proto2.json deleted file mode 100644 index adbfca5d..00000000 --- a/packages/cel-spec/src/testdata/json/proto2.json +++ /dev/null @@ -1,1403 +0,0 @@ -{ - "name": "proto2", - "description": "Protocol buffer version 2 tests. See notes for the available set of protos for tests.", - "section": [ - { - "name": "literal_singular", - "description": "Literals with singular fields set.", - "test": [ - { - "name": "int64_nocontainer", - "expr": "cel.expr.conformance.proto2.TestAllTypes{single_int64: 17}", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt64": "17" - } - } - }, - { - "name": "int32", - "expr": "TestAllTypes{single_int32: -34}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt32": -34 - } - } - }, - { - "name": "int32_eq_uint", - "expr": "Int32Value{value: 34} == dyn(UInt64Value{value: 34u})", - "container": "google.protobuf", - "value": { - "boolValue": true - } - }, - { - "name": "not_int32_eq_uint", - "expr": "Int32Value{value: 34} == dyn(UInt64Value{value: 18446744073709551615u})", - "container": "google.protobuf", - "value": { - "boolValue": false - } - }, - { - "name": "int32_eq_double", - "expr": "Int32Value{value: 34} == dyn(DoubleValue{value: 34.0})", - "container": "google.protobuf", - "value": { - "boolValue": true - } - }, - { - "name": "not_int32_eq_double", - "expr": "Int32Value{value: 34} == dyn(DoubleValue{value: -9223372036854775809.0})", - "container": "google.protobuf", - "value": { - "boolValue": false - } - }, - { - "name": "int64", - "expr": "TestAllTypes{single_int64: 17}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt64": "17" - } - } - }, - { - "name": "uint32", - "expr": "TestAllTypes{single_uint32: 1u}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleUint32": 1 - } - } - }, - { - "name": "uint32_eq_int", - "expr": "UInt32Value{value: 34u} == dyn(Int64Value{value: 34})", - "container": "google.protobuf", - "value": { - "boolValue": true - } - }, - { - "name": "not_uint32_eq_int", - "expr": "UInt32Value{value: 34u} == dyn(Int64Value{value: -1})", - "container": "google.protobuf", - "value": { - "boolValue": false - } - }, - { - "name": "uint32_eq_double", - "expr": "UInt32Value{value: 34u} == dyn(DoubleValue{value: 34.0})", - "container": "google.protobuf", - "value": { - "boolValue": true - } - }, - { - "name": "not_uint32_eq_double", - "expr": "UInt32Value{value: 34u} == dyn(DoubleValue{value: 18446744073709551616.0})", - "container": "google.protobuf", - "value": { - "boolValue": false - } - }, - { - "name": "uint64", - "expr": "TestAllTypes{single_uint64: 9999u}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleUint64": "9999" - } - } - }, - { - "name": "sint32", - "expr": "TestAllTypes{single_sint32: -3}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleSint32": -3 - } - } - }, - { - "name": "sint64", - "expr": "TestAllTypes{single_sint64: 255}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleSint64": "255" - } - } - }, - { - "name": "fixed32", - "expr": "TestAllTypes{single_fixed32: 43u}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleFixed32": 43 - } - } - }, - { - "name": "fixed64", - "expr": "TestAllTypes{single_fixed64: 1880u}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleFixed64": "1880" - } - } - }, - { - "name": "sfixed32", - "expr": "TestAllTypes{single_sfixed32: -404}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleSfixed32": -404 - } - } - }, - { - "name": "sfixed64", - "expr": "TestAllTypes{single_sfixed64: -1}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleSfixed64": "-1" - } - } - }, - { - "name": "float", - "expr": "TestAllTypes{single_float: 3.1416}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleFloat": 3.1416 - } - } - }, - { - "name": "float_eq_int", - "expr": "FloatValue{value: 3.0} == dyn(Int64Value{value: 3})", - "container": "google.protobuf", - "value": { - "boolValue": true - } - }, - { - "name": "not_float_eq_int", - "expr": "FloatValue{value: -1.14} == dyn(Int64Value{value: -1})", - "container": "google.protobuf", - "value": { - "boolValue": false - } - }, - { - "name": "float_eq_uint", - "expr": "FloatValue{value: 34.0} == dyn(UInt64Value{value: 34u})", - "container": "google.protobuf", - "value": { - "boolValue": true - } - }, - { - "name": "not_float_eq_uint", - "expr": "FloatValue{value: -1.0} == dyn(UInt64Value{value: 18446744073709551615u})", - "container": "google.protobuf", - "value": { - "boolValue": false - } - }, - { - "name": "double", - "expr": "TestAllTypes{single_double: 6.022e23}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleDouble": 6.022e23 - } - } - }, - { - "name": "bool", - "expr": "TestAllTypes{single_bool: true}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleBool": true - } - } - }, - { - "name": "string", - "expr": "TestAllTypes{single_string: 'foo'}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleString": "foo" - } - } - }, - { - "name": "bytes", - "expr": "TestAllTypes{single_bytes: b'\\377'}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleBytes": "/w==" - } - } - } - ] - }, - { - "name": "literal_wellknown", - "description": "Literals with well-known fields set.", - "test": [ - { - "name": "any", - "expr": "TestAllTypes{single_any: TestAllTypes{single_int32: 1}}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleAny": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt32": 1 - } - } - } - }, - { - "name": "duration", - "expr": "TestAllTypes{single_duration: duration('123s')}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleDuration": "123s" - } - } - }, - { - "name": "timestamp", - "expr": "TestAllTypes{single_timestamp: timestamp('2009-02-13T23:31:30Z')}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleTimestamp": "2009-02-13T23:31:30Z" - } - } - }, - { - "name": "struct", - "expr": "TestAllTypes{single_struct: {'one': 1, 'two': 2}}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleStruct": { - "one": 1, - "two": 2 - } - } - } - }, - { - "name": "value", - "expr": "TestAllTypes{single_value: 'foo'}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleValue": "foo" - } - } - }, - { - "name": "int64_wrapper", - "expr": "TestAllTypes{single_int64_wrapper: -321}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt64Wrapper": "-321" - } - } - }, - { - "name": "int32_wrapper", - "expr": "TestAllTypes{single_int32_wrapper: -456}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt32Wrapper": -456 - } - } - }, - { - "name": "double_wrapper", - "expr": "TestAllTypes{single_double_wrapper: 2.71828}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleDoubleWrapper": 2.71828 - } - } - }, - { - "name": "float_wrapper", - "expr": "TestAllTypes{single_float_wrapper: 2.99792e8}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleFloatWrapper": 299792000 - } - } - }, - { - "name": "uint64_wrapper", - "expr": "TestAllTypes{single_uint64_wrapper: 8675309u}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleUint64Wrapper": "8675309" - } - } - }, - { - "name": "uint32_wrapper", - "expr": "TestAllTypes{single_uint32_wrapper: 987u}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleUint32Wrapper": 987 - } - } - }, - { - "name": "string_wrapper", - "expr": "TestAllTypes{single_string_wrapper: 'hubba'}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleStringWrapper": "hubba" - } - } - }, - { - "name": "bool_wrapper", - "expr": "TestAllTypes{single_bool_wrapper: true}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleBoolWrapper": true - } - } - }, - { - "name": "bytes_wrapper", - "expr": "TestAllTypes{single_bytes_wrapper: b'\\301\\103'}", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleBytesWrapper": "wUM=" - } - } - } - ] - }, - { - "name": "singular_bind", - "description": "Binding the singular fields.", - "test": [ - { - "name": "int32", - "expr": "x.single_int32", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt32": 17 - } - } - } - }, - "value": { - "int64Value": "17" - } - }, - { - "name": "int64", - "expr": "x.single_int64", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "singleInt64": "-99" - } - } - } - }, - "value": { - "int64Value": "-99" - } - } - ] - }, - { - "name": "empty_field", - "description": "Tests on empty fields.", - "test": [ - { - "name": "scalar_with_default", - "expr": "TestAllTypes{}.single_int32", - "container": "cel.expr.conformance.proto2", - "value": { - "int64Value": "-32" - } - }, - { - "name": "scalar_no_default", - "expr": "TestAllTypes{}.single_fixed32", - "container": "cel.expr.conformance.proto2", - "value": { - "uint64Value": "0" - } - }, - { - "name": "nested_message", - "expr": "TestAllTypes{}.single_nested_message", - "container": "cel.expr.conformance.proto2", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes.NestedMessage" - } - } - }, - { - "name": "nested_message_subfield", - "expr": "TestAllTypes{}.single_nested_message.bb", - "container": "cel.expr.conformance.proto2", - "value": { - "int64Value": "0" - } - }, - { - "name": "wkt", - "expr": "TestAllTypes{}.single_int64_wrapper", - "container": "cel.expr.conformance.proto2", - "value": { - "nullValue": null - } - }, - { - "name": "repeated_scalar", - "expr": "TestAllTypes{}.repeated_int64", - "container": "cel.expr.conformance.proto2", - "value": { - "listValue": {} - } - }, - { - "name": "repeated_enum", - "expr": "TestAllTypes{}.repeated_nested_enum", - "container": "cel.expr.conformance.proto3", - "value": { - "listValue": {} - } - }, - { - "name": "repeated_nested", - "expr": "TestAllTypes{}.repeated_nested_message", - "container": "cel.expr.conformance.proto2", - "value": { - "listValue": {} - } - }, - { - "name": "map", - "expr": "TestAllTypes{}.map_string_string", - "container": "cel.expr.conformance.proto2", - "value": { - "mapValue": {} - } - } - ] - }, - { - "name": "has", - "description": "Tests for the has() macro on proto2 messages.", - "test": [ - { - "name": "undefined", - "expr": "has(TestAllTypes{}.no_such_field)", - "disableCheck": true, - "container": "cel.expr.conformance.proto2", - "evalError": { - "errors": [ - { - "message": "no_such_field" - } - ] - } - }, - { - "name": "repeated_none_implicit", - "expr": "has(TestAllTypes{}.repeated_int32)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "repeated_none_explicit", - "expr": "has(TestAllTypes{repeated_int32: []}.repeated_int32)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "repeated_one", - "expr": "has(TestAllTypes{repeated_int32: [1]}.repeated_int32)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "repeated_many", - "expr": "has(TestAllTypes{repeated_int32: [1, 2, 3]}.repeated_int32)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "map_none_implicit", - "expr": "has(TestAllTypes{}.map_string_string)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "map_none_explicit", - "expr": "has(TestAllTypes{map_string_string: {}}.map_string_string)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "map_one_default", - "expr": "has(TestAllTypes{map_string_string: {'MT': ''}}.map_string_string)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "map_one", - "expr": "has(TestAllTypes{map_string_string: {'one': 'uno'}}.map_string_string)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "map_many", - "expr": "has(TestAllTypes{map_string_string: {'one': 'uno', 'two': 'dos'}}.map_string_string)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "required", - "expr": "has(TestRequired{required_int32: 4}.required_int32)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "optional_unset_no_default", - "expr": "has(TestAllTypes{}.single_sint32)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "optional_set_no_default", - "expr": "has(TestAllTypes{single_sint32: -4}.single_sint32)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "optional_unset_with_default", - "expr": "has(TestAllTypes{}.single_int32)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "optional_set_with_default", - "expr": "has(TestAllTypes{single_int32: 16}.single_int32)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "optional_set_to_default", - "expr": "has(TestAllTypes{single_int32: -32}.single_int32)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "optional_message_unset", - "expr": "has(TestAllTypes{}.standalone_message)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "optional_message_set", - "expr": "has(TestAllTypes{standalone_message: TestAllTypes.NestedMessage{}}.standalone_message)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "optional_enum_unset", - "expr": "has(TestAllTypes{}.standalone_enum)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "optional_enum_set", - "expr": "has(TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.BAR}.standalone_enum)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "optional_enum_set_zero", - "expr": "has(TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.FOO}.standalone_enum)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "oneof_unset", - "expr": "has(TestAllTypes{}.single_nested_message)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "oneof_other_set", - "expr": "has(TestAllTypes{single_nested_enum: TestAllTypes.NestedEnum.BAZ}.single_nested_message)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "oneof_set", - "expr": "has(TestAllTypes{single_nested_message: TestAllTypes.NestedMessage{}}.single_nested_message)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "oneof_set_default", - "expr": "has(TestAllTypes{single_nested_enum: TestAllTypes.NestedEnum.FOO}.single_nested_enum)", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "set_null", - "test": [ - { - "name": "single_message", - "expr": "TestAllTypes{single_nested_message: null} == TestAllTypes{}", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "single_any", - "expr": "TestAllTypes{single_any: null}.single_any", - "container": "cel.expr.conformance.proto2", - "value": { - "nullValue": null - } - }, - { - "name": "single_value", - "expr": "TestAllTypes{single_value: null}.single_value", - "container": "cel.expr.conformance.proto2", - "value": { - "nullValue": null - } - }, - { - "name": "single_duration", - "expr": "TestAllTypes{single_duration: null} == TestAllTypes{}", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "single_timestamp", - "expr": "TestAllTypes{single_timestamp: null} == TestAllTypes{}", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - }, - { - "name": "single_scalar", - "expr": "TestAllTypes{single_bool: null} == TestAllTypes{}", - "disableCheck": true, - "container": "cel.expr.conformance.proto2", - "evalError": { - "errors": [ - { - "message": "unsupported field type" - } - ] - } - }, - { - "name": "repeated", - "expr": "TestAllTypes{repeated_int32: null} == TestAllTypes{}", - "disableCheck": true, - "container": "cel.expr.conformance.proto2", - "evalError": { - "errors": [ - { - "message": "unsupported field type" - } - ] - } - }, - { - "name": "map", - "expr": "TestAllTypes{map_string_string: null} == TestAllTypes{}", - "disableCheck": true, - "container": "cel.expr.conformance.proto2", - "evalError": { - "errors": [ - { - "message": "unsupported field type" - } - ] - } - }, - { - "name": "list_value", - "expr": "TestAllTypes{list_value: null} == TestAllTypes{}", - "disableCheck": true, - "container": "cel.expr.conformance.proto2", - "evalError": { - "errors": [ - { - "message": "unsupported field type" - } - ] - } - }, - { - "name": "single_struct", - "expr": "TestAllTypes{single_struct: null} == TestAllTypes{}", - "disableCheck": true, - "container": "cel.expr.conformance.proto2", - "evalError": { - "errors": [ - { - "message": "unsupported field type" - } - ] - } - } - ] - }, - { - "name": "quoted_fields", - "test": [ - { - "name": "set_field_with_quoted_name", - "expr": "TestAllTypes{`in`: true} == TestAllTypes{}", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": false - } - }, - { - "name": "get_field_with_quoted_name", - "expr": "TestAllTypes{`in`: true}.`in`", - "container": "cel.expr.conformance.proto2", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "extensions_has", - "description": "Tests for presence checks on proto2 extension fields.", - "test": [ - { - "name": "package_scoped_int32", - "expr": "has(msg.`cel.expr.conformance.proto2.int32_ext`)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.int32_ext]": 42 - } - } - } - } - }, - { - "name": "package_scoped_nested_ext", - "expr": "has(msg.`cel.expr.conformance.proto2.nested_ext`)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.nested_ext]": {} - } - } - } - } - }, - { - "name": "package_scoped_test_all_types_ext", - "expr": "has(msg.`cel.expr.conformance.proto2.test_all_types_ext`)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.test_all_types_ext]": {} - } - } - } - } - }, - { - "name": "package_scoped_test_all_types_nested_enum_ext", - "expr": "has(msg.`cel.expr.conformance.proto2.nested_enum_ext`)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.nested_enum_ext]": "BAR" - } - } - } - } - }, - { - "name": "package_scoped_repeated_test_all_types", - "expr": "has(msg.`cel.expr.conformance.proto2.repeated_test_all_types`)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.repeated_test_all_types]": [ - { - "singleInt64": "1" - }, - { - "singleBool": true - } - ] - } - } - } - } - }, - { - "name": "message_scoped_int64", - "expr": "has(msg.`cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.int64_ext`)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.int64_ext]": "42" - } - } - } - } - }, - { - "name": "message_scoped_nested_ext", - "expr": "has(msg.`cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_nested_ext`)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_nested_ext]": {} - } - } - } - } - }, - { - "name": "message_scoped_nested_enum_ext", - "expr": "has(msg.`cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.nested_enum_ext`)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.nested_enum_ext]": "BAR" - } - } - } - } - }, - { - "name": "message_scoped_repeated_test_all_types", - "expr": "has(msg.`cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_repeated_test_all_types`)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_repeated_test_all_types]": [ - { - "singleInt64": "1" - }, - { - "singleBool": true - } - ] - } - } - } - } - } - ] - }, - { - "name": "extensions_get", - "description": "Tests for accessing proto2 extension fields.", - "test": [ - { - "name": "package_scoped_int32", - "expr": "msg.`cel.expr.conformance.proto2.int32_ext` == 42", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.int32_ext]": 42 - } - } - } - } - }, - { - "name": "package_scoped_nested_ext", - "expr": "msg.`cel.expr.conformance.proto2.nested_ext` == cel.expr.conformance.proto2.TestAllTypes{}", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.nested_ext]": {} - } - } - } - } - }, - { - "name": "package_scoped_test_all_types_ext", - "expr": "msg.`cel.expr.conformance.proto2.test_all_types_ext` == cel.expr.conformance.proto2.TestAllTypes{}", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.test_all_types_ext]": {} - } - } - } - } - }, - { - "name": "package_scoped_test_all_types_nested_enum_ext", - "expr": "msg.`cel.expr.conformance.proto2.nested_enum_ext` == cel.expr.conformance.proto2.TestAllTypes.NestedEnum.BAR", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.nested_enum_ext]": "BAR" - } - } - } - } - }, - { - "name": "package_scoped_repeated_test_all_types", - "expr": "msg.`cel.expr.conformance.proto2.repeated_test_all_types` == [cel.expr.conformance.proto2.TestAllTypes{single_int64: 1}, cel.expr.conformance.proto2.TestAllTypes{single_bool: true}]", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.repeated_test_all_types]": [ - { - "singleInt64": "1" - }, - { - "singleBool": true - } - ] - } - } - } - } - }, - { - "name": "message_scoped_int64", - "expr": "msg.`cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.int64_ext` == 42", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.int64_ext]": "42" - } - } - } - } - }, - { - "name": "message_scoped_nested_ext", - "expr": "msg.`cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_nested_ext` == cel.expr.conformance.proto2.TestAllTypes{}", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_nested_ext]": {} - } - } - } - } - }, - { - "name": "message_scoped_nested_enum_ext", - "expr": "msg.`cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.nested_enum_ext` == cel.expr.conformance.proto2.TestAllTypes.NestedEnum.BAR", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.nested_enum_ext]": "BAR" - } - } - } - } - }, - { - "name": "message_scoped_repeated_test_all_types", - "expr": "msg.`cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_repeated_test_all_types` == [cel.expr.conformance.proto2.TestAllTypes{single_int64: 1}, cel.expr.conformance.proto2.TestAllTypes{single_bool: true}]", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_repeated_test_all_types]": [ - { - "singleInt64": "1" - }, - { - "singleBool": true - } - ] - } - } - } - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/proto2_ext.json b/packages/cel-spec/src/testdata/json/proto2_ext.json deleted file mode 100644 index 7d5195a8..00000000 --- a/packages/cel-spec/src/testdata/json/proto2_ext.json +++ /dev/null @@ -1,476 +0,0 @@ -{ - "name": "proto2_ext", - "description": "Tests for the proto extension library.", - "section": [ - { - "name": "has_ext", - "test": [ - { - "name": "package_scoped_int32", - "expr": "proto.hasExt(msg, cel.expr.conformance.proto2.int32_ext)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.int32_ext]": 42 - } - } - } - } - }, - { - "name": "package_scoped_nested_ext", - "expr": "proto.hasExt(msg, cel.expr.conformance.proto2.nested_ext)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.nested_ext]": {} - } - } - } - } - }, - { - "name": "package_scoped_test_all_types_ext", - "expr": "proto.hasExt(msg, cel.expr.conformance.proto2.test_all_types_ext)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.test_all_types_ext]": {} - } - } - } - } - }, - { - "name": "package_scoped_test_all_types_nested_enum_ext", - "expr": "proto.hasExt(msg, cel.expr.conformance.proto2.nested_enum_ext)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.nested_enum_ext]": "BAR" - } - } - } - } - }, - { - "name": "package_scoped_repeated_test_all_types", - "expr": "proto.hasExt(msg, cel.expr.conformance.proto2.repeated_test_all_types)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.repeated_test_all_types]": [ - { - "singleInt64": "1" - }, - { - "singleBool": true - } - ] - } - } - } - } - }, - { - "name": "message_scoped_int64", - "expr": "proto.hasExt(msg, cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.int64_ext)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.int64_ext]": "42" - } - } - } - } - }, - { - "name": "message_scoped_nested_ext", - "expr": "proto.hasExt(msg, cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_nested_ext)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_nested_ext]": {} - } - } - } - } - }, - { - "name": "message_scoped_nested_enum_ext", - "expr": "proto.hasExt(msg, cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.nested_enum_ext)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.nested_enum_ext]": "BAR" - } - } - } - } - }, - { - "name": "message_scoped_repeated_test_all_types", - "expr": "proto.hasExt(msg, cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_repeated_test_all_types)", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_repeated_test_all_types]": [ - { - "singleInt64": "1" - }, - { - "singleBool": true - } - ] - } - } - } - } - } - ] - }, - { - "name": "get_ext", - "test": [ - { - "name": "package_scoped_int32", - "expr": "proto.getExt(msg, cel.expr.conformance.proto2.int32_ext) == 42", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.int32_ext]": 42 - } - } - } - } - }, - { - "name": "package_scoped_nested_ext", - "expr": "proto.getExt(msg, cel.expr.conformance.proto2.nested_ext) == cel.expr.conformance.proto2.TestAllTypes{}", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.nested_ext]": {} - } - } - } - } - }, - { - "name": "package_scoped_test_all_types_ext", - "expr": "proto.getExt(msg, cel.expr.conformance.proto2.test_all_types_ext) == cel.expr.conformance.proto2.TestAllTypes{}", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.test_all_types_ext]": {} - } - } - } - } - }, - { - "name": "package_scoped_test_all_types_nested_enum_ext", - "expr": "proto.getExt(msg, cel.expr.conformance.proto2.nested_enum_ext) == cel.expr.conformance.proto2.TestAllTypes.NestedEnum.BAR", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.nested_enum_ext]": "BAR" - } - } - } - } - }, - { - "name": "package_scoped_repeated_test_all_types", - "expr": "proto.getExt(msg, cel.expr.conformance.proto2.repeated_test_all_types) == [cel.expr.conformance.proto2.TestAllTypes{single_int64: 1}, cel.expr.conformance.proto2.TestAllTypes{single_bool: true}]", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.repeated_test_all_types]": [ - { - "singleInt64": "1" - }, - { - "singleBool": true - } - ] - } - } - } - } - }, - { - "name": "message_scoped_int64", - "expr": "proto.getExt(msg, cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.int64_ext) == 42", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.int64_ext]": "42" - } - } - } - } - }, - { - "name": "message_scoped_nested_ext", - "expr": "proto.getExt(msg, cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_nested_ext) == cel.expr.conformance.proto2.TestAllTypes{}", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_nested_ext]": {} - } - } - } - } - }, - { - "name": "message_scoped_nested_enum_ext", - "expr": "proto.getExt(msg, cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.nested_enum_ext) == cel.expr.conformance.proto2.TestAllTypes.NestedEnum.BAR", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.nested_enum_ext]": "BAR" - } - } - } - } - }, - { - "name": "message_scoped_repeated_test_all_types", - "expr": "proto.getExt(msg, cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_repeated_test_all_types) == [cel.expr.conformance.proto2.TestAllTypes{single_int64: 1}, cel.expr.conformance.proto2.TestAllTypes{single_bool: true}]", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto2.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes", - "[cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_repeated_test_all_types]": [ - { - "singleInt64": "1" - }, - { - "singleBool": true - } - ] - } - } - } - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/proto3.json b/packages/cel-spec/src/testdata/json/proto3.json deleted file mode 100644 index 14c5b78e..00000000 --- a/packages/cel-spec/src/testdata/json/proto3.json +++ /dev/null @@ -1,811 +0,0 @@ -{ - "name": "proto3", - "description": "Protocol buffer version 3 tests. See notes for the available set of protos for tests.", - "section": [ - { - "name": "literal_singular", - "description": "Literals with singular fields set.", - "test": [ - { - "name": "int64_nocontainer", - "expr": "cel.expr.conformance.proto3.TestAllTypes{single_int64: 17}", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt64": "17" - } - } - }, - { - "name": "int32", - "expr": "TestAllTypes{single_int32: -34}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32": -34 - } - } - }, - { - "name": "int64", - "expr": "TestAllTypes{single_int64: 17}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt64": "17" - } - } - }, - { - "name": "uint32", - "expr": "TestAllTypes{single_uint32: 1u}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleUint32": 1 - } - } - }, - { - "name": "uint64", - "expr": "TestAllTypes{single_uint64: 9999u}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleUint64": "9999" - } - } - }, - { - "name": "sint32", - "expr": "TestAllTypes{single_sint32: -3}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleSint32": -3 - } - } - }, - { - "name": "sint64", - "expr": "TestAllTypes{single_sint64: 255}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleSint64": "255" - } - } - }, - { - "name": "fixed32", - "expr": "TestAllTypes{single_fixed32: 43u}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleFixed32": 43 - } - } - }, - { - "name": "fixed64", - "expr": "TestAllTypes{single_fixed64: 1880u}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleFixed64": "1880" - } - } - }, - { - "name": "sfixed32", - "expr": "TestAllTypes{single_sfixed32: -404}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleSfixed32": -404 - } - } - }, - { - "name": "sfixed64", - "expr": "TestAllTypes{single_sfixed64: -1}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleSfixed64": "-1" - } - } - }, - { - "name": "float", - "expr": "TestAllTypes{single_float: 3.1416}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleFloat": 3.1416 - } - } - }, - { - "name": "double", - "expr": "TestAllTypes{single_double: 6.022e23}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleDouble": 6.022e23 - } - } - }, - { - "name": "bool", - "expr": "TestAllTypes{single_bool: true}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleBool": true - } - } - }, - { - "name": "string", - "expr": "TestAllTypes{single_string: 'foo'}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleString": "foo" - } - } - }, - { - "name": "bytes", - "expr": "TestAllTypes{single_bytes: b'\\377'}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleBytes": "/w==" - } - } - } - ] - }, - { - "name": "literal_wellknown", - "description": "Literals with well-known fields set.", - "test": [ - { - "name": "any", - "expr": "TestAllTypes{single_any: TestAllTypes{single_int32: 1}}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleAny": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32": 1 - } - } - } - }, - { - "name": "duration", - "expr": "TestAllTypes{single_duration: duration('123s')}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleDuration": "123s" - } - } - }, - { - "name": "timestamp", - "expr": "TestAllTypes{single_timestamp: timestamp('2009-02-13T23:31:30Z')}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleTimestamp": "2009-02-13T23:31:30Z" - } - } - }, - { - "name": "struct", - "expr": "TestAllTypes{single_struct: {'one': 1, 'two': 2}}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleStruct": { - "one": 1, - "two": 2 - } - } - } - }, - { - "name": "value", - "expr": "TestAllTypes{single_value: 'foo'}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleValue": "foo" - } - } - }, - { - "name": "int64_wrapper", - "expr": "TestAllTypes{single_int64_wrapper: -321}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt64Wrapper": "-321" - } - } - }, - { - "name": "int32_wrapper", - "expr": "TestAllTypes{single_int32_wrapper: -456}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32Wrapper": -456 - } - } - }, - { - "name": "double_wrapper", - "expr": "TestAllTypes{single_double_wrapper: 2.71828}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleDoubleWrapper": 2.71828 - } - } - }, - { - "name": "float_wrapper", - "expr": "TestAllTypes{single_float_wrapper: 2.99792e8}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleFloatWrapper": 299792000 - } - } - }, - { - "name": "uint64_wrapper", - "expr": "TestAllTypes{single_uint64_wrapper: 8675309u}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleUint64Wrapper": "8675309" - } - } - }, - { - "name": "uint32_wrapper", - "expr": "TestAllTypes{single_uint32_wrapper: 987u}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleUint32Wrapper": 987 - } - } - }, - { - "name": "string_wrapper", - "expr": "TestAllTypes{single_string_wrapper: 'hubba'}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleStringWrapper": "hubba" - } - } - }, - { - "name": "bool_wrapper", - "expr": "TestAllTypes{single_bool_wrapper: true}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleBoolWrapper": true - } - } - }, - { - "name": "bytes_wrapper", - "expr": "TestAllTypes{single_bytes_wrapper: b'\\301\\103'}", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleBytesWrapper": "wUM=" - } - } - } - ] - }, - { - "name": "singular_bind", - "description": "Binding the singular fields.", - "test": [ - { - "name": "int32", - "expr": "x.single_int32", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt32": 17 - } - } - } - }, - "value": { - "int64Value": "17" - } - }, - { - "name": "int64", - "expr": "x.single_int64", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt64": "-99" - } - } - } - }, - "value": { - "int64Value": "-99" - } - } - ] - }, - { - "name": "empty_field", - "description": "Tests on empty fields.", - "test": [ - { - "name": "scalar", - "expr": "TestAllTypes{}.single_fixed32", - "container": "cel.expr.conformance.proto3", - "value": { - "uint64Value": "0" - } - }, - { - "name": "nested_message", - "expr": "TestAllTypes{}.single_nested_message", - "container": "cel.expr.conformance.proto3", - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes.NestedMessage" - } - } - }, - { - "name": "nested_message_subfield", - "expr": "TestAllTypes{}.single_nested_message.bb", - "container": "cel.expr.conformance.proto3", - "value": { - "int64Value": "0" - } - }, - { - "name": "wkt", - "expr": "TestAllTypes{}.single_int64_wrapper", - "container": "cel.expr.conformance.proto3", - "value": { - "nullValue": null - } - }, - { - "name": "repeated_scalar", - "expr": "TestAllTypes{}.repeated_int64", - "container": "cel.expr.conformance.proto3", - "value": { - "listValue": {} - } - }, - { - "name": "repeated_enum", - "expr": "TestAllTypes{}.repeated_nested_enum", - "container": "cel.expr.conformance.proto3", - "value": { - "listValue": {} - } - }, - { - "name": "repeated_nested", - "expr": "TestAllTypes{}.repeated_nested_message", - "container": "cel.expr.conformance.proto3", - "value": { - "listValue": {} - } - }, - { - "name": "map", - "expr": "TestAllTypes{}.map_string_string", - "container": "cel.expr.conformance.proto3", - "value": { - "mapValue": {} - } - } - ] - }, - { - "name": "has", - "description": "Tests for the has() macro on proto3 messages.", - "test": [ - { - "name": "undefined", - "expr": "has(TestAllTypes{}.no_such_field)", - "disableCheck": true, - "container": "cel.expr.conformance.proto3", - "evalError": { - "errors": [ - { - "message": "no_such_field" - } - ] - } - }, - { - "name": "repeated_none_implicit", - "expr": "has(TestAllTypes{}.repeated_int32)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "repeated_none_explicit", - "expr": "has(TestAllTypes{repeated_int32: []}.repeated_int32)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "repeated_one", - "expr": "has(TestAllTypes{repeated_int32: [1]}.repeated_int32)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "repeated_many", - "expr": "has(TestAllTypes{repeated_int32: [1, 2, 3]}.repeated_int32)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "map_none_implicit", - "expr": "has(TestAllTypes{}.map_string_string)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "map_none_explicit", - "expr": "has(TestAllTypes{map_string_string: {}}.map_string_string)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "map_one_default", - "expr": "has(TestAllTypes{map_string_string: {'MT': ''}}.map_string_string)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "map_one", - "expr": "has(TestAllTypes{map_string_string: {'one': 'uno'}}.map_string_string)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "map_many", - "expr": "has(TestAllTypes{map_string_string: {'one': 'uno', 'two': 'dos'}}.map_string_string)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "single_unset", - "expr": "has(TestAllTypes{}.single_int32)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "single_set", - "expr": "has(TestAllTypes{single_int32: 16}.single_int32)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "single_set_to_default", - "expr": "has(TestAllTypes{single_int32: 0}.single_int32)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "single_message_unset", - "expr": "has(TestAllTypes{}.standalone_message)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "single_message_set", - "expr": "has(TestAllTypes{standalone_message: TestAllTypes.NestedMessage{bb: 123}}.standalone_message)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "single_message_set_to_default", - "expr": "has(TestAllTypes{standalone_message: TestAllTypes.NestedMessage{}}.standalone_message)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "single_enum_unset", - "expr": "has(TestAllTypes{}.standalone_enum)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "single_enum_set", - "expr": "has(TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.BAR}.standalone_enum)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "single_enum_set_zero", - "expr": "has(TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.FOO}.standalone_enum)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "oneof_unset", - "expr": "has(TestAllTypes{}.single_nested_message)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "oneof_other_set", - "expr": "has(TestAllTypes{single_nested_enum: TestAllTypes.NestedEnum.BAZ}.single_nested_message)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "oneof_set", - "expr": "has(TestAllTypes{single_nested_message: TestAllTypes.NestedMessage{}}.single_nested_message)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "oneof_set_default", - "expr": "has(TestAllTypes{single_nested_enum: TestAllTypes.NestedEnum.FOO}.single_nested_enum)", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "set_null", - "test": [ - { - "name": "single_message", - "expr": "TestAllTypes{single_nested_message: null} == TestAllTypes{}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "single_any", - "expr": "TestAllTypes{single_any: null}.single_any", - "container": "cel.expr.conformance.proto3", - "value": { - "nullValue": null - } - }, - { - "name": "single_value", - "expr": "TestAllTypes{single_value: null}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "nullValue": null - } - }, - { - "name": "single_duration", - "expr": "TestAllTypes{single_duration: null} == TestAllTypes{}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "single_timestamp", - "expr": "TestAllTypes{single_timestamp: null} == TestAllTypes{}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "single_scalar", - "expr": "TestAllTypes{single_bool: null} == TestAllTypes{}", - "disableCheck": true, - "container": "cel.expr.conformance.proto3", - "evalError": { - "errors": [ - { - "message": "unsupported field type" - } - ] - } - }, - { - "name": "repeated", - "expr": "TestAllTypes{repeated_int32: null} == TestAllTypes{}", - "disableCheck": true, - "container": "cel.expr.conformance.proto3", - "evalError": { - "errors": [ - { - "message": "unsupported field type" - } - ] - } - }, - { - "name": "map", - "expr": "TestAllTypes{map_string_string: null} == TestAllTypes{}", - "disableCheck": true, - "container": "cel.expr.conformance.proto3", - "evalError": { - "errors": [ - { - "message": "unsupported field type" - } - ] - } - }, - { - "name": "list_value", - "expr": "TestAllTypes{list_value: null} == TestAllTypes{}", - "disableCheck": true, - "container": "cel.expr.conformance.proto3", - "evalError": { - "errors": [ - { - "message": "unsupported field type" - } - ] - } - }, - { - "name": "single_struct", - "expr": "TestAllTypes{single_struct: null} == TestAllTypes{}", - "disableCheck": true, - "container": "cel.expr.conformance.proto3", - "evalError": { - "errors": [ - { - "message": "unsupported field type" - } - ] - } - } - ] - }, - { - "name": "quoted_fields", - "test": [ - { - "name": "set_field", - "expr": "TestAllTypes{`in`: true} == TestAllTypes{}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": false - } - }, - { - "name": "get_field", - "expr": "TestAllTypes{`in`: true}.`in`", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/string.json b/packages/cel-spec/src/testdata/json/string.json deleted file mode 100644 index 5badc94d..00000000 --- a/packages/cel-spec/src/testdata/json/string.json +++ /dev/null @@ -1,405 +0,0 @@ -{ - "name": "string", - "description": "Tests for string and bytes operations.", - "section": [ - { - "name": "size", - "description": "Tests for the size() function.", - "test": [ - { - "name": "empty", - "expr": "size('')", - "value": { - "int64Value": "0" - } - }, - { - "name": "one_ascii", - "expr": "size('A')", - "value": { - "int64Value": "1" - } - }, - { - "name": "one_unicode", - "expr": "size('ÿ')", - "value": { - "int64Value": "1" - } - }, - { - "name": "ascii", - "expr": "size('four')", - "value": { - "int64Value": "4" - } - }, - { - "name": "unicode", - "expr": "size('πέντε')", - "value": { - "int64Value": "5" - } - }, - { - "name": "bytes_empty", - "expr": "size(b'')", - "value": { - "int64Value": "0" - } - }, - { - "name": "bytes", - "expr": "size(b'abc')", - "value": { - "int64Value": "3" - } - } - ] - }, - { - "name": "starts_with", - "description": "Tests for the startsWith() function.", - "test": [ - { - "name": "basic_true", - "expr": "'foobar'.startsWith('foo')", - "value": { - "boolValue": true - } - }, - { - "name": "basic_false", - "expr": "'foobar'.startsWith('bar')", - "value": { - "boolValue": false - } - }, - { - "name": "empty_target", - "expr": "''.startsWith('foo')", - "value": { - "boolValue": false - } - }, - { - "name": "empty_arg", - "expr": "'foobar'.startsWith('')", - "value": { - "boolValue": true - } - }, - { - "name": "empty_empty", - "expr": "''.startsWith('')", - "value": { - "boolValue": true - } - }, - { - "name": "unicode", - "expr": "'завтра'.startsWith('за')", - "value": { - "boolValue": true - } - }, - { - "name": "unicode_smp", - "expr": "'🐱😀😛'.startsWith('🐱')", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "ends_with", - "description": "Tests for the endsWith() function.", - "test": [ - { - "name": "basic_true", - "expr": "'foobar'.endsWith('bar')", - "value": { - "boolValue": true - } - }, - { - "name": "basic_false", - "expr": "'foobar'.endsWith('foo')", - "value": { - "boolValue": false - } - }, - { - "name": "empty_target", - "expr": "''.endsWith('foo')", - "value": { - "boolValue": false - } - }, - { - "name": "empty_arg", - "expr": "'foobar'.endsWith('')", - "value": { - "boolValue": true - } - }, - { - "name": "empty_empty", - "expr": "''.endsWith('')", - "value": { - "boolValue": true - } - }, - { - "name": "unicode", - "expr": "'forté'.endsWith('té')", - "value": { - "boolValue": true - } - }, - { - "name": "unicode_smp", - "expr": "'🐱😀😛'.endsWith('😛')", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "matches", - "description": "Tests for regexp matching. For now, we will only test the subset of regular languages.", - "test": [ - { - "name": "basic", - "expr": "'hubba'.matches('ubb')", - "value": { - "boolValue": true - } - }, - { - "name": "empty_target", - "expr": "''.matches('foo|bar')", - "value": { - "boolValue": false - } - }, - { - "name": "empty_arg", - "expr": "'cows'.matches('')", - "value": { - "boolValue": true - } - }, - { - "name": "empty_empty", - "expr": "''.matches('')", - "value": { - "boolValue": true - } - }, - { - "name": "re_concat", - "expr": "'abcd'.matches('bc')", - "value": { - "boolValue": true - } - }, - { - "name": "re_alt", - "expr": "'grey'.matches('gr(a|e)y')", - "value": { - "boolValue": true - } - }, - { - "name": "re_rep", - "expr": "'banana'.matches('ba(na)*')", - "value": { - "boolValue": true - } - }, - { - "name": "unicode", - "expr": "'mañana'.matches('a+ñ+a+')", - "value": { - "boolValue": true - } - }, - { - "name": "unicode_smp", - "expr": "'🐱😀😀'.matches('(a|😀){2}')", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "concatenation", - "description": "Tests for string concatenation.", - "test": [ - { - "name": "concat_true", - "expr": "'he' + 'llo'", - "value": { - "stringValue": "hello" - } - }, - { - "name": "concat_with_spaces", - "expr": "'hello' + ' ' == 'hello'", - "value": { - "boolValue": false - } - }, - { - "name": "concat_empty_string_beginning", - "expr": "'' + 'abc'", - "value": { - "stringValue": "abc" - } - }, - { - "name": "concat_empty_string_end", - "expr": "'abc' + ''", - "value": { - "stringValue": "abc" - } - }, - { - "name": "concat_empty_with_empty", - "expr": "'' + ''", - "value": { - "stringValue": "" - } - }, - { - "name": "unicode_unicode", - "expr": "'¢' + 'ÿ' + 'Ȁ'", - "value": { - "stringValue": "¢ÿȀ" - } - }, - { - "name": "ascii_unicode", - "expr": "'r' + 'ô' + 'le'", - "value": { - "stringValue": "rôle" - } - }, - { - "name": "ascii_unicode_unicode_smp", - "expr": "'a' + 'ÿ' + '🐱'", - "value": { - "stringValue": "aÿ🐱" - } - }, - { - "name": "empty_unicode", - "expr": "'' + 'Ω' + ''", - "value": { - "stringValue": "Ω" - } - } - ] - }, - { - "name": "contains", - "description": "Tests for contains.", - "test": [ - { - "name": "contains_true", - "expr": "'hello'.contains('he')", - "value": { - "boolValue": true - } - }, - { - "name": "contains_empty", - "expr": "'hello'.contains('')", - "value": { - "boolValue": true - } - }, - { - "name": "contains_false", - "expr": "'hello'.contains('ol')", - "value": { - "boolValue": false - } - }, - { - "name": "contains_multiple", - "expr": "'abababc'.contains('ababc')", - "value": { - "boolValue": true - } - }, - { - "name": "contains_unicode", - "expr": "'Straße'.contains('aß')", - "value": { - "boolValue": true - } - }, - { - "name": "contains_unicode_smp", - "expr": "'🐱😀😁'.contains('😀')", - "value": { - "boolValue": true - } - }, - { - "name": "empty_contains", - "expr": "''.contains('something')", - "value": { - "boolValue": false - } - }, - { - "name": "empty_empty", - "expr": "''.contains('')", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "bytes_concat", - "description": "Tests for bytes concatenation.", - "test": [ - { - "name": "concat", - "expr": "b'abc' + b'def'", - "value": { - "bytesValue": "YWJjZGVm" - } - }, - { - "name": "left_unit", - "expr": "b'' + b'\\xffoo'", - "value": { - "bytesValue": "/29v" - } - }, - { - "name": "right_unit", - "expr": "b'zxy' + b''", - "value": { - "bytesValue": "enh5" - } - }, - { - "name": "empty_empty", - "expr": "b'' + b''", - "value": { - "bytesValue": "" - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/string_ext.json b/packages/cel-spec/src/testdata/json/string_ext.json deleted file mode 100644 index 5a79cd62..00000000 --- a/packages/cel-spec/src/testdata/json/string_ext.json +++ /dev/null @@ -1,1689 +0,0 @@ -{ - "name": "string_ext", - "description": "Tests for the strings extension library.", - "section": [ - { - "name": "char_at", - "test": [ - { - "name": "middle_index", - "expr": "'tacocat'.charAt(3)", - "value": { - "stringValue": "o" - } - }, - { - "name": "end_index", - "expr": "'tacocat'.charAt(7)", - "value": { - "stringValue": "" - } - }, - { - "name": "multiple", - "expr": "'©αT'.charAt(0) == '©' && '©αT'.charAt(1) == 'α' && '©αT'.charAt(2) == 'T'" - } - ] - }, - { - "name": "index_of", - "test": [ - { - "name": "empty_index", - "expr": "'tacocat'.indexOf('')", - "value": { - "int64Value": "0" - } - }, - { - "name": "string_index", - "expr": "'tacocat'.indexOf('ac')", - "value": { - "int64Value": "1" - } - }, - { - "name": "nomatch", - "expr": "'tacocat'.indexOf('none') == -1" - }, - { - "name": "empty_index", - "expr": "'tacocat'.indexOf('', 3) == 3" - }, - { - "name": "char_index", - "expr": "'tacocat'.indexOf('a', 3) == 5" - }, - { - "name": "string_index", - "expr": "'tacocat'.indexOf('at', 3) == 5" - }, - { - "name": "unicode_char", - "expr": "'ta©o©αT'.indexOf('©') == 2" - }, - { - "name": "unicode_char_index", - "expr": "'ta©o©αT'.indexOf('©', 3) == 4" - }, - { - "name": "unicode_string_index", - "expr": "'ta©o©αT'.indexOf('©αT', 3) == 4" - }, - { - "name": "unicode_string_nomatch_index", - "expr": "'ta©o©αT'.indexOf('©α', 5) == -1" - }, - { - "name": "char_index", - "expr": "'ijk'.indexOf('k') == 2" - }, - { - "name": "string_with_space_fullmatch", - "expr": "'hello wello'.indexOf('hello wello') == 0" - }, - { - "name": "string_with_space_index", - "expr": "'hello wello'.indexOf('ello', 6) == 7" - }, - { - "name": "string_nomatch_index", - "expr": "'hello wello'.indexOf('elbo room!!') == -1" - } - ] - }, - { - "name": "last_index_of", - "test": [ - { - "name": "empty_string", - "expr": "''.lastIndexOf('@@') == -1" - }, - { - "name": "empty_argument", - "expr": "'tacocat'.lastIndexOf('') == 7" - }, - { - "name": "string", - "expr": "'tacocat'.lastIndexOf('at') == 5" - }, - { - "name": "string_nomatch", - "expr": "'tacocat'.lastIndexOf('none') == -1" - }, - { - "name": "empty_index", - "expr": "'tacocat'.lastIndexOf('', 3) == 3" - }, - { - "name": "char_index", - "expr": "'tacocat'.lastIndexOf('a', 3) == 1" - }, - { - "name": "unicode_char", - "expr": "'ta©o©αT'.lastIndexOf('©') == 4" - }, - { - "name": "unicode_char_index", - "expr": "'ta©o©αT'.lastIndexOf('©', 3) == 2" - }, - { - "name": "unicode_string_index", - "expr": "'ta©o©αT'.lastIndexOf('©α', 4) == 4" - }, - { - "name": "string_with_space_string_index", - "expr": "'hello wello'.lastIndexOf('ello', 6) == 1" - }, - { - "name": "string_with_space_string_nomatch", - "expr": "'hello wello'.lastIndexOf('low') == -1" - }, - { - "name": "string_with_space_string_with_space_nomatch", - "expr": "'hello wello'.lastIndexOf('elbo room!!') == -1" - }, - { - "name": "string_with_space_fullmatch", - "expr": "'hello wello'.lastIndexOf('hello wello') == 0" - }, - { - "name": "repeated_string", - "expr": "'bananananana'.lastIndexOf('nana', 7) == 6" - } - ] - }, - { - "name": "ascii_casing", - "test": [ - { - "name": "lowerascii", - "expr": "'TacoCat'.lowerAscii() == 'tacocat'" - }, - { - "name": "lowerascii_unicode", - "expr": "'TacoCÆt'.lowerAscii() == 'tacocÆt'" - }, - { - "name": "lowerascii_unicode_with_space", - "expr": "'TacoCÆt Xii'.lowerAscii() == 'tacocÆt xii'" - }, - { - "name": "upperascii", - "expr": "'tacoCat'.upperAscii() == 'TACOCAT'" - }, - { - "name": "upperascii_unicode", - "expr": "'tacoCαt'.upperAscii() == 'TACOCαT'" - }, - { - "name": "upperascii_unicode_with_space", - "expr": "'TacoCÆt Xii'.upperAscii() == 'TACOCÆT XII'" - } - ] - }, - { - "name": "replace", - "test": [ - { - "name": "no_placeholder", - "expr": "'12 days 12 hours'.replace('{0}', '2') == '12 days 12 hours'" - }, - { - "name": "basic", - "expr": "'{0} days {0} hours'.replace('{0}', '2') == '2 days 2 hours'" - }, - { - "name": "chained", - "expr": "'{0} days {0} hours'.replace('{0}', '2', 1).replace('{0}', '23') == '2 days 23 hours'" - }, - { - "name": "unicode", - "expr": "'1 ©αT taco'.replace('αT', 'o©α') == '1 ©o©α taco'" - } - ] - }, - { - "name": "split", - "test": [ - { - "name": "empty", - "expr": "'hello world'.split(' ') == ['hello', 'world']" - }, - { - "name": "zero_limit", - "expr": "'hello world events!'.split(' ', 0) == []" - }, - { - "name": "one_limit", - "expr": "'hello world events!'.split(' ', 1) == ['hello world events!']" - }, - { - "name": "unicode_negative_limit", - "expr": "'o©o©o©o'.split('©', -1) == ['o', 'o', 'o', 'o']" - } - ] - }, - { - "name": "substring", - "test": [ - { - "name": "start", - "expr": "'tacocat'.substring(4) == 'cat'" - }, - { - "name": "start_with_max_length", - "expr": "'tacocat'.substring(7) == ''" - }, - { - "name": "start_and_end", - "expr": "'tacocat'.substring(0, 4) == 'taco'" - }, - { - "name": "start_and_end_equal_value", - "expr": "'tacocat'.substring(4, 4) == ''" - }, - { - "name": "unicode_start_and_end", - "expr": "'ta©o©αT'.substring(2, 6) == '©o©α'" - }, - { - "name": "unicode_start_and_end_equal_value", - "expr": "'ta©o©αT'.substring(7, 7) == ''" - } - ] - }, - { - "name": "trim", - "test": [ - { - "name": "blank_spaces_escaped_chars", - "expr": "' \\f\\n\\r\\t\\vtext '.trim() == 'text'" - }, - { - "name": "unicode_space_chars_1", - "expr": "'\\u0085\\u00a0\\u1680text'.trim() == 'text'" - }, - { - "name": "unicode_space_chars_2", - "expr": "'text\\u2000\\u2001\\u2002\\u2003\\u2004\\u2004\\u2006\\u2007\\u2008\\u2009'.trim() == 'text'" - }, - { - "name": "unicode_space_chars_3", - "expr": "'\\u200atext\\u2028\\u2029\\u202F\\u205F\\u3000'.trim() == 'text'" - }, - { - "name": "unicode_no_trim", - "expr": "'\\u180etext\\u200b\\u200c\\u200d\\u2060\\ufeff'.trim() == '\\u180etext\\u200b\\u200c\\u200d\\u2060\\ufeff'" - } - ] - }, - { - "name": "join", - "test": [ - { - "name": "empty_separator", - "expr": "['x', 'y'].join() == 'xy'" - }, - { - "name": "dash_separator", - "expr": "['x', 'y'].join('-') == 'x-y'" - }, - { - "name": "empty_string_empty_separator", - "expr": "[].join() == ''" - }, - { - "name": "empty_string_dash_separator", - "expr": "[].join('-') == ''" - } - ] - }, - { - "name": "quote", - "test": [ - { - "name": "multiline", - "expr": "strings.quote(\"first\\nsecond\") == \"\\\"first\\\\nsecond\\\"\"" - }, - { - "name": "escaped", - "expr": "strings.quote(\"bell\\a\") == \"\\\"bell\\\\a\\\"\"" - }, - { - "name": "backspace", - "expr": "strings.quote(\"\\bbackspace\") == \"\\\"\\\\bbackspace\\\"\"" - }, - { - "name": "form_feed", - "expr": "strings.quote(\"\\fform feed\") == \"\\\"\\\\fform feed\\\"\"" - }, - { - "name": "carriage_return", - "expr": "strings.quote(\"carriage \\r return\") == \"\\\"carriage \\\\r return\\\"\"" - }, - { - "name": "horizontal_tab", - "expr": "strings.quote(\"horizontal tab\\t\") == \"\\\"horizontal tab\\\\t\\\"\"" - }, - { - "name": "vertical_tab", - "expr": "strings.quote(\"vertical \\v tab\") == \"\\\"vertical \\\\v tab\\\"\"" - }, - { - "name": "double_slash", - "expr": "strings.quote(\"double \\\\\\\\ slash\") == \"\\\"double \\\\\\\\\\\\\\\\ slash\\\"\"" - }, - { - "name": "two_escape_sequences", - "expr": "strings.quote(\"two escape sequences \\\\a\\\\n\") == \"\\\"two escape sequences \\\\\\\\a\\\\\\\\n\\\"\"" - }, - { - "name": "verbatim", - "expr": "strings.quote(\"verbatim\") == \"\\\"verbatim\\\"\"" - }, - { - "name": "ends_with", - "expr": "strings.quote(\"ends with \\\\\") == \"\\\"ends with \\\\\\\\\\\"\"" - }, - { - "name": "starts_with", - "expr": "strings.quote(\"\\\\ starts with\") == \"\\\"\\\\\\\\ starts with\\\"\"" - }, - { - "name": "printable_unicode", - "expr": "strings.quote(\"printable unicode😀\") == \"\\\"printable unicode😀\\\"\"" - }, - { - "name": "mid_string_quote", - "expr": "strings.quote(\"mid string \\\" quote\") == \"\\\"mid string \\\\\\\" quote\\\"\"" - }, - { - "name": "single_quote_with_double_quote", - "expr": "strings.quote('single-quote with \"double quote\"') == \"\\\"single-quote with \\\\\\\"double quote\\\\\\\"\\\"\"" - }, - { - "name": "size_unicode_char", - "expr": "strings.quote(\"size('ÿ')\") == \"\\\"size('ÿ')\\\"\"" - }, - { - "name": "size_unicode_string", - "expr": "strings.quote(\"size('πέντε')\") == \"\\\"size('πέντε')\\\"\"" - }, - { - "name": "unicode", - "expr": "strings.quote(\"завтра\") == \"\\\"завтра\\\"\"" - }, - { - "name": "unicode_code_points", - "expr": "strings.quote(\"\\U0001F431\\U0001F600\\U0001F61B\")", - "value": { - "stringValue": "\"🐱😀😛\"" - } - }, - { - "name": "unicode_2", - "expr": "strings.quote(\"ta©o©αT\") == \"\\\"ta©o©αT\\\"\"" - }, - { - "name": "empty_quote", - "expr": "strings.quote(\"\")", - "value": { - "stringValue": "\"\"" - } - } - ] - }, - { - "name": "format", - "test": [ - { - "name": "no-op", - "expr": "\"no substitution\".format([])", - "value": { - "stringValue": "no substitution" - } - }, - { - "name": "mid-string substitution", - "expr": "\"str is %s and some more\".format([\"filler\"])", - "value": { - "stringValue": "str is filler and some more" - } - }, - { - "name": "percent escaping", - "expr": "\"%% and also %%\".format([])", - "value": { - "stringValue": "% and also %" - } - }, - { - "name": "substitution inside escaped percent signs", - "expr": "\"%%%s%%\".format([\"text\"])", - "value": { - "stringValue": "%text%" - } - }, - { - "name": "substitution with one escaped percent sign on the right", - "expr": "\"%s%%\".format([\"percent on the right\"])", - "value": { - "stringValue": "percent on the right%" - } - }, - { - "name": "substitution with one escaped percent sign on the left", - "expr": "\"%%%s\".format([\"percent on the left\"])", - "value": { - "stringValue": "%percent on the left" - } - }, - { - "name": "multiple substitutions", - "expr": "\"%d %d %d, %s %s %s, %d %d %d, %s %s %s\".format([1, 2, 3, \"A\", \"B\", \"C\", 4, 5, 6, \"D\", \"E\", \"F\"])", - "value": { - "stringValue": "1 2 3, A B C, 4 5 6, D E F" - } - }, - { - "name": "percent sign escape sequence support", - "expr": "\"%%escaped %s%%\".format([\"percent\"])", - "value": { - "stringValue": "%escaped percent%" - } - }, - { - "name": "fixed point formatting clause", - "expr": "\"%.3f\".format([1.2345])", - "value": { - "stringValue": "1.234" - } - }, - { - "name": "binary formatting clause", - "expr": "\"this is 5 in binary: %b\".format([5])", - "value": { - "stringValue": "this is 5 in binary: 101" - } - }, - { - "name": "uint support for binary formatting", - "expr": "\"unsigned 64 in binary: %b\".format([uint(64)])", - "value": { - "stringValue": "unsigned 64 in binary: 1000000" - } - }, - { - "name": "bool support for binary formatting", - "expr": "\"bit set from bool: %b\".format([true])", - "value": { - "stringValue": "bit set from bool: 1" - } - }, - { - "name": "octal formatting clause", - "expr": "\"%o\".format([11])", - "value": { - "stringValue": "13" - } - }, - { - "name": "uint support for octal formatting clause", - "expr": "\"this is an unsigned octal: %o\".format([uint(65535)])", - "value": { - "stringValue": "this is an unsigned octal: 177777" - } - }, - { - "name": "lowercase hexadecimal formatting clause", - "expr": "\"%x is 20 in hexadecimal\".format([30])", - "value": { - "stringValue": "1e is 20 in hexadecimal" - } - }, - { - "name": "uppercase hexadecimal formatting clause", - "expr": "\"%X is 20 in hexadecimal\".format([30])", - "value": { - "stringValue": "1E is 20 in hexadecimal" - } - }, - { - "name": "unsigned support for hexadecimal formatting clause", - "expr": "\"%X is 6000 in hexadecimal\".format([uint(6000)])", - "value": { - "stringValue": "1770 is 6000 in hexadecimal" - } - }, - { - "name": "string support with hexadecimal formatting clause", - "expr": "\"%x\".format([\"Hello world!\"])", - "value": { - "stringValue": "48656c6c6f20776f726c6421" - } - }, - { - "name": "string support with uppercase hexadecimal formatting clause", - "expr": "\"%X\".format([\"Hello world!\"])", - "value": { - "stringValue": "48656C6C6F20776F726C6421" - } - }, - { - "name": "byte support with hexadecimal formatting clause", - "expr": "\"%x\".format([b\"byte string\"])", - "value": { - "stringValue": "6279746520737472696e67" - } - }, - { - "name": "byte support with uppercase hexadecimal formatting clause", - "expr": "\"%X\".format([b\"byte string\"])", - "value": { - "stringValue": "6279746520737472696E67" - } - }, - { - "name": "scientific notation formatting clause", - "expr": "\"%.6e\".format([1052.032911275])", - "value": { - "stringValue": "1.052033e+03" - } - }, - { - "name": "default precision for fixed-point clause", - "expr": "\"%f\".format([2.71828])", - "value": { - "stringValue": "2.718280" - } - }, - { - "name": "default precision for scientific notation", - "expr": "\"%e\".format([2.71828])", - "value": { - "stringValue": "2.718280e+00" - } - }, - { - "name": "NaN support for scientific notation", - "expr": "\"%e\".format([double(\"NaN\")])", - "value": { - "stringValue": "NaN" - } - }, - { - "name": "positive infinity support for scientific notation", - "expr": "\"%e\".format([double(\"Infinity\")])", - "value": { - "stringValue": "Infinity" - } - }, - { - "name": "negative infinity support for scientific notation", - "expr": "\"%e\".format([double(\"-Infinity\")])", - "value": { - "stringValue": "-Infinity" - } - }, - { - "name": "NaN support for decimal", - "expr": "\"%d\".format([double(\"NaN\")])", - "value": { - "stringValue": "NaN" - } - }, - { - "name": "positive infinity support for decimal", - "expr": "\"%d\".format([double(\"Infinity\")])", - "value": { - "stringValue": "Infinity" - } - }, - { - "name": "negative infinity support for decimal", - "expr": "\"%d\".format([double(\"-Infinity\")])", - "value": { - "stringValue": "-Infinity" - } - }, - { - "name": "NaN support for fixed-point", - "expr": "\"%f\".format([double(\"NaN\")])", - "value": { - "stringValue": "NaN" - } - }, - { - "name": "positive infinity support for fixed-point", - "expr": "\"%f\".format([double(\"Infinity\")])", - "value": { - "stringValue": "Infinity" - } - }, - { - "name": "negative infinity support for fixed-point", - "expr": "\"%f\".format([double(\"-Infinity\")])", - "value": { - "stringValue": "-Infinity" - } - }, - { - "name": "uint support for decimal clause", - "expr": "\"%d\".format([uint(64)])", - "value": { - "stringValue": "64" - } - }, - { - "name": "null support for string", - "expr": "\"%s\".format([null])", - "value": { - "stringValue": "null" - } - }, - { - "name": "int support for string", - "expr": "\"%s\".format([999999999999])", - "value": { - "stringValue": "999999999999" - } - }, - { - "name": "bytes support for string", - "expr": "\"%s\".format([b\"xyz\"])", - "value": { - "stringValue": "xyz" - } - }, - { - "name": "type() support for string", - "expr": "\"%s\".format([type(\"test string\")])", - "value": { - "stringValue": "string" - } - }, - { - "name": "timestamp support for string", - "expr": "\"%s\".format([timestamp(\"2023-02-03T23:31:20+00:00\")])", - "value": { - "stringValue": "2023-02-03T23:31:20Z" - } - }, - { - "name": "duration support for string", - "expr": "\"%s\".format([duration(\"1h45m47s\")])", - "value": { - "stringValue": "6347s" - } - }, - { - "name": "list support for string", - "expr": "\"%s\".format([[\"abc\", 3.14, null, [9, 8, 7, 6], timestamp(\"2023-02-03T23:31:20Z\")]])", - "value": { - "stringValue": "[abc, 3.14, null, [9, 8, 7, 6], 2023-02-03T23:31:20Z]" - } - }, - { - "name": "map support for string", - "expr": "\"%s\".format([{\"key1\": b\"xyz\", \"key5\": null, \"key2\": duration(\"2h\"), \"key4\": true, \"key3\": 2.71828}])", - "value": { - "stringValue": "{key1: xyz, key2: 7200s, key3: 2.71828, key4: true, key5: null}" - } - }, - { - "name": "map support (all key types)", - "expr": "\"%s\".format([{1: \"value1\", uint(2): \"value2\", true: double(\"NaN\")}])", - "value": { - "stringValue": "{1: value1, 2: value2, true: NaN}" - } - }, - { - "name": "boolean support for %s", - "expr": "\"%s, %s\".format([true, false])", - "value": { - "stringValue": "true, false" - } - }, - { - "name": "dyntype support for string formatting clause", - "expr": "\"%s\".format([dyn(\"a string\")])", - "value": { - "stringValue": "a string" - } - }, - { - "name": "dyntype support for numbers with string formatting clause", - "expr": "\"%s, %s\".format([dyn(32), dyn(56.8)])", - "value": { - "stringValue": "32, 56.8" - } - }, - { - "name": "dyntype support for integer formatting clause", - "expr": "\"%d\".format([dyn(128)])", - "value": { - "stringValue": "128" - } - }, - { - "name": "dyntype support for integer formatting clause (unsigned)", - "expr": "\"%d\".format([dyn(256u)])", - "value": { - "stringValue": "256" - } - }, - { - "name": "dyntype support for hex formatting clause", - "expr": "\"%x\".format([dyn(22)])", - "value": { - "stringValue": "16" - } - }, - { - "name": "dyntype support for hex formatting clause (uppercase)", - "expr": "\"%X\".format([dyn(26)])", - "value": { - "stringValue": "1A" - } - }, - { - "name": "dyntype support for unsigned hex formatting clause", - "expr": "\"%x\".format([dyn(500u)])", - "value": { - "stringValue": "1f4" - } - }, - { - "name": "dyntype support for fixed-point formatting clause", - "expr": "\"%.3f\".format([dyn(4.5)])", - "value": { - "stringValue": "4.500" - } - }, - { - "name": "dyntype support for scientific notation", - "expr": "\"%e\".format([dyn(2.71828)])", - "value": { - "stringValue": "2.718280e+00" - } - }, - { - "name": "dyntype NaN/infinity support", - "expr": "\"%s\".format([[double(\"NaN\"), double(\"Infinity\"), double(\"-Infinity\")]])", - "value": { - "stringValue": "[NaN, Infinity, -Infinity]" - } - }, - { - "name": "dyntype support for timestamp", - "expr": "\"%s\".format([dyn(timestamp(\"2009-11-10T23:00:00Z\"))])", - "value": { - "stringValue": "2009-11-10T23:00:00Z" - } - }, - { - "name": "dyntype support for duration", - "expr": "\"%s\".format([dyn(duration(\"8747s\"))])", - "value": { - "stringValue": "8747s" - } - }, - { - "name": "dyntype support for lists", - "expr": "\"%s\".format([dyn([6, 4.2, \"a string\"])])", - "value": { - "stringValue": "[6, 4.2, a string]" - } - }, - { - "name": "dyntype support for maps", - "expr": "\"%s\".format([{\"strKey\":\"x\", 6:duration(\"422s\"), true:42}])", - "value": { - "stringValue": "{6: 422s, strKey: x, true: 42}" - } - }, - { - "name": "string substitution in a string variable", - "expr": "str_var.format([\"filler\"])", - "typeEnv": [ - { - "name": "str_var", - "ident": { - "type": { - "primitive": "STRING" - } - } - } - ], - "bindings": { - "str_var": { - "value": { - "stringValue": "%s" - } - } - }, - "value": { - "stringValue": "filler" - } - }, - { - "name": "multiple substitutions in a string variable", - "expr": "str_var.format([1, 2, 3, \"A\", \"B\", \"C\", 4, 5, 6, \"D\", \"E\", \"F\"])", - "typeEnv": [ - { - "name": "str_var", - "ident": { - "type": { - "primitive": "STRING" - } - } - } - ], - "bindings": { - "str_var": { - "value": { - "stringValue": "%d %d %d, %s %s %s, %d %d %d, %s %s %s" - } - } - }, - "value": { - "stringValue": "1 2 3, A B C, 4 5 6, D E F" - } - }, - { - "name": "substitution inside escaped percent signs in a string variable", - "expr": "str_var.format([\"text\"])", - "typeEnv": [ - { - "name": "str_var", - "ident": { - "type": { - "primitive": "STRING" - } - } - } - ], - "bindings": { - "str_var": { - "value": { - "stringValue": "%%%s%%" - } - } - }, - "value": { - "stringValue": "%text%" - } - }, - { - "name": "fixed point formatting clause in a string variable", - "expr": "str_var.format([1.2345])", - "typeEnv": [ - { - "name": "str_var", - "ident": { - "type": { - "primitive": "STRING" - } - } - } - ], - "bindings": { - "str_var": { - "value": { - "stringValue": "%.3f" - } - } - }, - "value": { - "stringValue": "1.234" - } - }, - { - "name": "binary formatting clause in a string variable", - "expr": "str_var.format([5])", - "typeEnv": [ - { - "name": "str_var", - "ident": { - "type": { - "primitive": "STRING" - } - } - } - ], - "bindings": { - "str_var": { - "value": { - "stringValue": "%b" - } - } - }, - "value": { - "stringValue": "101" - } - }, - { - "name": "scientific notation formatting clause in a string variable", - "expr": "str_var.format([1052.032911275])", - "typeEnv": [ - { - "name": "str_var", - "ident": { - "type": { - "primitive": "STRING" - } - } - } - ], - "bindings": { - "str_var": { - "value": { - "stringValue": "%.6e" - } - } - }, - "value": { - "stringValue": "1.052033e+03" - } - }, - { - "name": "default precision for fixed-point clause in a string variable", - "expr": "str_var.format([2.71828])", - "typeEnv": [ - { - "name": "str_var", - "ident": { - "type": { - "primitive": "STRING" - } - } - } - ], - "bindings": { - "str_var": { - "value": { - "stringValue": "%f" - } - } - }, - "value": { - "stringValue": "2.718280" - } - }, - { - "name": "format_%f_insignificant_zeroes_removed", - "expr": "\"%.0f\".format([123.000000])", - "value": { - "stringValue": "123" - } - }, - { - "name": "format_%f_positive_round_to_whole_number", - "expr": "\"%.0f\".format([3.5001])", - "value": { - "stringValue": "4" - } - }, - { - "name": "format_%f_negative_truncate_to_whole_number", - "expr": "\"%.0f\".format([3.4999])", - "value": { - "stringValue": "3" - } - }, - { - "name": "format_%f_halfway_round_up_to_nearest_even", - "expr": "\"%.0f\".format([1.5])", - "value": { - "stringValue": "2" - } - }, - { - "name": "format_%f_halfway_truncate_to_nearest_even", - "expr": "\"%.0f\".format([2.5])", - "value": { - "stringValue": "2" - } - }, - { - "name": "format_%f_positive_round_up", - "expr": "\"%.3f\".format([123.4999])", - "value": { - "stringValue": "123.500" - } - }, - { - "name": "format_%f_positive_round_down", - "expr": "\"%.3f\".format([123.4994])", - "value": { - "stringValue": "123.499" - } - }, - { - "name": "format_%f_negative_round_up", - "expr": "\"%.3f\".format([-123.4999])", - "value": { - "stringValue": "-123.500" - } - }, - { - "name": "format_%f_negative_round_down", - "expr": "\"%.3f\".format([-123.4994])", - "value": { - "stringValue": "-123.499" - } - }, - { - "name": "format_%f_zero_padding", - "expr": "\"%.5f\".format([-1.2])", - "value": { - "stringValue": "-1.20000" - } - } - ] - }, - { - "name": "format_errors", - "test": [ - { - "name": "unrecognized formatting clause", - "expr": "\"%a\".format([1])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "could not parse formatting clause: unrecognized formatting clause \"a\"" - } - ] - } - }, - { - "name": "out of bounds arg index", - "expr": "\"%d %d %d\".format([0, 1])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "index 2 out of range" - } - ] - } - }, - { - "name": "string substitution is not allowed with binary clause", - "expr": "\"string is %b\".format([\"abc\"])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "error during formatting: only integers and bools can be formatted as binary, was given string" - } - ] - } - }, - { - "name": "duration substitution not allowed with decimal clause", - "expr": "\"%d\".format([duration(\"30m2s\")])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "error during formatting: decimal clause can only be used on integers, was given google.protobuf.Duration" - } - ] - } - }, - { - "name": "string substitution not allowed with octal clause", - "expr": "\"octal: %o\".format([\"a string\"])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "error during formatting: octal clause can only be used on integers, was given string" - } - ] - } - }, - { - "name": "double substitution not allowed with hex clause", - "expr": "\"double is %x\".format([0.5])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "error during formatting: only integers, byte buffers, and strings can be formatted as hex, was given double" - } - ] - } - }, - { - "name": "uppercase not allowed for scientific clause", - "expr": "\"double is %E\".format([0.5])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "could not parse formatting clause: unrecognized formatting clause \"E\"" - } - ] - } - }, - { - "name": "object not allowed", - "expr": "\"object is %s\".format([cel.expr.conformance.proto3.TestAllTypes{}])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "error during formatting: string clause can only be used on strings, bools, bytes, ints, doubles, maps, lists, types, durations, and timestamps, was given cel.expr.conformance.proto3.TestAllTypes" - } - ] - } - }, - { - "name": "object inside list", - "expr": "\"%s\".format([[1, 2, cel.expr.conformance.proto3.TestAllTypes{}]])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "error during formatting: string clause can only be used on strings, bools, bytes, ints, doubles, maps, lists, types, durations, and timestamps, was given cel.expr.conformance.proto3.TestAllTypes" - } - ] - } - }, - { - "name": "object inside map", - "expr": "\"%s\".format([{1: \"a\", 2: cel.expr.conformance.proto3.TestAllTypes{}}])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "error during formatting: string clause can only be used on strings, bools, bytes, ints, doubles, maps, lists, types, durations, and timestamps, was given cel.expr.conformance.proto3.TestAllTypes" - } - ] - } - }, - { - "name": "null not allowed for %d", - "expr": "\"null: %d\".format([null])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "error during formatting: decimal clause can only be used on integers, was given null_type" - } - ] - } - }, - { - "name": "null not allowed for %e", - "expr": "\"null: %e\".format([null])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "error during formatting: scientific clause can only be used on doubles, was given null_type" - } - ] - } - }, - { - "name": "null not allowed for %f", - "expr": "\"null: %f\".format([null])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "error during formatting: fixed-point clause can only be used on doubles, was given null_type" - } - ] - } - }, - { - "name": "null not allowed for %x", - "expr": "\"null: %x\".format([null])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "error during formatting: only integers, byte buffers, and strings can be formatted as hex, was given null_type" - } - ] - } - }, - { - "name": "null not allowed for %X", - "expr": "\"null: %X\".format([null])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "error during formatting: only integers, byte buffers, and strings can be formatted as hex, was given null_type" - } - ] - } - }, - { - "name": "null not allowed for %b", - "expr": "\"null: %b\".format([null])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "error during formatting: only integers and bools can be formatted as binary, was given null_type" - } - ] - } - }, - { - "name": "null not allowed for %o", - "expr": "\"null: %o\".format([null])", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "error during formatting: octal clause can only be used on integers, was given null_type" - } - ] - } - } - ] - }, - { - "name": "value_errors", - "test": [ - { - "name": "charat_out_of_range", - "expr": "'tacocat'.charAt(30) == ''", - "evalError": { - "errors": [ - { - "message": "index out of range: 30" - } - ] - } - }, - { - "name": "indexof_out_of_range", - "expr": "'tacocat'.indexOf('a', 30) == -1", - "evalError": { - "errors": [ - { - "message": "index out of range: 30" - } - ] - } - }, - { - "name": "lastindexof_negative_index", - "expr": "'tacocat'.lastIndexOf('a', -1) == -1", - "evalError": { - "errors": [ - { - "message": "index out of range: -1" - } - ] - } - }, - { - "name": "lastindexof_out_of_range", - "expr": "'tacocat'.lastIndexOf('a', 30) == -1", - "evalError": { - "errors": [ - { - "message": "index out of range: 30" - } - ] - } - }, - { - "name": "substring_out_of_range", - "expr": "'tacocat'.substring(40) == 'cat'", - "evalError": { - "errors": [ - { - "message": "index out of range: 40" - } - ] - } - }, - { - "name": "substring_negative_index", - "expr": "'tacocat'.substring(-1) == 'cat'", - "evalError": { - "errors": [ - { - "message": "index out of range: -1" - } - ] - } - }, - { - "name": "substring_end_index_out_of_range", - "expr": "'tacocat'.substring(1, 50) == 'cat'", - "evalError": { - "errors": [ - { - "message": "index out of range: 50" - } - ] - } - }, - { - "name": "substring_begin_index_out_of_range", - "expr": "'tacocat'.substring(49, 50) == 'cat'", - "evalError": { - "errors": [ - { - "message": "index out of range: 49" - } - ] - } - }, - { - "name": "substring_end_index_greater_than_begin_index", - "expr": "'tacocat'.substring(4, 3) == ''", - "evalError": { - "errors": [ - { - "message": "invalid substring range. start: 4, end: 3" - } - ] - } - } - ] - }, - { - "name": "type_errors", - "test": [ - { - "name": "charat_invalid_type", - "expr": "42.charAt(2) == ''", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "charat_invalid_argument", - "expr": "'hello'.charAt(true) == ''", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "indexof_unary_invalid_type", - "expr": "24.indexOf('2') == 0", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "indexof_unary_invalid_argument", - "expr": "'hello'.indexOf(true) == 1", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "indexof_binary_invalid_argument", - "expr": "42.indexOf('4', 0) == 0", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "indexof_binary_invalid_argument_2", - "expr": "'42'.indexOf(4, 0) == 0", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "indexof_binary_both_invalid_arguments", - "expr": "'42'.indexOf('4', '0') == 0", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "indexof_ternary_invalid_arguments", - "expr": "'42'.indexOf('4', 0, 1) == 0", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "split_invalid_type", - "expr": "42.split('2') == ['4']", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "replace_invalid_type", - "expr": "42.replace(2, 1) == '41'", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "replace_binary_invalid_argument", - "expr": "'42'.replace(2, 1) == '41'", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "replace_binary_invalid_argument_2", - "expr": "'42'.replace('2', 1) == '41'", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "replace_ternary_invalid_argument", - "expr": "42.replace('2', '1', 1) == '41'", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "replace_ternary_invalid_argument_2", - "expr": "'42'.replace(2, '1', 1) == '41'", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "replace_ternary_invalid_argument_3", - "expr": "'42'.replace('2', 1, 1) == '41'", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "replace_ternary_invalid_argument_4", - "expr": "'42'.replace('2', '1', '1') == '41'", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "replace_quaternary_invalid_argument", - "expr": "'42'.replace('2', '1', 1, false) == '41'", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "split_invalid_type_empty_arg", - "expr": "42.split('') == ['4', '2']", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "split_invalid_argument", - "expr": "'42'.split(2) == ['4']", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "split_binary_invalid_type", - "expr": "42.split('2', '1') == ['4']", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "split_binary_invalid_argument", - "expr": "'42'.split(2, 1) == ['4']", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "split_binary_invalid_argument_2", - "expr": "'42'.split('2', '1') == ['4']", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "split_ternary_invalid_argument", - "expr": "'42'.split('2', 1, 1) == ['4']", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "substring_ternary_invalid_argument", - "expr": "'hello'.substring(1, 2, 3) == ''", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "substring_binary_invalid_type", - "expr": "30.substring(true, 3) == ''", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "substring_binary_invalid_argument", - "expr": "'tacocat'.substring(true, 3) == ''", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - }, - { - "name": "substring_binary_invalid_argument_2", - "expr": "'tacocat'.substring(0, false) == ''", - "disableCheck": true, - "evalError": { - "errors": [ - { - "message": "no such overload" - } - ] - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/timestamps.json b/packages/cel-spec/src/testdata/json/timestamps.json deleted file mode 100644 index d015e023..00000000 --- a/packages/cel-spec/src/testdata/json/timestamps.json +++ /dev/null @@ -1,681 +0,0 @@ -{ - "name": "timestamps", - "description": "Timestamp and duration tests.", - "section": [ - { - "name": "timestamp_conversions", - "description": "Conversions of timestamps to other types.", - "test": [ - { - "name": "toInt_timestamp", - "expr": "int(timestamp('2009-02-13T23:31:30Z'))", - "value": { - "int64Value": "1234567890" - } - }, - { - "name": "toString_timestamp", - "expr": "string(timestamp('2009-02-13T23:31:30Z'))", - "value": { - "stringValue": "2009-02-13T23:31:30Z" - } - }, - { - "name": "toString_timestamp_nanos", - "expr": "string(timestamp('9999-12-31T23:59:59.999999999Z'))", - "value": { - "stringValue": "9999-12-31T23:59:59.999999999Z" - } - }, - { - "name": "toType_timestamp", - "expr": "type(timestamp('2009-02-13T23:31:30Z'))", - "value": { - "typeValue": "google.protobuf.Timestamp" - } - }, - { - "name": "type_comparison", - "expr": "google.protobuf.Timestamp == type(timestamp('2009-02-13T23:31:30Z'))", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "duration_conversions", - "description": "Conversions of durations to other types.", - "test": [ - { - "name": "toString_duration", - "expr": "string(duration('1000000s'))", - "value": { - "stringValue": "1000000s" - } - }, - { - "name": "toType_duration", - "expr": "type(duration('1000000s'))", - "value": { - "typeValue": "google.protobuf.Duration" - } - }, - { - "name": "type_comparison", - "expr": "google.protobuf.Duration == type(duration('1000000s'))", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "timestamp_selectors", - "description": "Timestamp selection operators without timezones", - "test": [ - { - "name": "getDate", - "expr": "timestamp('2009-02-13T23:31:30Z').getDate()", - "value": { - "int64Value": "13" - } - }, - { - "name": "getDayOfMonth", - "expr": "timestamp('2009-02-13T23:31:30Z').getDayOfMonth()", - "value": { - "int64Value": "12" - } - }, - { - "name": "getDayOfWeek", - "expr": "timestamp('2009-02-13T23:31:30Z').getDayOfWeek()", - "value": { - "int64Value": "5" - } - }, - { - "name": "getDayOfYear", - "expr": "timestamp('2009-02-13T23:31:30Z').getDayOfYear()", - "value": { - "int64Value": "43" - } - }, - { - "name": "getFullYear", - "expr": "timestamp('2009-02-13T23:31:30Z').getFullYear()", - "value": { - "int64Value": "2009" - } - }, - { - "name": "getHours", - "expr": "timestamp('2009-02-13T23:31:30Z').getHours()", - "value": { - "int64Value": "23" - } - }, - { - "name": "getMilliseconds", - "expr": "timestamp('2009-02-13T23:31:20.123456789Z').getMilliseconds()", - "value": { - "int64Value": "123" - } - }, - { - "name": "getMinutes", - "expr": "timestamp('2009-02-13T23:31:30Z').getMinutes()", - "value": { - "int64Value": "31" - } - }, - { - "name": "getMonth", - "expr": "timestamp('2009-02-13T23:31:30Z').getMonth()", - "value": { - "int64Value": "1" - } - }, - { - "name": "getSeconds", - "expr": "timestamp('2009-02-13T23:31:30Z').getSeconds()", - "value": { - "int64Value": "30" - } - } - ] - }, - { - "name": "timestamp_selectors_tz", - "description": "Timestamp selection operators with timezones", - "test": [ - { - "name": "getDate", - "expr": "timestamp('2009-02-13T23:31:30Z').getDate('Australia/Sydney')", - "value": { - "int64Value": "14" - } - }, - { - "name": "getDayOfMonth_name_pos", - "expr": "timestamp('2009-02-13T23:31:30Z').getDayOfMonth('US/Central')", - "value": { - "int64Value": "12" - } - }, - { - "name": "getDayOfMonth_numerical_pos", - "expr": "timestamp('2009-02-13T23:31:30Z').getDayOfMonth('+11:00')", - "value": { - "int64Value": "13" - } - }, - { - "name": "getDayOfMonth_numerical_neg", - "expr": "timestamp('2009-02-13T02:00:00Z').getDayOfMonth('-02:30')", - "value": { - "int64Value": "11" - } - }, - { - "name": "getDayOfMonth_name_neg", - "expr": "timestamp('2009-02-13T02:00:00Z').getDayOfMonth('America/St_Johns')", - "value": { - "int64Value": "11" - } - }, - { - "name": "getDayOfWeek", - "expr": "timestamp('2009-02-13T23:31:30Z').getDayOfWeek('UTC')", - "value": { - "int64Value": "5" - } - }, - { - "name": "getDayOfYear", - "expr": "timestamp('2009-02-13T23:31:30Z').getDayOfYear('US/Central')", - "value": { - "int64Value": "43" - } - }, - { - "name": "getFullYear", - "expr": "timestamp('2009-02-13T23:31:30Z').getFullYear('-09:30')", - "value": { - "int64Value": "2009" - } - }, - { - "name": "getHours", - "expr": "timestamp('2009-02-13T23:31:30Z').getHours('02:00')", - "value": { - "int64Value": "1" - } - }, - { - "name": "getMinutes", - "expr": "timestamp('2009-02-13T23:31:30Z').getMinutes('Asia/Kathmandu')", - "value": { - "int64Value": "16" - } - }, - { - "name": "getMonth", - "expr": "timestamp('2009-02-13T23:31:30Z').getMonth('UTC')", - "value": { - "int64Value": "1" - } - }, - { - "name": "getSeconds", - "expr": "timestamp('2009-02-13T23:31:30Z').getSeconds('-00:00')", - "value": { - "int64Value": "30" - } - } - ] - }, - { - "name": "timestamp_equality", - "description": "Equality operations on timestamps.", - "test": [ - { - "name": "eq_same", - "expr": "timestamp('2009-02-13T23:31:30Z') == timestamp('2009-02-13T23:31:30Z')", - "value": { - "boolValue": true - } - }, - { - "name": "eq_diff", - "expr": "timestamp('2009-02-13T23:31:29Z') == timestamp('2009-02-13T23:31:30Z')", - "value": { - "boolValue": false - } - }, - { - "name": "neq_same", - "expr": "timestamp('1945-05-07T02:41:00Z') != timestamp('1945-05-07T02:41:00Z')", - "value": { - "boolValue": false - } - }, - { - "name": "neq_diff", - "expr": "timestamp('2000-01-01T00:00:00Z') != timestamp('2001-01-01T00:00:00Z')", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "duration_equality", - "description": "Equality tests for durations.", - "test": [ - { - "name": "eq_same", - "expr": "duration('123s') == duration('123s')", - "value": { - "boolValue": true - } - }, - { - "name": "eq_diff", - "expr": "duration('60s') == duration('3600s')", - "value": { - "boolValue": false - } - }, - { - "name": "neq_same", - "expr": "duration('604800s') != duration('604800s')", - "value": { - "boolValue": false - } - }, - { - "name": "neq_diff", - "expr": "duration('86400s') != duration('86164s')", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "timestamp_arithmetic", - "description": "Arithmetic operations on timestamps and/or durations.", - "test": [ - { - "name": "add_duration_to_time", - "expr": "timestamp('2009-02-13T23:00:00Z') + duration('240s') == timestamp('2009-02-13T23:04:00Z')", - "value": { - "boolValue": true - } - }, - { - "name": "add_time_to_duration", - "expr": "duration('120s') + timestamp('2009-02-13T23:01:00Z') == timestamp('2009-02-13T23:03:00Z')", - "value": { - "boolValue": true - } - }, - { - "name": "add_duration_to_duration", - "expr": "duration('600s') + duration('50s') == duration('650s')", - "value": { - "boolValue": true - } - }, - { - "name": "add_time_to_duration_nanos_negative", - "expr": "timestamp('0001-01-01T00:00:01.000000001Z') + duration('-999999999ns') == timestamp('0001-01-01T00:00:00.000000002Z')", - "value": { - "boolValue": true - } - }, - { - "name": "add_time_to_duration_nanos_positive", - "expr": "timestamp('0001-01-01T00:00:01.999999999Z') + duration('999999999ns') == timestamp('0001-01-01T00:00:02.999999998Z')", - "value": { - "boolValue": true - } - }, - { - "name": "subtract_duration_from_time", - "expr": "timestamp('2009-02-13T23:10:00Z') - duration('600s') == timestamp('2009-02-13T23:00:00Z')", - "value": { - "boolValue": true - } - }, - { - "name": "subtract_time_from_time", - "expr": "timestamp('2009-02-13T23:31:00Z') - timestamp('2009-02-13T23:29:00Z') == duration('120s')", - "value": { - "boolValue": true - } - }, - { - "name": "subtract_duration_from_duration", - "expr": "duration('900s') - duration('42s') == duration('858s')", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "comparisons", - "description": "Comparisons on timestamps and/or durations.", - "test": [ - { - "name": "leq_timestamp_true", - "expr": "timestamp('2009-02-13T23:00:00Z') <= timestamp('2009-02-13T23:00:00Z')", - "value": { - "boolValue": true - } - }, - { - "name": "leq_timestamp_false", - "expr": "timestamp('2009-02-13T23:00:00Z') <= timestamp('2009-02-13T22:59:59Z')", - "value": { - "boolValue": false - } - }, - { - "name": "leq_duration_true", - "expr": "duration('200s') <= duration('200s')", - "value": { - "boolValue": true - } - }, - { - "name": "leq_duration_false", - "expr": "duration('300s') <= duration('200s')", - "value": { - "boolValue": false - } - }, - { - "name": "less_timestamp_true", - "expr": "timestamp('2009-02-13T23:00:00Z') < timestamp('2009-03-13T23:00:00Z')", - "value": { - "boolValue": true - } - }, - { - "name": "less_duration_true", - "expr": "duration('200s') < duration('300s')", - "value": { - "boolValue": true - } - }, - { - "name": "geq_timestamp_true", - "expr": "timestamp('2009-02-13T23:00:00Z') >= timestamp('2009-02-13T23:00:00Z')", - "value": { - "boolValue": true - } - }, - { - "name": "geq_timestamp_false", - "expr": "timestamp('2009-02-13T22:58:00Z') >= timestamp('2009-02-13T23:00:00Z')", - "value": { - "boolValue": false - } - }, - { - "name": "geq_duration_true", - "expr": "duration('200s') >= duration('200s')", - "value": { - "boolValue": true - } - }, - { - "name": "geq_duration_false", - "expr": "duration('120s') >= duration('200s')", - "value": { - "boolValue": false - } - }, - { - "name": "greater_timestamp_true", - "expr": "timestamp('2009-02-13T23:59:00Z') > timestamp('2009-02-13T23:00:00Z')", - "value": { - "boolValue": true - } - }, - { - "name": "greater_duration_true", - "expr": "duration('300s') > duration('200s')", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "duration_converters", - "description": "Conversion functions on durations. Unlike timestamps, we don't, e.g. select the 'minutes' field - we convert the duration to integer minutes.", - "test": [ - { - "name": "get_hours", - "expr": "duration('10000s').getHours()", - "value": { - "int64Value": "2" - } - }, - { - "name": "get_milliseconds", - "description": "Obtain the milliseconds component of the duration. Note, this is not the same as converting the duration to milliseconds. This behavior will be deprecated.", - "expr": "x.getMilliseconds()", - "typeEnv": [ - { - "name": "x", - "ident": { - "type": { - "messageType": "google.protobuf.Duration" - } - } - } - ], - "bindings": { - "x": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.Duration", - "value": "123.321456789s" - } - } - } - }, - "value": { - "int64Value": "321" - } - }, - { - "name": "get_minutes", - "expr": "duration('3730s').getMinutes()", - "value": { - "int64Value": "62" - } - }, - { - "name": "get_seconds", - "expr": "duration('3730s').getSeconds()", - "value": { - "int64Value": "3730" - } - } - ] - }, - { - "name": "timestamp_range", - "description": "Tests for out-of-range operations on timestamps.", - "test": [ - { - "name": "from_string_under", - "expr": "timestamp('0000-01-01T00:00:00Z')", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "from_string_over", - "expr": "timestamp('10000-01-01T00:00:00Z')", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "add_duration_under", - "expr": "timestamp('0001-01-01T00:00:00Z') + duration('-1s')", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "add_duration_over", - "expr": "timestamp('9999-12-31T23:59:59Z') + duration('1s')", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "add_duration_nanos_over", - "expr": "timestamp('9999-12-31T23:59:59.999999999Z') + duration('1ns')", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "add_duration_nanos_under", - "expr": "timestamp('0001-01-01T00:00:00Z') + duration('-1ns')", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "sub_time_duration_over", - "expr": "timestamp('9999-12-31T23:59:59Z') - timestamp('0001-01-01T00:00:00Z')", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "sub_time_duration_under", - "expr": "timestamp('0001-01-01T00:00:00Z') - timestamp('9999-12-31T23:59:59Z')", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - } - ] - }, - { - "name": "duration_range", - "description": "Tests for out-of-range operations on durations.", - "test": [ - { - "name": "from_string_under", - "expr": "duration('-320000000000s')", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "from_string_over", - "expr": "duration('320000000000s')", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "add_under", - "expr": "duration('-200000000000s') + duration('-200000000000s')", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "add_over", - "expr": "duration('200000000000s') + duration('200000000000s')", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "sub_under", - "expr": "duration('-200000000000s') - duration('200000000000s')", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - }, - { - "name": "sub_over", - "expr": "duration('200000000000s') - duration('-200000000000s')", - "evalError": { - "errors": [ - { - "message": "range" - } - ] - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/type_deductions.json b/packages/cel-spec/src/testdata/json/type_deductions.json deleted file mode 100644 index 22cf354e..00000000 --- a/packages/cel-spec/src/testdata/json/type_deductions.json +++ /dev/null @@ -1,1171 +0,0 @@ -{ - "name": "type_deductions", - "description": "Tests for type checker deduced types", - "section": [ - { - "name": "constant_literals", - "test": [ - { - "name": "bool", - "expr": "true", - "typedResult": { - "result": { - "boolValue": true - }, - "deducedType": { - "primitive": "BOOL" - } - } - }, - { - "name": "int", - "expr": "42", - "typedResult": { - "result": { - "int64Value": "42" - }, - "deducedType": { - "primitive": "INT64" - } - } - }, - { - "name": "uint", - "expr": "42u", - "typedResult": { - "result": { - "uint64Value": "42" - }, - "deducedType": { - "primitive": "UINT64" - } - } - }, - { - "name": "double", - "expr": "0.1", - "typedResult": { - "result": { - "doubleValue": 0.1 - }, - "deducedType": { - "primitive": "DOUBLE" - } - } - }, - { - "name": "string", - "expr": "\"test\"", - "typedResult": { - "result": { - "stringValue": "test" - }, - "deducedType": { - "primitive": "STRING" - } - } - }, - { - "name": "bytes", - "expr": "b\"test\"", - "typedResult": { - "result": { - "bytesValue": "dGVzdA==" - }, - "deducedType": { - "primitive": "BYTES" - } - } - }, - { - "name": "null", - "expr": "null", - "typedResult": { - "result": { - "nullValue": null - }, - "deducedType": { - "null": null - } - } - } - ] - }, - { - "name": "complex_initializers", - "test": [ - { - "name": "list", - "expr": "[1]", - "typedResult": { - "result": { - "listValue": { - "values": [ - { - "int64Value": "1" - } - ] - } - }, - "deducedType": { - "listType": { - "elemType": { - "primitive": "INT64" - } - } - } - } - }, - { - "name": "map", - "expr": "{'abc': 123}", - "typedResult": { - "result": { - "mapValue": { - "entries": [ - { - "key": { - "stringValue": "abc" - }, - "value": { - "int64Value": "123" - } - } - ] - } - }, - "deducedType": { - "mapType": { - "keyType": { - "primitive": "STRING" - }, - "valueType": { - "primitive": "INT64" - } - } - } - } - }, - { - "name": "struct", - "expr": "TestAllTypes{single_int64: 1}", - "container": "cel.expr.conformance.proto3", - "typedResult": { - "result": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes", - "singleInt64": "1" - } - }, - "deducedType": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ] - }, - { - "name": "field_access", - "test": [ - { - "name": "int_field", - "expr": "TestAllTypes{single_int64: 1}.single_int64", - "container": "cel.expr.conformance.proto3", - "typedResult": { - "result": { - "int64Value": "1" - }, - "deducedType": { - "primitive": "INT64" - } - } - }, - { - "name": "repeated_int_field", - "expr": "TestAllTypes{}.repeated_int64", - "container": "cel.expr.conformance.proto3", - "typedResult": { - "result": { - "listValue": {} - }, - "deducedType": { - "listType": { - "elemType": { - "primitive": "INT64" - } - } - } - } - }, - { - "name": "map_bool_int", - "expr": "TestAllTypes{}.map_bool_int64", - "container": "cel.expr.conformance.proto3", - "typedResult": { - "result": { - "mapValue": {} - }, - "deducedType": { - "mapType": { - "keyType": { - "primitive": "BOOL" - }, - "valueType": { - "primitive": "INT64" - } - } - } - } - }, - { - "name": "enum_field", - "expr": "TestAllTypes{}.standalone_enum", - "container": "cel.expr.conformance.proto3", - "typedResult": { - "result": { - "int64Value": "0" - }, - "deducedType": { - "primitive": "INT64" - } - } - }, - { - "name": "repeated_enum_field", - "expr": "TestAllTypes{}.repeated_nested_enum", - "container": "cel.expr.conformance.proto3", - "typedResult": { - "result": { - "listValue": {} - }, - "deducedType": { - "listType": { - "elemType": { - "primitive": "INT64" - } - } - } - } - }, - { - "name": "enum_map_field", - "expr": "TestAllTypes{}.map_int32_enum", - "container": "cel.expr.conformance.proto3", - "typedResult": { - "result": { - "mapValue": {} - }, - "deducedType": { - "mapType": { - "keyType": { - "primitive": "INT64" - }, - "valueType": { - "primitive": "INT64" - } - } - } - } - } - ] - }, - { - "name": "indexing", - "test": [ - { - "name": "list", - "expr": "['foo'][0]", - "typedResult": { - "result": { - "stringValue": "foo" - }, - "deducedType": { - "primitive": "STRING" - } - } - }, - { - "name": "map", - "expr": "{'abc': 123}['abc']", - "typedResult": { - "result": { - "int64Value": "123" - }, - "deducedType": { - "primitive": "INT64" - } - } - } - ] - }, - { - "name": "functions", - "test": [ - { - "name": "nested_calls", - "expr": "('foo' + 'bar').startsWith('foo')", - "typedResult": { - "result": { - "boolValue": true - }, - "deducedType": { - "primitive": "BOOL" - } - } - }, - { - "name": "function_result_type", - "expr": "fn('abc', 123)", - "checkOnly": true, - "typeEnv": [ - { - "name": "fn", - "function": { - "overloads": [ - { - "overloadId": "fn_string_int", - "params": [ - { - "primitive": "STRING" - }, - { - "primitive": "INT64" - } - ], - "resultType": { - "primitive": "STRING" - } - } - ] - } - } - ], - "typedResult": { - "deducedType": { - "primitive": "STRING" - } - } - } - ] - }, - { - "name": "flexible_type_parameter_assignment", - "test": [ - { - "name": "list_parameter", - "expr": "[[], [[]], [[[]]], [[[[]]]]]", - "checkOnly": true, - "typedResult": { - "deducedType": { - "listType": { - "elemType": { - "listType": { - "elemType": { - "listType": { - "elemType": { - "listType": { - "elemType": { - "listType": { - "elemType": { - "dyn": {} - } - } - } - } - } - } - } - } - } - } - } - } - }, - { - "name": "list_parameter_order_independent", - "expr": "[[[[[]]]], [], [[[]]]]", - "checkOnly": true, - "typedResult": { - "deducedType": { - "listType": { - "elemType": { - "listType": { - "elemType": { - "listType": { - "elemType": { - "listType": { - "elemType": { - "listType": { - "elemType": { - "dyn": {} - } - } - } - } - } - } - } - } - } - } - } - } - }, - { - "name": "comprehension_type_var_aliasing", - "expr": "msg.repeated_nested_message.map(x, x).map(y, y.bb)", - "checkOnly": true, - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "typedResult": { - "deducedType": { - "listType": { - "elemType": { - "primitive": "INT64" - } - } - } - } - }, - { - "name": "overload_type_var_aliasing", - "expr": "([] + msg.repeated_nested_message + [])[0].bb", - "checkOnly": true, - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "typedResult": { - "deducedType": { - "primitive": "INT64" - } - } - }, - { - "name": "unconstrained_type_var_as_dyn", - "expr": "([].map(x,x))[0].foo", - "checkOnly": true, - "typedResult": { - "deducedType": { - "dyn": {} - } - } - }, - { - "name": "list_parameters_do_not_unify", - "expr": "[msg.single_int64_wrapper, msg.single_string_wrapper]", - "checkOnly": true, - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "typedResult": { - "deducedType": { - "listType": { - "elemType": { - "dyn": {} - } - } - } - } - }, - { - "name": "optional_none", - "expr": "[optional.none(), optional.of(1)]", - "checkOnly": true, - "typedResult": { - "deducedType": { - "listType": { - "elemType": { - "abstractType": { - "name": "optional_type", - "parameterTypes": [ - { - "primitive": "INT64" - } - ] - } - } - } - } - } - }, - { - "name": "optional_none_2", - "expr": "[optional.of(1), optional.none()]", - "checkOnly": true, - "typedResult": { - "deducedType": { - "listType": { - "elemType": { - "abstractType": { - "name": "optional_type", - "parameterTypes": [ - { - "primitive": "INT64" - } - ] - } - } - } - } - } - }, - { - "name": "optional_dyn_promotion", - "expr": "[optional.of(1), optional.of(dyn(1))]", - "checkOnly": true, - "typedResult": { - "deducedType": { - "listType": { - "elemType": { - "abstractType": { - "name": "optional_type", - "parameterTypes": [ - { - "dyn": {} - } - ] - } - } - } - } - } - }, - { - "name": "optional_dyn_promotion_2", - "expr": "[optional.of(dyn(1)), optional.of(1)]", - "checkOnly": true, - "typedResult": { - "deducedType": { - "listType": { - "elemType": { - "abstractType": { - "name": "optional_type", - "parameterTypes": [ - { - "dyn": {} - } - ] - } - } - } - } - } - }, - { - "name": "optional_in_ternary", - "expr": "true ? optional.of(dyn(1)) : optional.of(1)", - "checkOnly": true, - "typedResult": { - "deducedType": { - "abstractType": { - "name": "optional_type", - "parameterTypes": [ - { - "dyn": {} - } - ] - } - } - } - } - ] - }, - { - "name": "wrappers", - "test": [ - { - "name": "wrapper_promotion", - "expr": "[msg.single_int64_wrapper, msg.single_int64]", - "checkOnly": true, - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "typedResult": { - "deducedType": { - "listType": { - "elemType": { - "wrapper": "INT64" - } - } - } - } - }, - { - "name": "wrapper_promotion_2", - "expr": "[msg.single_int64, msg.single_int64_wrapper]", - "checkOnly": true, - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "typedResult": { - "deducedType": { - "listType": { - "elemType": { - "wrapper": "INT64" - } - } - } - } - }, - { - "name": "wrapper_dyn_promotion", - "expr": "[msg.single_int64_wrapper, msg.single_int64, dyn(1)]", - "checkOnly": true, - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "typedResult": { - "deducedType": { - "listType": { - "elemType": { - "dyn": {} - } - } - } - } - }, - { - "name": "wrapper_dyn_promotion_2", - "expr": "[dyn(1), msg.single_int64_wrapper, msg.single_int64]", - "checkOnly": true, - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "typedResult": { - "deducedType": { - "listType": { - "elemType": { - "dyn": {} - } - } - } - } - }, - { - "name": "wrapper_primitive_assignable", - "expr": "msg.single_int64_wrapper + 1", - "checkOnly": true, - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "typedResult": { - "deducedType": { - "primitive": "INT64" - } - } - }, - { - "name": "wrapper_null_assignable", - "expr": "msg.single_int64_wrapper == null", - "checkOnly": true, - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "typedResult": { - "deducedType": { - "primitive": "BOOL" - } - } - }, - { - "name": "wrapper_ternary_parameter_assignment", - "expr": "false ? msg.single_int64_wrapper : null", - "checkOnly": true, - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "typedResult": { - "deducedType": { - "wrapper": "INT64" - } - } - }, - { - "name": "wrapper_ternary_parameter_assignment_2", - "expr": "true ? msg.single_int64_wrapper : 42", - "checkOnly": true, - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "typedResult": { - "deducedType": { - "wrapper": "INT64" - } - } - } - ] - }, - { - "name": "type_parameters", - "test": [ - { - "name": "multiple_parameters_generality", - "expr": "[tuple(1, 2u, 3.0), tuple(dyn(1), dyn(2u), dyn(3.0))][0]", - "checkOnly": true, - "typeEnv": [ - { - "name": "tuple", - "function": { - "overloads": [ - { - "overloadId": "tuple_T_U_V", - "params": [ - { - "typeParam": "T" - }, - { - "typeParam": "U" - }, - { - "typeParam": "V" - } - ], - "resultType": { - "abstractType": { - "name": "tuple", - "parameterTypes": [ - { - "typeParam": "T" - }, - { - "typeParam": "U" - }, - { - "typeParam": "V" - } - ] - } - } - } - ] - } - } - ], - "typedResult": { - "deducedType": { - "abstractType": { - "name": "tuple", - "parameterTypes": [ - { - "dyn": {} - }, - { - "dyn": {} - }, - { - "dyn": {} - } - ] - } - } - } - }, - { - "name": "multiple_parameters_generality_2", - "expr": "sort(tuple(dyn(1), 2u, 3.0))", - "checkOnly": true, - "typeEnv": [ - { - "name": "tuple", - "function": { - "overloads": [ - { - "overloadId": "tuple_T_U_V", - "params": [ - { - "typeParam": "T" - }, - { - "typeParam": "U" - }, - { - "typeParam": "V" - } - ], - "resultType": { - "abstractType": { - "name": "tuple", - "parameterTypes": [ - { - "typeParam": "T" - }, - { - "typeParam": "U" - }, - { - "typeParam": "V" - } - ] - } - } - } - ] - } - }, - { - "name": "sort", - "function": { - "overloads": [ - { - "overloadId": "sort_tuple_T_T_T", - "params": [ - { - "abstractType": { - "name": "tuple", - "parameterTypes": [ - { - "typeParam": "T" - }, - { - "typeParam": "T" - }, - { - "typeParam": "T" - } - ] - } - } - ], - "resultType": { - "abstractType": { - "name": "tuple", - "parameterTypes": [ - { - "typeParam": "T" - }, - { - "typeParam": "T" - }, - { - "typeParam": "T" - } - ] - } - } - } - ] - } - } - ], - "typedResult": { - "deducedType": { - "abstractType": { - "name": "tuple", - "parameterTypes": [ - { - "dyn": {} - }, - { - "dyn": {} - }, - { - "dyn": {} - } - ] - } - } - } - }, - { - "name": "multiple_parameters_parameterized_ovl", - "expr": "tuple(1, 2u, 3.0) == tuple(1, dyn(2u), dyn(3.0))", - "checkOnly": true, - "typeEnv": [ - { - "name": "tuple", - "function": { - "overloads": [ - { - "overloadId": "tuple_T_U_V", - "params": [ - { - "typeParam": "T" - }, - { - "typeParam": "U" - }, - { - "typeParam": "V" - } - ], - "resultType": { - "abstractType": { - "name": "tuple", - "parameterTypes": [ - { - "typeParam": "T" - }, - { - "typeParam": "U" - }, - { - "typeParam": "V" - } - ] - } - } - } - ] - } - } - ], - "typedResult": { - "deducedType": { - "primitive": "BOOL" - } - } - }, - { - "name": "multiple_parameters_parameterized_ovl_2", - "expr": "tuple(dyn(1), dyn(2u), 3.0) == tuple(1, 2u, 3.0)", - "checkOnly": true, - "typeEnv": [ - { - "name": "tuple", - "function": { - "overloads": [ - { - "overloadId": "tuple_T_U_V", - "params": [ - { - "typeParam": "T" - }, - { - "typeParam": "U" - }, - { - "typeParam": "V" - } - ], - "resultType": { - "abstractType": { - "name": "tuple", - "parameterTypes": [ - { - "typeParam": "T" - }, - { - "typeParam": "U" - }, - { - "typeParam": "V" - } - ] - } - } - } - ] - } - } - ], - "typedResult": { - "deducedType": { - "primitive": "BOOL" - } - } - } - ] - }, - { - "name": "legacy_nullable_types", - "test": [ - { - "name": "null_assignable_to_message_parameter_candidate", - "expr": "[msg, null][0]", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes" - } - } - } - }, - "typedResult": { - "result": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes" - } - }, - "deducedType": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - }, - { - "name": "null_assignable_to_duration_parameter_candidate", - "expr": "[msg.single_duration, null][0]", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes" - } - } - } - }, - "typedResult": { - "result": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.Duration", - "value": "0s" - } - }, - "deducedType": { - "wellKnown": "DURATION" - } - } - }, - { - "name": "null_assignable_to_timestamp_parameter_candidate", - "expr": "[msg.single_timestamp, null][0]", - "typeEnv": [ - { - "name": "msg", - "ident": { - "type": { - "messageType": "cel.expr.conformance.proto3.TestAllTypes" - } - } - } - ], - "bindings": { - "msg": { - "value": { - "objectValue": { - "@type": "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes" - } - } - } - }, - "typedResult": { - "result": { - "objectValue": { - "@type": "type.googleapis.com/google.protobuf.Timestamp", - "value": "1970-01-01T00:00:00Z" - } - }, - "deducedType": { - "wellKnown": "TIMESTAMP" - } - } - }, - { - "name": "null_assignable_to_abstract_parameter_candidate", - "expr": "[optional.of(1), null][0]", - "checkOnly": true, - "typedResult": { - "deducedType": { - "abstractType": { - "name": "optional_type", - "parameterTypes": [ - { - "primitive": "INT64" - } - ] - } - } - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/json/unknowns.json b/packages/cel-spec/src/testdata/json/unknowns.json deleted file mode 100644 index e4b9d097..00000000 --- a/packages/cel-spec/src/testdata/json/unknowns.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "unknowns", - "description": "Tests for evaluation with unknown inputs." -} diff --git a/packages/cel-spec/src/testdata/json/wrappers.json b/packages/cel-spec/src/testdata/json/wrappers.json deleted file mode 100644 index c2865888..00000000 --- a/packages/cel-spec/src/testdata/json/wrappers.json +++ /dev/null @@ -1,374 +0,0 @@ -{ - "name": "wrappers", - "description": "Conformance tests related to wrapper types.", - "section": [ - { - "name": "bool", - "test": [ - { - "name": "to_any", - "expr": "TestAllTypes{single_any: google.protobuf.BoolValue{value: true}}.single_any", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "to_json", - "expr": "TestAllTypes{single_value: google.protobuf.BoolValue{value: true}}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - }, - { - "name": "to_null", - "expr": "TestAllTypes{single_bool_wrapper: null} == TestAllTypes{}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "int32", - "test": [ - { - "name": "to_any", - "expr": "TestAllTypes{single_any: google.protobuf.Int32Value{value: 1}}.single_any", - "container": "cel.expr.conformance.proto3", - "value": { - "int64Value": "1" - } - }, - { - "name": "to_json", - "expr": "TestAllTypes{single_value: google.protobuf.Int32Value{value: 1}}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "doubleValue": 1 - } - }, - { - "name": "to_null", - "expr": "TestAllTypes{single_int32_wrapper: null} == TestAllTypes{}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "int64", - "test": [ - { - "name": "to_any", - "expr": "TestAllTypes{single_any: google.protobuf.Int64Value{value: 1}}.single_any", - "container": "cel.expr.conformance.proto3", - "value": { - "int64Value": "1" - } - }, - { - "name": "to_json_number", - "expr": "TestAllTypes{single_value: google.protobuf.Int64Value{value: 1}}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "doubleValue": 1 - } - }, - { - "name": "to_json_string", - "expr": "TestAllTypes{single_value: google.protobuf.Int64Value{value: 9223372036854775807}}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "stringValue": "9223372036854775807" - } - }, - { - "name": "to_null", - "expr": "TestAllTypes{single_int64_wrapper: null} == TestAllTypes{}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "uint32", - "test": [ - { - "name": "to_any", - "expr": "TestAllTypes{single_any: google.protobuf.UInt32Value{value: 1u}}.single_any", - "container": "cel.expr.conformance.proto3", - "value": { - "uint64Value": "1" - } - }, - { - "name": "to_json", - "expr": "TestAllTypes{single_value: google.protobuf.UInt32Value{value: 1u}}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "doubleValue": 1 - } - }, - { - "name": "to_null", - "expr": "TestAllTypes{single_uint32_wrapper: null} == TestAllTypes{}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "uint64", - "test": [ - { - "name": "to_any", - "expr": "TestAllTypes{single_any: google.protobuf.UInt64Value{value: 1u}}.single_any", - "container": "cel.expr.conformance.proto3", - "value": { - "uint64Value": "1" - } - }, - { - "name": "to_json_number", - "expr": "TestAllTypes{single_value: google.protobuf.UInt64Value{value: 1u}}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "doubleValue": 1 - } - }, - { - "name": "to_json_string", - "expr": "TestAllTypes{single_value: google.protobuf.UInt64Value{value: 18446744073709551615u}}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "stringValue": "18446744073709551615" - } - }, - { - "name": "to_null", - "expr": "TestAllTypes{single_uint64_wrapper: null} == TestAllTypes{}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "float", - "test": [ - { - "name": "to_any", - "expr": "TestAllTypes{single_any: google.protobuf.FloatValue{value: 1.0}}.single_any", - "container": "cel.expr.conformance.proto3", - "value": { - "doubleValue": 1 - } - }, - { - "name": "to_json", - "expr": "TestAllTypes{single_value: google.protobuf.FloatValue{value: 1.0}}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "doubleValue": 1 - } - }, - { - "name": "to_null", - "expr": "TestAllTypes{single_float_wrapper: null} == TestAllTypes{}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "double", - "test": [ - { - "name": "to_any", - "expr": "TestAllTypes{single_any: google.protobuf.DoubleValue{value: 1.0}}.single_any", - "container": "cel.expr.conformance.proto3", - "value": { - "doubleValue": 1 - } - }, - { - "name": "to_json", - "expr": "TestAllTypes{single_value: google.protobuf.DoubleValue{value: 1.0}}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "doubleValue": 1 - } - }, - { - "name": "to_null", - "expr": "TestAllTypes{single_double_wrapper: null} == TestAllTypes{}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "bytes", - "test": [ - { - "name": "to_any", - "expr": "TestAllTypes{single_any: google.protobuf.BytesValue{value: b'foo'}}.single_any", - "container": "cel.expr.conformance.proto3", - "value": { - "bytesValue": "Zm9v" - } - }, - { - "name": "to_json", - "expr": "TestAllTypes{single_value: google.protobuf.BytesValue{value: b'foo'}}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "stringValue": "Zm9v" - } - }, - { - "name": "to_null", - "expr": "TestAllTypes{single_bytes_wrapper: null} == TestAllTypes{}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "string", - "test": [ - { - "name": "to_any", - "expr": "TestAllTypes{single_any: google.protobuf.StringValue{value: 'foo'}}.single_any", - "container": "cel.expr.conformance.proto3", - "value": { - "stringValue": "foo" - } - }, - { - "name": "to_json", - "expr": "TestAllTypes{single_value: google.protobuf.StringValue{value: 'foo'}}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "stringValue": "foo" - } - }, - { - "name": "to_null", - "expr": "TestAllTypes{single_string_wrapper: null} == TestAllTypes{}", - "container": "cel.expr.conformance.proto3", - "value": { - "boolValue": true - } - } - ] - }, - { - "name": "value", - "test": [ - { - "name": "default_to_json", - "expr": "TestAllTypes{single_any: TestAllTypes{}.single_value}.single_any", - "container": "cel.expr.conformance.proto3", - "value": { - "nullValue": null - } - } - ] - }, - { - "name": "list_value", - "test": [ - { - "name": "literal_to_any", - "expr": "TestAllTypes{single_any: []}.single_any", - "container": "cel.expr.conformance.proto3", - "value": { - "listValue": {} - } - } - ] - }, - { - "name": "struct", - "test": [ - { - "name": "literal_to_any", - "expr": "TestAllTypes{single_any: {}}.single_any", - "container": "cel.expr.conformance.proto3", - "value": { - "mapValue": {} - } - } - ] - }, - { - "name": "field_mask", - "test": [ - { - "name": "to_json", - "expr": "TestAllTypes{single_value: google.protobuf.FieldMask{paths: ['foo', 'bar']}}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "stringValue": "foo,bar" - } - } - ] - }, - { - "name": "duration", - "test": [ - { - "name": "to_json", - "expr": "TestAllTypes{single_value: duration('1000000s')}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "stringValue": "1000000s" - } - } - ] - }, - { - "name": "timestamp", - "test": [ - { - "name": "to_json", - "expr": "TestAllTypes{single_value: timestamp('9999-12-31T23:59:59.999999999Z')}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "stringValue": "9999-12-31T23:59:59.999999999Z" - } - } - ] - }, - { - "name": "empty", - "test": [ - { - "name": "to_json", - "expr": "TestAllTypes{single_value: google.protobuf.Empty{}}.single_value", - "container": "cel.expr.conformance.proto3", - "value": { - "mapValue": {} - } - } - ] - } - ] -} diff --git a/packages/cel-spec/src/testdata/textproto/basic.textproto b/packages/cel-spec/src/testdata/textproto/basic.textproto new file mode 100644 index 00000000..e52604ce --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/basic.textproto @@ -0,0 +1,293 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "basic" +description: "Basic conformance tests that all implementations should pass." +section { + name: "self_eval_zeroish" + description: "Simple self-evaluating forms to zero-ish values." + test { + name: "self_eval_int_zero" + expr: "0" + value: { int64_value: 0 } + } + test { + name: "self_eval_uint_zero" + expr: "0u" + value: { uint64_value: 0 } + } + test { + name: "self_eval_uint_alias_zero" + expr: "0U" + value: { uint64_value: 0 } + } + test { + name: "self_eval_float_zero" + expr: "0.0" + value: { double_value: 0 } + } + test { + name: "self_eval_float_zerowithexp" + expr: "0e+0" + value: { double_value: 0 } + } + test { + name: "self_eval_string_empty" + expr: "''" + value: { string_value: "" } + } + test { + name: "self_eval_string_empty_quotes" + expr: '""' + value: { string_value: "" } + } + test { + name: "self_eval_string_raw_prefix" + expr: 'r""' + value: { string_value: "" } + } + test { + name: "self_eval_bytes_empty" + expr: 'b""' + value: { bytes_value: "" } + } + test { + name: "self_eval_bool_false" + expr: "false" + value: { bool_value: false } + } + test { + name: "self_eval_null" + expr: "null" + value: { null_value: NULL_VALUE } + } + test { + name: "self_eval_empty_list" + expr: '[]' + value: { list_value: {} } + } + test { + name: "self_eval_empty_map" + expr: '{}' + value: { map_value: {} } + } + test { + name: "self_eval_string_raw_prefix_triple_double" + expr: 'r""""""' + value: { string_value: "" } + } + test { + name: "self_eval_string_raw_prefix_triple_single" + expr: "r''''''" + value: { string_value: "" } + } +} +section { + name: "self_eval_nonzeroish" + description: "Simple self-evaluating forms to non-zero-ish values." + test { + name: "self_eval_int_nonzero" + expr: "42" + value: { int64_value: 42 } + } + test { + name: "self_eval_uint_nonzero" + expr: "123456789u" + value: { uint64_value: 123456789 } + } + test { + name: "self_eval_uint_alias_nonzero" + expr: "123456789U" + value: { uint64_value: 123456789 } + } + test { + name: "self_eval_int_negative_min" + expr: "-9223372036854775808" + value: { int64_value: -9223372036854775808 } + } + test { + name: "self_eval_float_negative_exp" + expr: "-2.3e+1" + value: { double_value: -23.0 } + } + test { + name: "self_eval_string_excl" + expr: '"!"' + value: { string_value: "!" } + } + test { + name: "self_eval_string_escape" + expr: "'\\''" + value: { string_value: "'" } + } + test { + name: "self_eval_bytes_escape" + expr: "b'ÿ'" + value: { bytes_value: "\303\277" } + } + test { + name: "self_eval_bytes_invalid_utf8" + expr: "b'\\000\\xff'" + value: { bytes_value: "\000\377" } + } + test { + name: "self_eval_list_singleitem" + expr: "[-1]" + value: { + list_value { + values: { int64_value: -1 } + } + } + } + test { + name: "self_eval_map_singleitem" + expr: '{"k":"v"}' + value: { + map_value { + entries { + key: { string_value: "k" } + value: { string_value: "v" } + } + } + } + } + test { + name: "self_eval_bool_true" + expr: "true" + value: { bool_value: true } + } + test { + name: "self_eval_int_hex" + expr: "0x55555555" + value: { int64_value: 1431655765 } + } + test { + name: "self_eval_int_hex_negative" + expr: "-0x55555555" + value: { int64_value: -1431655765 } + } + test { + name: "self_eval_uint_hex" + expr: "0x55555555u" + value: { uint64_value: 1431655765 } + } + test { + name: "self_eval_uint_alias_hex" + expr: "0x55555555U" + value: { uint64_value: 1431655765 } + } + test { + name: "self_eval_unicode_escape_four" + expr: '"\\u270c"' + value: { string_value: "\xe2\x9c\x8c" } + } + test { + name: "self_eval_unicode_escape_eight" + expr: '"\\U0001f431"' + value: { string_value: "\xf0\x9f\x90\xb1" } + } + test { + name: "self_eval_ascii_escape_seq" + expr: '"\\a\\b\\f\\n\\r\\t\\v\\"\\\'\\\\"' + value: { string_value: "\a\b\f\n\r\t\v\"'\\" } + } +} +section { + name: "variables" + description: "Variable lookups." + test { + name: "self_eval_bound_lookup" + expr: "x" + type_env: { + name: "x", + ident: { type: { primitive: INT64 } } + } + bindings: { + key: "x" + value: { value: { int64_value: 123 } } + } + value: { int64_value: 123 } + } + test { + name: "self_eval_unbound_lookup" + description: "An unbound variable should be marked as an error during execution. See google/cel-go#154" + expr: "x" + disable_check: true + eval_error: { + errors: { message: "undeclared reference to 'x' (in container '')" } + } + } + test { + name: "unbound_is_runtime_error" + description: "Make sure we can short-circuit around an unbound variable." + expr: "x || true" + disable_check: true + value { bool_value: true } + } +} +section { + name: "functions" + description: "Basic mechanisms for function calls." + test { + name: "binop" + expr: "1 + 1" + value { int64_value: 2 } + } + test { + name: "unbound" + expr: "f_unknown(17)" + disable_check: true + eval_error { + errors { message: "unbound function" } + } + } + test { + name: "unbound_is_runtime_error" + expr: "f_unknown(17) || true" + disable_check: true + value { bool_value: true } + } +} +section { + name: "reserved_const" + description: "Named constants should never be shadowed by identifiers." + test { + name: "false" + expr: "false" + type_env: { + name: "false" + ident: { type: { primitive: BOOL } } + } + bindings { + key: "false" + value: { value: { bool_value: true } } + } + value: { bool_value: false } + } + test { + name: "true" + expr: "true" + type_env: { + name: "true" + ident: { type: { primitive: BOOL } } + } + bindings { + key: "true" + value: { value: { bool_value: false } } + } + value: { bool_value: true } + } + test { + name: "null" + expr: "null" + type_env: { + name: "null" + ident: { type: { primitive: BOOL } } + } + bindings { + key: "null" + value: { value: { bool_value: true } } + } + value: { null_value: 0 } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/bindings_ext.textproto b/packages/cel-spec/src/testdata/textproto/bindings_ext.textproto new file mode 100644 index 00000000..3a3d93f5 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/bindings_ext.textproto @@ -0,0 +1,43 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "bindings_ext" +description: "Tests for the bindings extension library." +section: { + name: "bind" + test: { + name: "boolean_literal" + expr: "cel.bind(t, true, t)" + value: { + bool_value: true + } + } + test: { + name: "string_concat" + expr: "cel.bind(msg, \"hello\", msg + msg + msg)" + value: { + string_value: "hellohellohello" + } + } + test: { + name: "bind_nested" + expr: "cel.bind(t1, true, cel.bind(t2, true, t1 && t2))" + value: { + bool_value: true + } + } + test: { + name: "macro_exists" + expr: "cel.bind(valid_elems, [1, 2, 3], [3, 4, 5].exists(e, e in valid_elems))" + value: { + bool_value: true + } + } + test: { + name: "macro_not_exists" + expr: "cel.bind(valid_elems, [1, 2, 3], ![4, 5].exists(e, e in valid_elems))" + value: { + bool_value: true + } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/block_ext.textproto b/packages/cel-spec/src/testdata/textproto/block_ext.textproto new file mode 100644 index 00000000..ebdf76f4 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/block_ext.textproto @@ -0,0 +1,1070 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +# This conformance test relies on the test-only macros cel.block, cel.index, +# cel.iterVar, and cel.accuVar. These test-only macros allow exercising +# cel.block without the optimizers being present. +# `cel.block(l, e)` must rewrite itself to be `cel.block(l, e)` +# `cel.index(N)` must rewrite itself to `@indexN` +# `cel.iterVar(N, M)` must rewrite itself to `@it:N:M` +# `cel.accuVar(N, M)` must rewrite itself to `@ac:N:M` + +name: "block_ext" +description: "Tests for cel.block." +section: { + name: "basic" + test: { + name: "int_add" + expr: "cel.block([1, cel.index(0) + 1, cel.index(1) + 1, cel.index(2) + 1], cel.index(3))" + value: { + int64_value: 4 + } + } + test: { + name: "size_1" + expr: "cel.block([[1, 2], size(cel.index(0)), cel.index(1) + cel.index(1), cel.index(2) + 1], cel.index(3))" + value: { + int64_value: 5 + } + } + test: { + name: "size_2" + expr: "cel.block([[1, 2], size(cel.index(0)), 2 + cel.index(1), cel.index(2) + cel.index(1), cel.index(3) + 1], cel.index(4))" + value: { + int64_value: 7 + } + } + test: { + name: "size_3" + expr: "cel.block([[0], size(cel.index(0)), [1, 2], size(cel.index(2)), cel.index(1) + cel.index(1), cel.index(4) + cel.index(3), cel.index(5) + cel.index(3)], cel.index(6))" + value: { + int64_value: 6 + } + } + test: { + name: "size_4" + expr: "cel.block([[0], size(cel.index(0)), [1, 2], size(cel.index(2)), [1, 2, 3], size(cel.index(4)), 5 + cel.index(1), cel.index(6) + cel.index(1), cel.index(7) + cel.index(3), cel.index(8) + cel.index(3), cel.index(9) + cel.index(5), cel.index(10) + cel.index(5)], cel.index(11))" + value: { + int64_value: 17 + } + } + test: { + name: "timestamp" + expr: "cel.block([timestamp(1000000000), int(cel.index(0)), timestamp(cel.index(1)), cel.index(2).getFullYear(), timestamp(50), int(cel.index(4)), timestamp(cel.index(5)), timestamp(200), int(cel.index(7)), timestamp(cel.index(8)), cel.index(9).getFullYear(), timestamp(75), int(cel.index(11)), timestamp(cel.index(12)), cel.index(13).getFullYear(), cel.index(3) + cel.index(14), cel.index(6).getFullYear(), cel.index(15) + cel.index(16), cel.index(17) + cel.index(3), cel.index(6).getSeconds(), cel.index(18) + cel.index(19), cel.index(20) + cel.index(10), cel.index(21) + cel.index(10), cel.index(13).getMinutes(), cel.index(22) + cel.index(23), cel.index(24) + cel.index(3)], cel.index(25))" + value: { + int64_value: 13934 + } + } + test: { + name: "map_index" + expr: "cel.block([{\"a\": 2}, cel.index(0)[\"a\"], cel.index(1) * cel.index(1), cel.index(1) + cel.index(2)], cel.index(3))" + value: { + int64_value: 6 + } + } + test: { + name: "nested_map_construction" + expr: "cel.block([{\"b\": 1}, {\"e\": cel.index(0)}], {\"a\": cel.index(0), \"c\": cel.index(0), \"d\": cel.index(1), \"e\": cel.index(1)})" + value: { + map_value: { + entries { + key: { + string_value: 'a' + } + value: { + map_value: { + entries { + key: { + string_value: 'b' + } + value: { + int64_value: 1 + } + } + } + } + } + entries { + key: { + string_value: 'c' + } + value: { + map_value: { + entries { + key: { + string_value: 'b' + } + value: { + int64_value: 1 + } + } + } + } + } + entries { + key: { + string_value: 'd' + } + value: { + map_value: { + entries { + key: { + string_value: 'e' + } + value: { + map_value: { + entries { + key: { + string_value: 'b' + } + value: { + int64_value: 1 + } + } + } + } + } + } + } + } + entries { + key: { + string_value: 'e' + } + value: { + map_value: { + entries { + key: { + string_value: 'e' + } + value: { + map_value: { + entries { + key: { + string_value: 'b' + } + value: { + int64_value: 1 + } + } + } + } + } + } + } + } + } + } + } + test: { + name: "nested_list_construction" + expr: "cel.block([[1, 2, 3, 4], [1, 2], [cel.index(1), cel.index(0)]], [1, cel.index(0), 2, cel.index(0), 5, cel.index(0), 7, cel.index(2), cel.index(1)])" + value: { + list_value: { + values { + int64_value: 1 + } + values { + list_value: { + values { + int64_value: 1 + } + values { + int64_value: 2 + } + values { + int64_value: 3 + } + values { + int64_value: 4 + } + } + } + values { + int64_value: 2 + } + values { + list_value: { + values { + int64_value: 1 + } + values { + int64_value: 2 + } + values { + int64_value: 3 + } + values { + int64_value: 4 + } + } + } + values { + int64_value: 5 + } + values { + list_value: { + values { + int64_value: 1 + } + values { + int64_value: 2 + } + values { + int64_value: 3 + } + values { + int64_value: 4 + } + } + } + values { + int64_value: 7 + } + values { + list_value: { + values { + list_value: { + values { + int64_value: 1 + } + values { + int64_value: 2 + } + } + } + values { + list_value: { + values { + int64_value: 1 + } + values { + int64_value: 2 + } + values { + int64_value: 3 + } + values { + int64_value: 4 + } + } + } + } + } + values { + list_value: { + values { + int64_value: 1 + } + values { + int64_value: 2 + } + } + } + } + } + } + test: { + name: "select" + expr: "cel.block([msg.single_int64, cel.index(0) + cel.index(0)], cel.index(1))" + value: { + int64_value: 6 + } + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_int64: 3 + single_int32: 5 + oneof_type: { + payload: { + single_int32: 8 + single_int64: 10 + map_int32_int64 { + key: 0 + value: 1 + } + map_int32_int64 { + key: 1 + value: 5 + } + map_int32_int64 { + key: 2 + value: 2 + } + map_string_string { + key: "key" + value: "A" + } + } + } + } + } + } + } + } + } + test: { + name: "select_nested_1" + expr: "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).single_int64, cel.index(1).single_int32, cel.index(2) + cel.index(3), cel.index(4) + cel.index(2), msg.single_int64, cel.index(5) + cel.index(6), cel.index(1).oneof_type, cel.index(8).payload, cel.index(9).single_int64, cel.index(7) + cel.index(10)], cel.index(11))" + value: { + int64_value: 31 + } + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_int64: 3 + single_int32: 5 + oneof_type: { + payload: { + single_int32: 8 + single_int64: 10 + map_int32_int64 { + key: 0 + value: 1 + } + map_int32_int64 { + key: 1 + value: 5 + } + map_int32_int64 { + key: 2 + value: 2 + } + map_string_string { + key: "key" + value: "A" + } + } + } + } + } + } + } + } + } + test: { + name: "select_nested_2" + expr: "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).oneof_type, cel.index(2).payload, cel.index(3).oneof_type, cel.index(4).payload, cel.index(5).oneof_type, cel.index(6).payload, cel.index(7).single_bool, true || cel.index(8), cel.index(4).child, cel.index(10).child, cel.index(11).payload, cel.index(12).single_bool], cel.index(9) || cel.index(13))" + value: { + bool_value: true + } + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_int64: 3 + single_int32: 5 + oneof_type: { + payload: { + single_int32: 8 + single_int64: 10 + map_int32_int64 { + key: 0 + value: 1 + } + map_int32_int64 { + key: 1 + value: 5 + } + map_int32_int64 { + key: 2 + value: 2 + } + map_string_string { + key: "key" + value: "A" + } + } + } + } + } + } + } + } + } + test: { + name: "select_nested_message_map_index_1" + expr: "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).map_int32_int64, cel.index(2)[1], cel.index(3) + cel.index(3), cel.index(4) + cel.index(3)], cel.index(5))" + value: { + int64_value: 15 + } + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_int64: 3 + single_int32: 5 + oneof_type: { + payload: { + single_int32: 8 + single_int64: 10 + map_int32_int64 { + key: 0 + value: 1 + } + map_int32_int64 { + key: 1 + value: 5 + } + map_int32_int64 { + key: 2 + value: 2 + } + map_string_string { + key: "key" + value: "A" + } + } + } + } + } + } + } + } + } + test: { + name: "select_nested_message_map_index_2" + expr: "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).map_int32_int64, cel.index(2)[0], cel.index(2)[1], cel.index(3) + cel.index(4), cel.index(2)[2], cel.index(5) + cel.index(6)], cel.index(7))" + value: { + int64_value: 8 + } + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_int64: 3 + single_int32: 5 + oneof_type: { + payload: { + single_int32: 8 + single_int64: 10 + map_int32_int64 { + key: 0 + value: 1 + } + map_int32_int64 { + key: 1 + value: 5 + } + map_int32_int64 { + key: 2 + value: 2 + } + map_string_string { + key: "key" + value: "A" + } + } + } + } + } + } + } + } + } + test: { + name: "ternary" + expr: "cel.block([msg.single_int64, cel.index(0) > 0, cel.index(1) ? cel.index(0) : 0], cel.index(2))" + value: { + int64_value: 3 + } + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_int64: 3 + single_int32: 5 + oneof_type: { + payload: { + single_int32: 8 + single_int64: 10 + map_int32_int64 { + key: 0 + value: 1 + } + map_int32_int64 { + key: 1 + value: 5 + } + map_int32_int64 { + key: 2 + value: 2 + } + map_string_string { + key: "key" + value: "A" + } + } + } + } + } + } + } + } + } + test: { + name: "nested_ternary" + expr: "cel.block([msg.single_int64, msg.single_int32, cel.index(0) > 0, cel.index(1) > 0, cel.index(0) + cel.index(1), cel.index(3) ? cel.index(4) : 0, cel.index(2) ? cel.index(5) : 0], cel.index(6))" + value: { + int64_value: 8 + } + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_int64: 3 + single_int32: 5 + oneof_type: { + payload: { + single_int32: 8 + single_int64: 10 + map_int32_int64 { + key: 0 + value: 1 + } + map_int32_int64 { + key: 1 + value: 5 + } + map_int32_int64 { + key: 2 + value: 2 + } + map_string_string { + key: "key" + value: "A" + } + } + } + } + } + } + } + } + } + test: { + name: "multiple_macros_1" + expr: "cel.block([[1].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 0), size([cel.index(0)]), [2].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 1), size([cel.index(2)])], cel.index(1) + cel.index(1) + cel.index(3) + cel.index(3))" + value: { + int64_value: 4 + } + } + test: { + name: "multiple_macros_2" + expr: "cel.block([[1].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 0), [cel.index(0)], ['a'].exists(cel.iterVar(0, 1), cel.iterVar(0, 1) == 'a'), [cel.index(2)]], cel.index(1) + cel.index(1) + cel.index(3) + cel.index(3))" + value: { + list_value: { + values { + bool_value: true + } + values { + bool_value: true + } + values { + bool_value: true + } + values { + bool_value: true + } + } + } + } + test: { + name: "multiple_macros_3" + expr: "cel.block([[1].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 0)], cel.index(0) && cel.index(0) && [1].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 1) && [2].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 1))" + value: { + bool_value: false + } + } + test: { + name: "nested_macros_1" + expr: "cel.block([[1, 2, 3]], cel.index(0).map(cel.iterVar(0, 0), cel.index(0).map(cel.iterVar(1, 0), cel.iterVar(1, 0) + 1)))" + value: { + list_value: { + values { + list_value: { + values { + int64_value: 2 + } + values { + int64_value: 3 + } + values { + int64_value: 4 + } + } + } + values { + list_value: { + values { + int64_value: 2 + } + values { + int64_value: 3 + } + values { + int64_value: 4 + } + } + } + values { + list_value: { + values { + int64_value: 2 + } + values { + int64_value: 3 + } + values { + int64_value: 4 + } + } + } + } + } + } + test: { + name: "nested_macros_2" + expr: "[1, 2].map(cel.iterVar(0, 0), [1, 2, 3].filter(cel.iterVar(1, 0), cel.iterVar(1, 0) == cel.iterVar(0, 0)))" + value: { + list_value: { + values { + list_value: { + values { + int64_value: 1 + } + } + } + values { + list_value: { + values { + int64_value: 2 + } + } + } + } + } + } + test: { + name: "adjacent_macros" + expr: "cel.block([[1, 2, 3], cel.index(0).map(cel.iterVar(0, 0), cel.index(0).map(cel.iterVar(1, 0), cel.iterVar(1, 0) + 1))], cel.index(1) == cel.index(1))" + value: { + bool_value: true + } + } + test: { + name: "macro_shadowed_variable_1" + expr: "cel.block([x - 1, cel.index(0) > 3], [cel.index(1) ? cel.index(0) : 5].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) - 1 > 3) || cel.index(1))" + value: { + bool_value: true + } + type_env: { + name: "x" + ident: { type: { primitive: INT64 }} + } + bindings: { + key: "x" + value: { + value: { + int64_value: 5 + } + } + } + } + test: { + name: "macro_shadowed_variable_2" + expr: "['foo', 'bar'].map(cel.iterVar(1, 0), [cel.iterVar(1, 0) + cel.iterVar(1, 0), cel.iterVar(1, 0) + cel.iterVar(1, 0)]).map(cel.iterVar(0, 0), [cel.iterVar(0, 0) + cel.iterVar(0, 0), cel.iterVar(0, 0) + cel.iterVar(0, 0)])" + value: { + list_value: { + values { + list_value: { + values { + list_value: { + values { + string_value: "foofoo" + } + values { + string_value: "foofoo" + } + values { + string_value: "foofoo" + } + values { + string_value: "foofoo" + } + } + } + values { + list_value: { + values { + string_value: "foofoo" + } + values { + string_value: "foofoo" + } + values { + string_value: "foofoo" + } + values { + string_value: "foofoo" + } + } + } + } + } + values { + list_value: { + values { + list_value: { + values { + string_value: "barbar" + } + values { + string_value: "barbar" + } + values { + string_value: "barbar" + } + values { + string_value: "barbar" + } + } + } + values { + list_value: { + values { + string_value: "barbar" + } + values { + string_value: "barbar" + } + values { + string_value: "barbar" + } + values { + string_value: "barbar" + } + } + } + } + } + } + } + type_env: { + name: "x" + ident: { type: { primitive: INT64 }} + } + bindings: { + key: "x" + value: { + value: { + int64_value: 5 + } + } + } + } + test: { + name: "inclusion_list" + expr: "cel.block([[1, 2, 3], 1 in cel.index(0), 2 in cel.index(0), cel.index(1) && cel.index(2), [3, cel.index(0)], 3 in cel.index(4), cel.index(5) && cel.index(1)], cel.index(3) && cel.index(6))" + value: { + bool_value: true + } + } + test: { + name: "inclusion_map" + expr: "cel.block([{true: false}, {\"a\": 1, 2: cel.index(0), 3: cel.index(0)}], 2 in cel.index(1))" + value: { + bool_value: true + } + } + test: { + name: "presence_test" + expr: "cel.block([{\"a\": true}, has(cel.index(0).a), cel.index(0)[\"a\"]], cel.index(1) && cel.index(2))" + value: { + bool_value: true + } + } + test: { + name: "presence_test_2" + expr: "cel.block([{\"a\": true}, has(cel.index(0).a)], cel.index(1) && cel.index(1))" + value: { + bool_value: true + } + } + test: { + name: "presence_test_with_ternary" + expr: "cel.block([msg.oneof_type, has(cel.index(0).payload), cel.index(0).payload, cel.index(2).single_int64, cel.index(1) ? cel.index(3) : 0], cel.index(4))" + value: { + int64_value: 10 + } + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_int64: 3 + single_int32: 5 + oneof_type: { + payload: { + single_int32: 8 + single_int64: 10 + map_int32_int64 { + key: 0 + value: 1 + } + map_int32_int64 { + key: 1 + value: 5 + } + map_int32_int64 { + key: 2 + value: 2 + } + map_string_string { + key: "key" + value: "A" + } + } + } + } + } + } + } + } + } + test: { + name: "presence_test_with_ternary_2" + expr: "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).single_int64, has(cel.index(0).payload), cel.index(2) * 0, cel.index(3) ? cel.index(2) : cel.index(4)], cel.index(5))" + value: { + int64_value: 10 + } + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_int64: 3 + single_int32: 5 + oneof_type: { + payload: { + single_int32: 8 + single_int64: 10 + map_int32_int64 { + key: 0 + value: 1 + } + map_int32_int64 { + key: 1 + value: 5 + } + map_int32_int64 { + key: 2 + value: 2 + } + map_string_string { + key: "key" + value: "A" + } + } + } + } + } + } + } + } + } + test: { + name: "presence_test_with_ternary_3" + expr: "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).single_int64, has(cel.index(1).single_int64), cel.index(2) * 0, cel.index(3) ? cel.index(2) : cel.index(4)], cel.index(5))" + value: { + int64_value: 10 + } + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_int64: 3 + single_int32: 5 + oneof_type: { + payload: { + single_int32: 8 + single_int64: 10 + map_int32_int64 { + key: 0 + value: 1 + } + map_int32_int64 { + key: 1 + value: 5 + } + map_int32_int64 { + key: 2 + value: 2 + } + map_string_string { + key: "key" + value: "A" + } + } + } + } + } + } + } + } + } + test: { + name: "presence_test_with_ternary_nested" + expr: "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).map_string_string, has(msg.oneof_type), has(cel.index(0).payload), cel.index(3) && cel.index(4), has(cel.index(1).single_int64), cel.index(5) && cel.index(6), has(cel.index(1).map_string_string), has(cel.index(2).key), cel.index(8) && cel.index(9), cel.index(2).key, cel.index(11) == \"A\", cel.index(10) ? cel.index(12) : false], cel.index(7) ? cel.index(13) : false)" + value: { + bool_value: true + } + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_int64: 3 + single_int32: 5 + oneof_type: { + payload: { + single_int32: 8 + single_int64: 10 + map_int32_int64 { + key: 0 + value: 1 + } + map_int32_int64 { + key: 1 + value: 5 + } + map_int32_int64 { + key: 2 + value: 2 + } + map_string_string { + key: "key" + value: "A" + } + } + } + } + } + } + } + } + } + test: { + name: "optional_list" + expr: "cel.block([optional.none(), [?cel.index(0), ?optional.of(opt_x)], [5], [10, ?cel.index(0), cel.index(1), cel.index(1)], [10, cel.index(2), cel.index(2)]], cel.index(3) == cel.index(4))" + value: { + bool_value: true + } + type_env: { + name: "opt_x" + ident: { type: { primitive: INT64 }} + } + bindings: { + key: "opt_x", + value: { + value: { + int64_value: 5 + } + } + } + } + test: { + name: "optional_map" + expr: "cel.block([optional.of(\"hello\"), {?\"hello\": cel.index(0)}, cel.index(1)[\"hello\"], cel.index(2) + cel.index(2)], cel.index(3) == \"hellohello\")" + value: { + bool_value: true + } + } + test: { + name: "optional_map_chained" + expr: "cel.block([{\"key\": \"test\"}, optional.of(\"test\"), {?\"key\": cel.index(1)}, cel.index(2)[?\"bogus\"], cel.index(0)[?\"bogus\"], cel.index(3).or(cel.index(4)), cel.index(0)[\"key\"], cel.index(5).orValue(cel.index(6))], cel.index(7))" + value: { + string_value: 'test' + } + } + test: { + name: "optional_message" + container: "cel.expr.conformance.proto3" + expr: "cel.block([optional.ofNonZeroValue(1), optional.of(4), TestAllTypes{?single_int64: cel.index(0), ?single_int32: cel.index(1)}, cel.index(2).single_int32, cel.index(2).single_int64, cel.index(3) + cel.index(4)], cel.index(5))" + value: { + int64_value: 5 + } + } + test: { + name: "call" + expr: "cel.block([\"h\" + \"e\", cel.index(0) + \"l\", cel.index(1) + \"l\", cel.index(2) + \"o\", cel.index(3) + \" world\"], cel.index(4).matches(cel.index(3)))" + value: { + bool_value: true + } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/comparisons.textproto b/packages/cel-spec/src/testdata/textproto/comparisons.textproto new file mode 100644 index 00000000..e7121962 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/comparisons.textproto @@ -0,0 +1,2370 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "comparisons" +description: "Tests for boolean-valued functions and operators." +section { + name: "eq_literal" + description: "Literals comparison on _==_" + test { + name: "eq_int" + expr: "1 == 1" + value: { bool_value: true } + } + test { + name: "not_eq_int" + expr: "-1 == 1" + value: { bool_value: false } + } + test { + name: "eq_int_uint" + expr: "dyn(1) == 1u" + value: { bool_value: true } + } + test { + name: "not_eq_int_uint" + expr: "dyn(2) == 1u" + value: { bool_value: false } + } + test { + name: "eq_int_double" + expr: "dyn(1) == 1.0" + value: { bool_value: true } + } + test { + name: "not_eq_int_double" + expr: "dyn(2) == 1.0" + value: { bool_value: false } + } + test { + name: "eq_uint" + expr: "2u == 2u" + value: { bool_value: true } + } + test { + name: "not_eq_uint" + expr: "1u == 2u" + value: { bool_value: false } + } + test { + name: "eq_uint_int" + expr: "dyn(1u) == 1" + value: { bool_value: true } + } + test { + name: "not_eq_uint_int" + expr: "dyn(2u) == 1" + value: { bool_value: false } + } + test { + name: "eq_uint_double" + expr: "dyn(1u) == 1.0" + value: { bool_value: true } + } + test { + name: "not_eq_uint_double" + expr: "dyn(2u) == 1.0" + value: { bool_value: false } + } + test { + name: "eq_double" + expr: "1.0 == 1.0e+0" + value: { bool_value: true } + } + test { + name: "not_eq_double" + expr: "-1.0 == 1.0" + value: { bool_value: false } + } + test { + name: "not_eq_double_nan" + expr: "0.0/0.0 == 0.0/0.0" + value: { bool_value: false } + } + test { + name: "not_eq_int_double_nan" + expr: "dyn(1) == 0.0/0.0" + value: { bool_value: false } + } + test { + name: "not_eq_uint_double_nan" + expr: "dyn(1u) == 0.0/0.0" + value: { bool_value: false } + } + test { + name: "eq_double_int" + expr: "dyn(1.0) == 1" + value: { bool_value: true } + } + test { + name: "not_eq_double_int" + expr: "dyn(2.0) == 1" + value: { bool_value: false } + } + test { + name: "eq_double_uint" + expr: "dyn(1.0) == 1u" + value: { bool_value: true } + } + test { + name: "not_eq_double_uint" + expr: "dyn(2.0) == 1u" + value: { bool_value: false } + } + test { + name: "eq_string" + expr: "'' == \"\"" + value: { bool_value: true } + } + test { + name: "not_eq_string" + expr: "'a' == 'b'" + value: { bool_value: false } + } + test { + name: "eq_raw_string" + expr: "'abc' == r'abc'" + value: { bool_value: true } + } + test { + name: "not_eq_string_case" + expr: "'abc' == 'ABC'" + value: { bool_value: false } + } + test { + name: "eq_string_unicode" + expr: "'ίσος' == 'ίσος'" + value: { bool_value: true } + } + test { + name: "not_eq_string_unicode_ascii" + expr: "'a' == 'à'" + value: { bool_value: false } + } + test { + name: "no_string_normalization" + description: "Should not normalize Unicode." + expr: "'Am\\u00E9lie' == 'Ame\\u0301lie'" + value: { bool_value: false } + } + test { + name: "eq_null" + expr: "null == null" + value: { bool_value: true } + } + test { + name: "eq_bool" + expr: "true == true" + value: { bool_value: true } + } + test { + name: "not_eq_bool" + expr: "false == true" + value: { bool_value: false } + } + test { + name: "eq_bytes" + description: "Test bytes literal equality with encoding" + expr: "b'ÿ' == b'\\303\\277'" + value: { bool_value: true } + } + test { + name: "not_eq_bytes" + expr: "b'abc' == b'abcd'" + value: { bool_value: false } + } + test { + name: "eq_list_empty" + expr: "[] == []" + value: { bool_value: true } + } + test { + name: "eq_list_null" + expr: "[null] == [null]" + value: { bool_value: true } + } + test { + name: "not_eq_list_null" + expr: "['1', '2', null] == ['1', '2', '3']" + value: { bool_value: false } + } + test { + name: "eq_list_numbers" + expr: "[1, 2, 3] == [1, 2, 3]" + value: { bool_value: true } + } + test { + name: "eq_list_mixed_type_numbers" + expr: "[1.0, 2.0, 3] == [1u, 2, 3u]" + value: { bool_value: true } + } + test { + name: "not_eq_list_mixed_type_numbers" + expr: "[1.0, 2.1] == [1u, 2]" + value: { bool_value: false } + } + test { + name: "not_eq_list_order" + expr: "[1, 2, 3] == [1, 3, 2]" + value: { bool_value: false } + } + test { + name: "not_eq_list_string_case" + expr: "['case'] == ['cAse']" + value: { bool_value: false } + } + test { + name: "not_eq_list_length" + expr: "['one'] == [2, 3]" + disable_check: true + value: { bool_value: false } + } + test { + name: "not_eq_list_false_vs_types" + expr: "[1, 'dos', 3] == [1, 2, 4]" + value: { bool_value: false } + } + test { + name: "eq_map_empty" + expr: "{} == {}" + value: { bool_value: true } + } + test { + name: "eq_map_null" + expr: "{'k': null} == {'k': null}" + value: { bool_value: true } + } + test { + name: "not_eq_map_null" + expr: "{'k': 1, 'j': 2} == {'k': 1, 'j': null}" + value: { bool_value: false } + } + test { + name: "eq_map_onekey" + expr: "{'k':'v'} == {\"k\":\"v\"}" + value: { bool_value: true } + } + test { + name: "eq_map_double_value" + expr: "{'k':1.0} == {'k':1e+0}" + value: { bool_value: true } + } + test { + name: "eq_map_mixed_type_numbers" + expr: "{1: 1.0, 2u: 3u} == {1u: 1, 2: 3.0}" + value: { bool_value: true } + } + test { + name: "not_eq_map_value" + expr: "{'k':'v'} == {'k':'v1'}" + value: { bool_value: false } + } + test { + name: "not_eq_map_extra_key" + expr: "{'k':'v','k1':'v1'} == {'k':'v'}" + value: { bool_value: false } + } + test { + name: "eq_map_key_order" + expr: "{'k1':'v1','k2':'v2'} == {'k2':'v2','k1':'v1'}" + value: { bool_value: true } + } + test { + name: "not_eq_map_key_casing" + expr: "{'key':'value'} == {'Key':'value'}" + value: { bool_value: false } + } + test { + name: "not_eq_map_false_vs_types" + expr: "{'k1': 1, 'k2': 'dos', 'k3': 3} == {'k1': 1, 'k2': 2, 'k3': 4}" + value: { bool_value: false } + } + test { + name: "eq_mixed_types" + expr: "1.0 == 1" + disable_check: true # need to make it fail in the evaluation phase + value: { bool_value: true } + } + test { + name: "eq_list_elem_mixed_types" + expr: "[1] == [1.0]" + disable_check: true # need to make it fail in the evaluation phase + value: { bool_value: true } + } + test { + name: "eq_map_value_mixed_types" + expr: "{'k':'v', 1:1} == {'k':'v', 1:'v1'}" + value: { bool_value: false } + } + test { + name: "eq_dyn_json_null" + expr: "dyn(google.protobuf.Value{}) == null" + value: { bool_value: true } + } + test { + name: "not_eq_dyn_bool_null" + expr: "dyn(false) == null" + value: { bool_value: false } + } + test { + name: "not_eq_dyn_bytes_null" + expr: "dyn(b'') == null" + value: { bool_value: false } + } + test { + name: "not_eq_dyn_double_null" + expr: "dyn(2.1) == null" + value: { bool_value: false } + } + test { + name: "not_eq_dyn_duration_null" + expr: "dyn(duration('0s')) == null" + value: { bool_value: false } + } + test { + name: "not_eq_dyn_int_null" + expr: "dyn(1) == null" + value: { bool_value: false } + } + test { + name: "not_eq_dyn_list_null" + expr: "dyn([]) == null" + value: { bool_value: false } + } + test { + name: "not_eq_dyn_map_null" + expr: "dyn({}) == null" + value: { bool_value: false } + } + test { + name: "not_eq_dyn_proto2_msg_null" + container: "cel.expr.conformance.proto2" + expr: "dyn(TestAllTypes{}) == null" + value: { bool_value: false } + } + test { + name: "not_eq_dyn_proto3_msg_null" + container: "cel.expr.conformance.proto3" + expr: "dyn(TestAllTypes{}) == null" + value: { bool_value: false } + } + test { + name: "not_eq_dyn_string_null" + expr: "dyn('') == null" + value: { bool_value: false } + } + test { + name: "not_eq_dyn_timestamp_null" + expr: "dyn(timestamp(0)) == null" + value: { bool_value: false } + } + test { + name: "not_eq_list_elem_null" + expr: "[1, 2, null] == [1, null, 3]" + value: { bool_value: false } + } + test { + name: "not_eq_map_value_null" + expr: "{1:'hello', 2:'world'} == {1:'goodbye', 2:null}" + value: { bool_value: false } + } + test { + name: "eq_dyn_int_uint" + expr: "dyn(1) == 1u" + value: { bool_value: true } + } + test { + name: "eq_dyn_int_double" + expr: "dyn(1) == 1.0" + value: { bool_value: true } + } + test { + name: "eq_dyn_uint_int" + expr: "dyn(1u) == 1" + value: { bool_value: true } + } + test { + name: "eq_dyn_uint_double" + expr: "dyn(1u) == 1.0" + value: { bool_value: true } + } + test { + name: "eq_dyn_double_int" + expr: "dyn(1.0) == 1" + value: { bool_value: true } + } + test { + name: "eq_dyn_double_uint" + expr: "dyn(1.0) == 1u" + value: { bool_value: true } + } + test { + name: "not_eq_dyn_int_uint" + expr: "dyn(1) == 2u" + value: { bool_value: false } + } + test { + name: "not_eq_dyn_int_double" + expr: "dyn(1) == 2.0" + value: { bool_value: false } + } + test { + name: "not_eq_dyn_uint_int" + expr: "dyn(1u) == 2" + value: { bool_value: false } + } + test { + name: "not_eq_dyn_uint_double" + expr: "dyn(1u) == 120" + value: { bool_value: false } + } + test { + name: "not_eq_dyn_double_int" + expr: "dyn(1.0) == 2" + value: { bool_value: false } + } + test { + name: "not_eq_dyn_double_uint" + expr: "dyn(1.0) == 2u" + value: { bool_value: false } + } +} +section { + name: "eq_wrapper" + description: "Wrapper type comparison on _==_. Wrapper types treated as boxed primitives when they appear on message fields. An unset wrapper field should be treated as null. The tests show the distinction between unset, empty, and set equality behavior." + test { + name: "eq_bool" + expr: "google.protobuf.BoolValue{value: true} == true" + value: { bool_value: true } + } + test { + name: "eq_bool_empty" + expr: "google.protobuf.BoolValue{} == false" + value: { bool_value: true } + } + test { + name: "eq_bool_not_null" + expr: "google.protobuf.BoolValue{} != null" + value: { bool_value: true } + } + test { + name: "eq_bool_proto2_null" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_bool_wrapper == null" + value: { bool_value: true } + } + test { + name: "eq_bool_proto3_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_bool_wrapper == null" + value: { bool_value: true } + } + + test { + name: "eq_bytes" + expr: "google.protobuf.BytesValue{value: b'set'} == b'set'" + value: { bool_value: true } + } + test { + name: "eq_bytes_empty" + expr: "google.protobuf.BytesValue{} == b''" + value: { bool_value: true } + } + test { + name: "eq_bytes_not_null" + expr: "google.protobuf.BytesValue{} != null" + value: { bool_value: true } + } + test { + name: "eq_bytes_proto2_null" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_bytes_wrapper == null" + value: { bool_value: true } + } + test { + name: "eq_bytes_proto3_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_bytes_wrapper == null" + value: { bool_value: true } + } + + test { + name: "eq_double" + expr: "google.protobuf.DoubleValue{value: -1.175494e-40} == -1.175494e-40" + value: { bool_value: true } + } + test { + name: "eq_double_empty" + expr: "google.protobuf.DoubleValue{} == 0.0" + value: { bool_value: true } + } + test { + name: "eq_double_not_null" + expr: "google.protobuf.DoubleValue{} != null" + value: { bool_value: true } + } + test { + name: "eq_double_proto2_null" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_double_wrapper == null" + value: { bool_value: true } + } + test { + name: "eq_double_proto3_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_double_wrapper == null" + value: { bool_value: true } + } + + test { + name: "eq_float" + expr: "google.protobuf.FloatValue{value: -1.5} == -1.5" + value: { bool_value: true } + } + test { + name: "eq_float_empty" + expr: "google.protobuf.FloatValue{} == 0.0" + value: { bool_value: true } + } + test { + name: "eq_float_not_null" + expr: "google.protobuf.FloatValue{} != null" + value: { bool_value: true } + } + test { + name: "eq_float_proto2_null" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_float_wrapper == null" + value: { bool_value: true } + } + test { + name: "eq_float_proto3_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_float_wrapper == null" + value: { bool_value: true } + } + + test { + name: "eq_int32" + expr: "google.protobuf.Int32Value{value: 123} == 123" + value: { bool_value: true } + } + test { + name: "eq_int32_empty" + expr: "google.protobuf.Int32Value{} == 0" + value: { bool_value: true } + } + test { + name: "eq_int32_not_null" + expr: "google.protobuf.Int32Value{} != null" + value: { bool_value: true } + } + test { + name: "eq_int32_proto2_null" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_int32_wrapper == null" + value: { bool_value: true } + } + test { + name: "eq_int32_proto3_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_int32_wrapper == null" + value: { bool_value: true } + } + + test { + name: "eq_int64" + expr: "google.protobuf.Int64Value{value: 2147483650} == 2147483650" + value: { bool_value: true } + } + test { + name: "eq_int64_empty" + expr: "google.protobuf.Int64Value{} == 0" + value: { bool_value: true } + } + test { + name: "eq_int64_not_null" + expr: "google.protobuf.Int64Value{} != null" + value: { bool_value: true } + } + test { + name: "eq_int64_proto2_null" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_int64_wrapper == null" + value: { bool_value: true } + } + test { + name: "eq_int64_proto3_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_int64_wrapper == null" + value: { bool_value: true } + } + + test { + name: "eq_string" + expr: "google.protobuf.StringValue{value: 'set'} == 'set'" + value: { bool_value: true } + } + test { + name: "eq_string_empty" + expr: "google.protobuf.StringValue{} == ''" + value: { bool_value: true } + } + test { + name: "eq_string_not_null" + expr: "google.protobuf.StringValue{} != null" + value: { bool_value: true } + } + test { + name: "eq_string_proto2_null" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_string_wrapper == null" + value: { bool_value: true } + } + test { + name: "eq_string_proto3_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_string_wrapper == null" + value: { bool_value: true } + } + + test { + name: "eq_uint32" + expr: "google.protobuf.UInt32Value{value: 42u} == 42u" + value: { bool_value: true } + } + test { + name: "eq_uint32_empty" + expr: "google.protobuf.UInt32Value{} == 0u" + value: { bool_value: true } + } + test { + name: "eq_uint32_not_null" + expr: "google.protobuf.UInt32Value{} != null" + value: { bool_value: true } + } + test { + name: "eq_uint32_proto2_null" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_uint32_wrapper == null" + value: { bool_value: true } + } + test { + name: "eq_uint32_proto3_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_uint32_wrapper == null" + value: { bool_value: true } + } + + test { + name: "eq_uint64" + expr: "google.protobuf.UInt64Value{value: 4294967296u} == 4294967296u" + value: { bool_value: true } + } + test { + name: "eq_uint64_empty" + expr: "google.protobuf.UInt64Value{} == 0u" + value: { bool_value: true } + } + test { + name: "eq_uint64_not_null" + expr: "google.protobuf.UInt64Value{} != null" + value: { bool_value: true } + } + test { + name: "eq_uint64_proto2_null" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_uint64_wrapper == null" + value: { bool_value: true } + } + test { + name: "eq_uint64_proto3_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_uint64_wrapper == null" + value: { bool_value: true } + } + test { + name: "eq_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int64: 1234, single_string: '1234'} == TestAllTypes{single_int64: 1234, single_string: '1234'}" + value { bool_value: true } + } + test { + name: "eq_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int64: 1234, single_string: '1234'} == TestAllTypes{single_int64: 1234, single_string: '1234'}" + value { bool_value: true } + } + test { + name: "eq_proto2_missing_fields_neq" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int64: 1234} == TestAllTypes{single_string: '1234'}" + value { bool_value: false } + } + test { + name: "eq_proto3_missing_fields_neq" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int64: 1234} == TestAllTypes{single_string: '1234'}" + value { bool_value: false } + } + test { + name: "eq_proto_nan_equal" + container: "cel.expr.conformance.proto2" + description: "For proto equality, fields with NaN value are treated as not equal." + expr: "TestAllTypes{single_double: double('NaN')} == TestAllTypes{single_double: double('NaN')}" + value { bool_value: false } + } + test { + name: "eq_proto_different_types" + container: "cel.expr.conformance.proto2" + description: "At runtime, differently typed messages are treated as not equal." + expr: "dyn(TestAllTypes{}) == dyn(NestedTestAllTypes{})" + value { bool_value: false } + } + test { + name: "eq_proto2_any_unpack_equal" + description: "Any values should be unpacked and compared." + container: "cel.expr.conformance.proto2" + # Two equal messages with any fields serialized differently (but both are valid). + # TestAllTypes{single_any: [TestAllTypes]{single_int64: 1234, single_string: '1234'}} + expr: + "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} ==" + " TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}" + value { bool_value: true } + } + test { + name: "eq_proto2_any_unpack_not_equal" + description: "Any values should be unpacked and compared." + container: "cel.expr.conformance.proto2" + # Two messages with any fields that are not equal + # TestAllTypes{single_any: [TestAllTypes]{single_int64: 1234, single_string: '1234'}} + # TestAllTypes{single_any: [TestAllTypes]{single_double: -1234.0, single_string: '1234'}} + expr: + "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'a\\000\\000\\000\\000\\000H\\223\\300r\\0041234'}} ==" + " TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}" + value { bool_value: false } + } + test { + name: "eq_proto2_any_unpack_bytewise_fallback_not_equal" + description: "If an any field is missing its type_url, the comparison should fallback to a bytewise comparison of the serialized proto." + container: "cel.expr.conformance.proto2" + # The missing type info any is doubly nested to skip create message validations. + expr: + "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} ==" + " TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}" + value { bool_value: false } + } + test { + name: "eq_proto2_any_unpack_bytewise_fallback_equal" + description: "If an any field is missing its type_url, the comparison should fallback to a bytewise comparison of the serialized proto." + container: "cel.expr.conformance.proto2" + # The missing type info any is doubly nested to skip create message validations. + expr: + "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} ==" + " TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}}" + value { bool_value: true } + } + test { + name: "eq_proto3_any_unpack_equal" + description: "Any values should be unpacked and compared." + container: "cel.expr.conformance.proto3" + # Two equal messages with any fields serialized differently (but both are valid). + expr: + "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} ==" + " TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}" + value { bool_value: true } + } + test { + name: "eq_proto3_any_unpack_not_equal" + description: "Any values should be unpacked and compared." + container: "cel.expr.conformance.proto3" + # Two messages with any fields that are not equal + # TestAllTypes{single_any: [TestAllTypes]{single_int64: 1234, single_string: '1234'}} + # TestAllTypes{single_any: [TestAllTypes]{single_double: -1234.0, single_string: '1234'}} + expr: + "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'a\\000\\000\\000\\000\\000H\\223\\300r\\0041234'}} ==" + " TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}" + value { bool_value: false } + } + test { + name: "eq_proto3_any_unpack_bytewise_fallback_not_equal" + description: "If an any field is missing its type_url, the comparison should fallback to a bytewise comparison of the serialized proto." + container: "cel.expr.conformance.proto3" + # The missing type info any is doubly nested to skip create message validations. + expr: + "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} ==" + " TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}" + value { bool_value: false } + } + test { + name: "eq_proto3_any_unpack_bytewise_fallback_equal" + description: "If an any field is missing its type_url, the comparison should fallback to a bytewise comparison of the serialized proto." + container: "cel.expr.conformance.proto3" + # The missing type info any is doubly nested to skip create message validations. + expr: + "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} ==" + " TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}}" + value { bool_value: true } + } +} +section { + name: "ne_literal" + description: "Literals comparison on _!=_" + test { + name: "ne_int" + expr: "24 != 42" + value: { bool_value: true } + } + test { + name: "not_ne_int" + expr: "1 != 1" + value: { bool_value: false } + } + test { + name: "ne_int_double" + expr: "dyn(24) != 24.1" + value: { bool_value: true } + } + test { + name: "not_ne_int_double" + expr: "dyn(1) != 1.0" + value: { bool_value: false } + } + test { + name: "ne_int_uint" + expr: "dyn(24) != 42u" + value: { bool_value: true } + } + test { + name: "not_ne_int_uint" + expr: "dyn(1) != 1u" + value: { bool_value: false } + } + test { + name: "ne_uint" + expr: "1u != 2u" + value: { bool_value: true } + } + test { + name: "not_ne_uint" + expr: "99u != 99u" + value: { bool_value: false } + } + test { + name: "ne_uint_double" + expr: "dyn(1u) != 2.0" + value: { bool_value: true } + } + test { + name: "not_ne_uint_double" + expr: "dyn(99u) != 99.0" + value: { bool_value: false } + } + test { + name: "ne_double" + expr: "9.0e+3 != 9001.0" + value: { bool_value: true } + } + test { + name: "not_ne_double_nan" + expr: "0.0/0.0 != 0.0/0.0" + value: { bool_value: true } + } + test { + name: "not_ne_int_double_nan" + expr: "dyn(1) != 0.0/0.0" + value: { bool_value: true } + } + test { + name: "not_ne_uint_double_nan" + expr: "dyn(1u) != 0.0/0.0" + value: { bool_value: true } + } + test { + name: "not_ne_double" + expr: "1.0 != 1e+0" + value: { bool_value: false } + } + test { + name: "ne_double_int" + expr: "dyn(9000) != 9001.0" + value: { bool_value: true } + } + test { + name: "not_ne_double_int" + expr: "dyn(1) != 1e+0" + value: { bool_value: false } + } + test { + name: "ne_double_uint" + expr: "dyn(9000u) != 9001.0" + value: { bool_value: true } + } + test { + name: "not_ne_double_uint" + expr: "dyn(1u) != 1e+0" + value: { bool_value: false } + } + test { + name: "ne_double_nan" + expr: "0.0/0.0 != 0.0/0.0" + value: { bool_value: true } + } + test { + name: "ne_string" + expr: "'abc' != ''" + value: { bool_value: true } + } + test { + name: "not_ne_string" + expr: "'abc' != 'abc'" + value: { bool_value: false } + } + test { + name: "ne_string_unicode" + expr: "'résumé' != 'resume'" + value: { bool_value: true } + } + test { + name: "not_ne_string_unicode" + expr: "'ίδιο' != 'ίδιο'" + value: { bool_value: false } + } + test { + name: "ne_bytes" + expr: "b'\\x00\\xFF' != b'ÿ'" + value: { bool_value: true } + } + test { + name: "not_ne_bytes" + expr: "b'\\303\\277' != b'ÿ'" + value: { bool_value: false } + } + test { + name: "ne_bool" + expr: "false != true" + value: { bool_value: true } + } + test { + name: "not_ne_bool" + expr: "true != true" + value: { bool_value: false } + } + test { + name: "not_ne_null" + description: "null can only be equal to null, or else it won't match" + expr: "null != null" + value: { bool_value: false } + } + test { + name: "ne_list_empty" + expr: "[] != [1]" + value: { bool_value: true } + } + test { + name: "not_ne_list_empty" + expr: "[] != []" + value: { bool_value: false } + } + test { + name: "ne_list_bool" + expr: "[true, false, true] != [true, true, false]" + value: { bool_value: true } + } + test { + name: "not_ne_list_bool" + expr: "[false, true] != [false, true]" + value: { bool_value: false } + } + test { + name: "not_ne_list_of_list" + expr: "[[]] != [[]]" + value: { bool_value: false } + } + test { + name: "ne_map_by_value" + expr: "{'k':'v'} != {'k':'v1'}" + value: { bool_value: true } + } + test { + name: "ne_map_by_key" + expr: "{'k':true} != {'k1':true}" + value: { bool_value: true } + } + test { + name: "not_ne_map_int_to_float" + expr: "{1:1.0} != {1:1.0}" + value: { bool_value: false } + } + test { + name: "not_ne_map_key_order" + expr: "{'a':'b','c':'d'} != {'c':'d','a':'b'}" + value: { bool_value: false } + } + test { + name: "ne_mixed_types" + expr: "2u != 2" + disable_check: true + value: { bool_value: false } + } + test { + name: "ne_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int64: 1234, single_string: '1234'} != TestAllTypes{single_int64: 1234, single_string: '1234'}" + value { bool_value: false } + } + test { + name: "ne_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int64: 1234, single_string: '1234'} != TestAllTypes{single_int64: 1234, single_string: '1234'}" + value { bool_value: false } + } + test { + name: "ne_proto2_missing_fields_neq" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int64: 1234} != TestAllTypes{single_string: '1234'}" + value { bool_value: true } + } + test { + name: "ne_proto3_missing_fields_neq" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int64: 1234} != TestAllTypes{single_string: '1234'}" + value { bool_value: true } + } + test { + name: "ne_proto_nan_not_equal" + container: "cel.expr.conformance.proto2" + description: "For proto equality, NaN field values are not considered equal." + expr: "TestAllTypes{single_double: double('NaN')} != TestAllTypes{single_double: double('NaN')}" + value { bool_value: true } + } + test { + name: "ne_proto_different_types" + container: "cel.expr.conformance.proto2" + description: "At runtime, comparing differently typed messages is false." + expr: "dyn(TestAllTypes{}) != dyn(NestedTestAllTypes{})" + value: { bool_value: true } + } + test { + name: "ne_proto2_any_unpack" + description: "Any values should be unpacked and compared." + container: "cel.expr.conformance.proto2" + # Two equal messages with any fields serialized differently (but both are valid). + # TestAllTypes{single_any: [TestAllTypes]{single_int64: 1234, single_string: '1234'}} + expr: + "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} !=" + " TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}" + value { bool_value: false } + } + test { + name: "ne_proto2_any_unpack_bytewise_fallback" + description: "If an any field is missing its type_url, the comparison should fallback to a bytewise comparison of the serialized proto." + container: "cel.expr.conformance.proto3" + # The missing type info any is doubly nested to skip create + # message validations. + expr: + "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} !=" + " TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}" + value { bool_value: true } + } + test { + name: "ne_proto3_any_unpack" + description: "Any values should be unpacked and compared." + container: "cel.expr.conformance.proto2" + # Two equal messages with any fields serialized differently (but both are valid). + expr: + "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} !=" + " TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}" + value { bool_value: false } + } + test { + name: "ne_proto3_any_unpack_bytewise_fallback" + description: "If an any field is missing its type_url, the comparison should fallback to a bytewise comparison of the serialized proto." + container: "cel.expr.conformance.proto3" + # The missing type info any is doubly nested to skip create message validations. + expr: + "TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001r\\0041234'}} !=" + " TestAllTypes{single_any: google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\242\\006\\023\\022\\021r\\0041234\\020\\256\\366\\377\\377\\377\\377\\377\\377\\377\\001'}}" + value { bool_value: true } + } +} +section { + name: "lt_literal" + description: "Literals comparison on _<_. (a < b) == (b > a) == !(a >= b) == !(b <= a)" + test { + name: "lt_int" + expr: "-1 < 0" + value: { bool_value: true } + } + test { + name: "not_lt_int" + expr: "0 < 0" + value: { bool_value: false } + } + test { + name: "lt_uint" + expr: "0u < 1u" + value: { bool_value: true } + } + test { + name: "not_lt_uint" + expr: "2u < 2u" + value: { bool_value: false } + } + test { + name: "lt_double" + expr: "1.0 < 1.0000001" + value: { bool_value: true } + } + test { + name: "not_lt_double" + description: "Following IEEE 754, negative zero compares equal to zero" + expr: "-0.0 < 0.0" + value: { bool_value: false } + } + test { + name: "lt_string" + expr: "'a' < 'b'" + value: { bool_value: true } + } + test { + name: "lt_string_empty_to_nonempty" + expr: "'' < 'a'" + value: { bool_value: true } + } + test { + name: "lt_string_case" + expr: "'Abc' < 'aBC'" + value: { bool_value: true } + } + test { + name: "lt_string_length" + expr: "'abc' < 'abcd'" + value: { bool_value: true } + } + test { + name: "lt_string_diacritical_mark_sensitive" + description: "Verifies that the we're not using a string comparison function that strips diacritical marks (á)" + expr: "'a' < '\\u00E1'" + value: { bool_value: true } + } + test { + name: "not_lt_string_empty" + expr: "'' < ''" + value: { bool_value: false } + } + test { + name: "not_lt_string_same" + expr: "'abc' < 'abc'" + value: { bool_value: false } + } + test { + name: "not_lt_string_case_length" + expr: "'a' < 'AB'" + value: { bool_value: false } + } + test { + name: "unicode_order_lexical" + description: "Compare the actual code points of the string, instead of decomposing ế into 'e' plus accent modifiers." + expr: "'f' < '\\u1EBF'" + value: { bool_value: true } + } + test { + name: "lt_bytes" + expr: "b'a' < b'b'" + value: { bool_value: true } + } + test { + name: "not_lt_bytes_same" + expr: "b'abc' < b'abc'" + value: { bool_value: false } + } + test { + name: "not_lt_bytes_width" + expr: "b'á' < b'b'" + value: { bool_value: false } + } + test { + name: "lt_bool_false_first" + expr: "false < true" + value: { bool_value: true } + } + test { + name: "not_lt_bool_same" + expr: "true < true" + value: { bool_value: false } + } + test { + name: "not_lt_bool_true_first" + expr: "true < false" + value: { bool_value: false } + } + test { + name: "lt_list_unsupported" + expr: "[0] < [1]" + disable_check: true + eval_error: { + errors: { message: "no such overload" } + } + } + test { + name: "lt_map_unsupported" + expr: "{0:'a'} < {1:'b'}" + disable_check: true + eval_error: { + errors: { message: "no such overload" } + } + } + test { + name: "lt_null_unsupported" + description: "Ensure _<_ doesn't have a binding for null" + expr: "null < null" + disable_check: true + eval_error: { + errors: { message: "no such overload" } + } + } + test { + name: "lt_mixed_types_error" + expr: "'foo' < 1024" + disable_check: true + eval_error: { + errors: { message: "no such overload" } + } + } + test { + name: "lt_dyn_int_uint" + expr: "dyn(1) < 2u" + value: { bool_value: true } + } + test { + name: "lt_dyn_int_double" + expr: "dyn(1) < 2.0" + value: { bool_value: true } + } + test { + name: "lt_dyn_uint_int" + expr: "dyn(1u) < 2" + value: { bool_value: true } + } + test { + name: "lt_dyn_uint_double" + expr: "dyn(1u) < 2.0" + value: { bool_value: true } + } + test { + name: "lt_dyn_double_int" + expr: "dyn(1.0) < 2" + value: { bool_value: true } + } + test { + name: "lt_dyn_double_uint" + expr: "dyn(1.0) < 2u" + value: { bool_value: true } + } + test { + name: "not_lt_dyn_int_uint" + expr: "dyn(1) < 1u" + value: { bool_value: false } + } + test { + name: "not_lt_dyn_int_double" + expr: "dyn(1) < 1.0" + value: { bool_value: false } + } + test { + name: "not_lt_dyn_uint_int" + expr: "dyn(1u) < 1" + value: { bool_value: false } + } + test { + name: "not_lt_dyn_uint_double" + expr: "dyn(1u) < 1.0" + value: { bool_value: false } + } + test { + name: "not_lt_dyn_double_int" + expr: "dyn(1.0) < 1" + value: { bool_value: false } + } + test { + name: "not_lt_dyn_double_uint" + expr: "dyn(1.0) < 1u" + value: { bool_value: false } + } + test { + name: "lt_dyn_int_big_uint" + expr: "dyn(1) < 9223372036854775808u" + value: { bool_value: true } + } + test { + name: "lt_dyn_small_int_uint" + expr: "dyn(-1) < 0u" + value: { bool_value: true } + } + test { + name: "not_lt_dyn_int_big_lossy_double" + expr: "dyn(9223372036854775807) < 9223372036854775808.0" + value: { bool_value: false } + } + test { + name: "lt_dyn_int_big_lossy_double" + expr: "dyn(9223372036854775807) < 9223372036854777857.0" + value: { bool_value: true } + } + test { + name: "not_lt_dyn_int_small_double" + expr: "dyn(9223372036854775807) < -9223372036854777857.0" + value: { bool_value: false } + } + test { + name: "not_lt_dyn_int_small_lossy_double" + expr: "dyn(-9223372036854775808) < -9223372036854775809.0" + value: { bool_value: false } + } + test { + name: "not_lt_dyn_uint_small_int" + expr: "dyn(1u) < -9223372036854775808" + value: { bool_value: false } + } + test { + name: "not_lt_dyn_big_uint_int" + expr: "dyn(9223372036854775808u) < 1" + value: { bool_value: false } + } + test { + name: "not_lt_dyn_uint_small_double" + expr: "dyn(18446744073709551615u) < -1.0" + value: { bool_value: false } + } + test { + name: "lt_dyn_uint_big_double" + expr: "dyn(18446744073709551615u) < 18446744073709590000.0" + value: { bool_value: true } + } + test { + name: "not_lt_dyn_big_double_uint" + expr: "dyn(18446744073709553665.0) < 18446744073709551615u" + value: { bool_value: false } + } + test { + name: "not_lt_dyn_big_double_int" + expr: "dyn(9223372036854775808.0) < 9223372036854775807" + value: { bool_value: false } + } + test { + name: "not_lt_dyn_small_double_int" + expr: "dyn(-9223372036854775809.0) < -9223372036854775808" + value: { bool_value: false } + } + +} +section { + name: "gt_literal" + description: "Literals comparison on _>_" + test { + name: "gt_int" + expr: "42 > -42" + value: { bool_value: true } + } + test { + name: "not_gt_int" + expr: "0 > 0" + value: { bool_value: false } + } + test { + name: "gt_uint" + expr: "48u > 46u" + value: { bool_value: true } + } + test { + name: "not_gt_uint" + expr: "0u > 999u" + value: { bool_value: false } + } + test { + name: "gt_double" + expr: "1e+1 > 1e+0" + value: { bool_value: true } + } + test { + name: "not_gt_double" + expr: ".99 > 9.9e-1" + value: { bool_value: false } + } + test { + name: "gt_string_case" + expr: "'abc' > 'aBc'" + value: { bool_value: true } + } + test { + name: "gt_string_to_empty" + expr: "'A' > ''" + value: { bool_value: true } + } + test { + name: "not_gt_string_empty_to_empty" + expr: "'' > ''" + value: { bool_value: false } + } + test { + name: "gt_string_unicode" + expr: "'α' > 'omega'" + value: { bool_value: true } + } + test { + name: "gt_bytes_one" + expr: "b'\x01' > b'\x00'" + value: { bool_value: true } + } + test { + name: "gt_bytes_one_to_empty" + expr: "b'\x00' > b''" + value: { bool_value: true } + } + test { + name: "not_gt_bytes_sorting" + expr: "b'\x00\x01' > b'\x01'" + value: { bool_value: false } + } + test { + name: "gt_bool_true_false" + expr: "true > false" + value: { bool_value: true } + } + test { + name: "not_gt_bool_false_true" + expr: "false > true" + value: { bool_value: false } + } + test { + name: "not_gt_bool_same" + expr: "true > true" + value: { bool_value: false } + } + test { + name: "gt_null_unsupported" + expr: "null > null" + disable_check: true + eval_error: { + errors: { message: "no such overload" } + } + } + test { + name: "gt_list_unsupported" + expr: "[1] > [0]" + disable_check: true + eval_error: { + errors: { message: "no such overload" } + } + } + test { + name: "gt_map_unsupported" + expr: "{1:'b'} > {0:'a'}" + disable_check: true + eval_error: { + errors: { message: "no such overload" } + } + } + test { + name: "gt_mixed_types_error" + expr: "'foo' > 1024" + disable_check: true + eval_error: { + errors: { message: "no such overload" } + } + } + test { + name: "gt_dyn_int_uint" + expr: "dyn(2) > 1u" + value: { bool_value: true } + } + test { + name: "gt_dyn_int_double" + expr: "dyn(2) > 1.0" + value: { bool_value: true } + } + test { + name: "gt_dyn_uint_int" + expr: "dyn(2u) > 1" + value: { bool_value: true } + } + test { + name: "gt_dyn_uint_double" + expr: "dyn(2u) > 1.0" + value: { bool_value: true } + } + test { + name: "gt_dyn_double_int" + expr: "dyn(2.0) > 1" + value: { bool_value: true } + } + test { + name: "gt_dyn_double_uint" + expr: "dyn(2.0) > 1u" + value: { bool_value: true } + } + test { + name: "not_gt_dyn_int_uint" + expr: "dyn(1) > 1u" + value: { bool_value: false } + } + test { + name: "not_gt_dyn_int_double" + expr: "dyn(1) > 1.0" + value: { bool_value: false } + } + test { + name: "not_gt_dyn_uint_int" + expr: "dyn(1u) > 1" + value: { bool_value: false } + } + test { + name: "not_gt_dyn_uint_double" + expr: "dyn(1u) > 1.0" + value: { bool_value: false } + } + test { + name: "not_gt_dyn_double_int" + expr: "dyn(1.0) > 1" + value: { bool_value: false } + } + test { + name: "not_gt_dyn_double_uint" + expr: "dyn(1.0) > 1u" + value: { bool_value: false } + } + test { + name: "not_gt_dyn_int_big_uint" + expr: "dyn(1) > 9223372036854775808u" + value: { bool_value: false } + } + test { + name: "not_gt_dyn_small_int_uint" + expr: "dyn(-1) > 0u" + value: { bool_value: false } + } + test { + name: "not_gt_dyn_int_big_double" + expr: "dyn(9223372036854775807) > 9223372036854775808.0" + value: { bool_value: false } + } + test { + name: "not_gt_dyn_int_small_lossy_double" + description: "The conversion of the int to double is lossy and the numbers end up being equal" + expr: "dyn(-9223372036854775808) > -9223372036854775809.0" + value: { bool_value: false } + } + test { + name: "gt_dyn_int_small_lossy_double_greater" + expr: "dyn(-9223372036854775808) > -9223372036854777857.0" + value: { bool_value: true } + } + test { + name: "gt_dyn_uint_small_int" + expr: "dyn(1u) > -1" + value: { bool_value: true } + } + test { + name: "gt_dyn_big_uint_int" + expr: "dyn(9223372036854775808u) > 1" + value: { bool_value: true } + } + test { + name: "gt_dyn_uint_small_double" + expr: "dyn(9223372036854775807u) > -1.0" + value: { bool_value: true } + } + test { + name: "not_gt_dyn_uint_big_double" + expr: "dyn(18446744073709551615u) > 18446744073709590000.0" + value: { bool_value: false } + } + test { + name: "gt_dyn_big_double_uint" + expr: "dyn(18446744073709553665.0) > 18446744073709551615u" + value: { bool_value: true } + } + test { + name: "not_gt_dyn_big_double_int" + expr: "dyn(9223372036854775808.0) > 9223372036854775807" + value: { bool_value: false } + } + test { + name: "not_gt_dyn_small_double_int" + expr: "dyn(-9223372036854775809.0) > -9223372036854775808" + value: { bool_value: false } + } +} +section { + name: "lte_literal" + description: "Literals comparison on _<=_" + test { + name: "lte_int_lt" + expr: "0 <= 1" + value: { bool_value: true } + } + test { + name: "lte_int_eq" + expr: "1 <= 1" + value: { bool_value: true } + } + test { + name: "not_lte_int_gt" + expr: "1 <= -1" + value: { bool_value: false } + } + test { + name: "lte_uint_lt" + expr: "0u <= 1u" + value: { bool_value: true } + } + test { + name: "lte_uint_eq" + expr: "1u <= 1u" + value: { bool_value: true } + } + test { + name: "not_lte_uint_gt" + expr: "1u <= 0u" + value: { bool_value: false } + } + test { + name: "lte_double_lt" + expr: "0.0 <= 0.1e-31" + value: { bool_value: true } + } + test { + name: "lte_double_eq" + expr: "0.0 <= 0e-1" + value: { bool_value: true } + } + test { + name: "not_lte_double_gt" + expr: "1.0 <= 0.99" + value: { bool_value: false } + } + test { + name: "lte_string_empty" + expr: "'' <= ''" + value: { bool_value: true } + } + test { + name: "lte_string_from_empty" + expr: "'' <= 'a'" + value: { bool_value: true } + } + test { + name: "not_lte_string_to_empty" + expr: "'a' <= ''" + value: { bool_value: false } + } + test { + name: "lte_string_lexicographical" + expr: "'aBc' <= 'abc'" + value: { bool_value: true } + } + test { + name: "lte_string_unicode_eq" + expr: "'α' <= 'α'" + value: { bool_value: true } + } + test { + name: "lte_string_unicode_lt" + expr: "'a' <= 'α'" + value: { bool_value: true } + } + test { + name: "not_lte_string_unicode" + expr: "'α' <= 'a'" + value: { bool_value: false } + } + test { + name: "lte_bytes_empty" + expr: "b'' <= b'\x00'" + value: { bool_value: true } + } + test { + name: "not_lte_bytes_length" + expr: "b'\x01\x00' <= b'\x01'" + value: { bool_value: false } + } + test { + name: "lte_bool_false_true" + expr: "false <= true" + value: { bool_value: true } + } + test { + name: "lte_bool_false_false" + expr: "false <= false" + value: { bool_value: true } + } + test { + name: "lte_bool_true_false" + expr: "true <= false" + value: { bool_value: false } + } + test { + name: "lte_null_unsupported" + expr: "null <= null" + disable_check: true + eval_error: { + errors: { message: "no such overload" } + } + } + test { + name: "lte_list_unsupported" + expr: "[0] <= [0]" + disable_check: true + eval_error: { + errors: { message: "no such overload" } + } + } + test { + name: "lte_map_unsupported" + expr: "{0:'a'} <= {1:'b'}" + disable_check: true + eval_error: { + errors: { message: "no such overload" } + } + } + test { + name: "lte_mixed_types_error" + expr: "'foo' <= 1024" + disable_check: true + eval_error: { + errors: { message: "no such overload" } + } + } + test { + name: "lte_dyn_int_uint" + expr: "dyn(1) <= 2u" + value: { bool_value: true } + } + test { + name: "lte_dyn_int_double" + expr: "dyn(1) <= 2.0" + value: { bool_value: true } + } + test { + name: "lte_dyn_uint_int" + expr: "dyn(1u) <= 2" + value: { bool_value: true } + } + test { + name: "lte_dyn_uint_double" + expr: "dyn(1u) <= 2.0" + value: { bool_value: true } + } + test { + name: "lte_dyn_double_int" + expr: "dyn(1.0) <= 2" + value: { bool_value: true } + } + test { + name: "lte_dyn_double_uint" + expr: "dyn(1.0) <= 2u" + value: { bool_value: true } + } + test { + name: "not_lte_dyn_int_uint" + expr: "dyn(2) <= 1u" + value: { bool_value: false } + } + test { + name: "not_lte_dyn_int_double" + expr: "dyn(2) <= 1.0" + value: { bool_value: false } + } + test { + name: "not_lte_dyn_uint_int" + expr: "dyn(2u) <= 1" + value: { bool_value: false } + } + test { + name: "not_lte_dyn_uint_double" + expr: "dyn(2u) <= 1.0" + value: { bool_value: false } + } + test { + name: "not_lte_dyn_double_int" + expr: "dyn(2.0) <= 1" + value: { bool_value: false } + } + test { + name: "not_lte_dyn_double_uint" + expr: "dyn(2.0) <= 1u" + value: { bool_value: false } + } + test { + name: "lte_dyn_int_big_uint" + expr: "dyn(1) <= 9223372036854775808u" + value: { bool_value: true } + } + test { + name: "lte_dyn_small_int_uint" + expr: "dyn(-1) <= 0u" + value: { bool_value: true } + } + test { + name: "lte_dyn_int_big_double" + expr: "dyn(9223372036854775807) <= 9223372036854775808.0" + value: { bool_value: true } + } + test { + name: "lte_dyn_int_small_lossy_double" + description: "The conversion of the int to double is lossy and the numbers end up being equal" + expr: "dyn(-9223372036854775808) <= -9223372036854775809.0" + value: { bool_value: true } + } + test { + name: "not_lte_dyn_int_small_lossy_double_less" + expr: "dyn(-9223372036854775808) <= -9223372036854777857.0" + value: { bool_value: false } + } + test { + name: "not_lte_dyn_uint_small_int" + expr: "dyn(1u) <= -9223372036854775808" + value: { bool_value: false } + } + test { + name: "not_lte_dyn_big_uint_int" + expr: "dyn(9223372036854775808u) <= 1" + value: { bool_value: false } + } + test { + name: "not_lte_dyn_uint_small_double" + expr: "dyn(18446744073709551615u) <= -1.0" + value: { bool_value: false } + } + test { + name: "lte_dyn_uint_big_double" + expr: "dyn(18446744073709551615u) <= 18446744073709590000.0" + value: { bool_value: true } + } + test { + name: "not_lte_dyn_big_double_uint" + expr: "dyn(18446744073709553665.0) <= 18446744073709551615u" + value: { bool_value: false } + } + test { + name: "lte_dyn_big_double_int" + expr: "dyn(9223372036854775808.0) <= 9223372036854775807" + value: { bool_value: true } + } + test { + name: "lte_dyn_small_double_int" + expr: "dyn(-9223372036854775809.0) <= -9223372036854775808" + value: { bool_value: true } + } +} +section { + name: "gte_literal" + description: "Literals comparison on _>=_" + test { + name: "gte_int_gt" + expr: "0 >= -1" + value: { bool_value: true } + } + test { + name: "gte_int_eq" + expr: "999 >= 999" + value: { bool_value: true } + } + test { + name: "not_gte_int_lt" + expr: "999 >= 1000" + value: { bool_value: false } + } + test { + name: "gte_uint_gt" + expr: "1u >= 0u" + value: { bool_value: true } + } + test { + name: "gte_uint_eq" + expr: "0u >= 0u" + value: { bool_value: true } + } + test { + name: "not_gte_uint_lt" + expr: "1u >= 10u" + value: { bool_value: false } + } + test { + name: "gte_double_gt" + expr: "1e+1 >= 1e+0" + value: { bool_value: true } + } + test { + name: "gte_double_eq" + expr: "9.80665 >= 9.80665e+0" + value: { bool_value: true } + } + test { + name: "not_gte_double_lt" + expr: "0.9999 >= 1.0" + value: { bool_value: false } + } + test { + name: "gte_string_empty" + expr: "'' >= ''" + value: { bool_value: true } + } + test { + name: "gte_string_to_empty" + expr: "'a' >= ''" + value: { bool_value: true } + } + test { + name: "gte_string_empty_to_nonempty" + expr: "'' >= 'a'" + value: { bool_value: false } + } + test { + name: "gte_string_length" + expr: "'abcd' >= 'abc'" + value: { bool_value: true } + } + test { + name: "not_gte_string_lexicographical" + expr: "'abc' >= 'abd'" + value: { bool_value: false } + } + test { + name: "gte_string_unicode_eq" + expr: "'τ' >= 'τ'" + value: { bool_value: true } + } + test { + name: "gte_string_unicode_gt" + expr: "'τ' >= 't'" + value: { bool_value: true } + } + test { + name: "not_get_string_unicode" + expr: "'t' >= 'τ'" + value: { bool_value: false } + } + test { + name: "gte_bytes_to_empty" + expr: "b'\x00' >= b''" + value: { bool_value: true } + } + test { + name: "not_gte_bytes_empty_to_nonempty" + expr: "b'' >= b'\x00'" + value: { bool_value: false } + } + test { + name: "gte_bytes_samelength" + expr: "b'\x00\x01' >= b'\x01\x00'" + value: { bool_value: false } + } + test { + name: "gte_bool_gt" + expr: "true >= false" + value: { bool_value: true } + } + test { + name: "gte_bool_eq" + expr: "true >= true" + value: { bool_value: true } + } + test { + name: "not_gte_bool_lt" + expr: "false >= true" + value: { bool_value: false } + } + test { + name: "gte_null_unsupported" + expr: "null >= null" + disable_check: true + eval_error: { + errors: { message: "no such overload" } + } + } + test { + name: "gte_list_unsupported" + expr: "['y'] >= ['x']" + disable_check: true + eval_error: { + errors: { message: "no such overload" } + } + } + test { + name: "gte_map_unsupported" + expr: "{1:'b'} >= {0:'a'}" + disable_check: true + eval_error: { + errors: { message: "no such overload" } + } + } + test { + name: "gte_mixed_types_error" + expr: "'foo' >= 1.0" + disable_check: true + eval_error: { + errors: { message: "no such overload" } + } + } + test { + name: "gte_dyn_int_uint" + expr: "dyn(2) >= 1u" + value: { bool_value: true } + } + test { + name: "gte_dyn_int_double" + expr: "dyn(2) >= 1.0" + value: { bool_value: true } + } + test { + name: "gte_dyn_uint_int" + expr: "dyn(2u) >= 1" + value: { bool_value: true } + } + test { + name: "gte_dyn_uint_double" + expr: "dyn(2u) >= 1.0" + value: { bool_value: true } + } + test { + name: "gte_dyn_double_int" + expr: "dyn(2.0) >= 1" + value: { bool_value: true } + } + test { + name: "gte_dyn_double_uint" + expr: "dyn(2.0) >= 1u" + value: { bool_value: true } + } + test { + name: "not_gte_dyn_int_uint" + expr: "dyn(0) >= 1u" + value: { bool_value: false } + } + test { + name: "not_gte_dyn_int_double" + expr: "dyn(0) >= 1.0" + value: { bool_value: false } + } + test { + name: "not_gte_dyn_uint_int" + expr: "dyn(0u) >= 1" + value: { bool_value: false } + } + test { + name: "not_gte_dyn_uint_double" + expr: "dyn(0u) >= 1.0" + value: { bool_value: false } + } + test { + name: "not_gte_dyn_double_int" + expr: "dyn(0.0) >= 1" + value: { bool_value: false } + } + test { + name: "not_gte_dyn_double_uint" + expr: "dyn(0.0) >= 1u" + value: { bool_value: false } + } + test { + name: "not_gte_dyn_int_big_uint" + expr: "dyn(1) >= 9223372036854775808u" + value: { bool_value: false } + } + test { + name: "not_gte_dyn_small_int_uint" + expr: "dyn(-1) >= 0u" + value: { bool_value: false } + } + test { + name: "gte_dyn_int_big_lossy_double" + expr: "dyn(9223372036854775807) >= 9223372036854775808.0" + value: { bool_value: true } + } + test { + name: "not_gte_dyn_int_big_double" + expr: "dyn(9223372036854775807) >= 9223372036854777857.0" + value: { bool_value: false } + } + test { + name: "gte_dyn_int_small_lossy_double_equal" + description: "The conversion of the int to double is lossy and the numbers end up being equal" + expr: "dyn(-9223372036854775808) >= -9223372036854775809.0" + value: { bool_value: true } + } + test { + name: "gte_dyn_int_small_lossy_double_greater" + expr: "dyn(-9223372036854775808) >= -9223372036854777857.0" + value: { bool_value: true } + } + test { + name: "gte_dyn_uint_small_int" + expr: "dyn(1u) >= -1" + value: { bool_value: true } + } + test { + name: "gte_dyn_big_uint_int" + expr: "dyn(9223372036854775808u) >= 1" + value: { bool_value: true } + } + test { + name: "gte_dyn_uint_small_double" + expr: "dyn(9223372036854775807u) >= -1.0" + value: { bool_value: true } + } + test { + name: "not_gte_dyn_uint_big_double" + expr: "dyn(18446744073709551615u) >= 18446744073709553665.0" + value: { bool_value: false } + } + test { + name: "gte_dyn_big_double_uint" + expr: "dyn(18446744073709553665.0) >= 18446744073709551615u" + value: { bool_value: true } + } + test { + name: "gte_dyn_big_double_int" + expr: "dyn(9223372036854775808.0) >= 9223372036854775807" + value: { bool_value: true } + } + test { + name: "gte_dyn_small_double_int" + expr: "dyn(-9223372036854775809.0) >= -9223372036854775808" + value: { bool_value: true } + } +} +section { + name: "in_list_literal" + description: "Set membership tests using list literals and the 'in' operator" + test { + name: "elem_not_in_empty_list" + expr: "'empty' in []" + value { bool_value: false } + } + test { + name: "elem_in_list" + expr: "'elem' in ['elem', 'elemA', 'elemB']" + value { bool_value: true } + } + test { + name: "elem_not_in_list" + expr: "'not' in ['elem1', 'elem2', 'elem3']" + value { bool_value: false } + } + test { + name: "elem_in_mixed_type_list" + description: "Set membership tests should succeed if the 'elem' exists in a mixed element type list." + expr: "'elem' in [1, 'elem', 2]" + value { bool_value: true } + } + test { + name: "elem_in_mixed_type_list_cross_type" + description: "Set membership tests should return false due to the introduction of heterogeneous-equality. Set membership via 'in' is equivalent to the macro exists() behavior." + expr: "'elem' in [1u, 'str', 2, b'bytes']" + value: { bool_value: false } + } +} +section { + name: "in_map_literal" + description: "Set membership tests using map literals and the 'in' operator" + test { + name: "key_not_in_empty_map" + expr: "'empty' in {}" + value { bool_value: false } + } + test { + name: "key_in_map" + expr: "'key' in {'key':'1', 'other':'2'}" + value { bool_value: true } + } + test { + name: "key_not_in_map" + expr: "'key' in {'lock':1, 'gate':2}" + value { bool_value: false } + } + test { + name: "key_in_mixed_key_type_map" + description: "Map keys are of mixed type, but since the key is present the result is true." + expr: "'key' in {3:3.0, 'key':2u}" + value { bool_value: true } + } + test { + name: "key_in_mixed_key_type_map_cross_type" + expr: "'key' in {1u:'str', 2:b'bytes'}" + value: { bool_value: false } + } +} +section { + name: "bound" + description: "Comparing bound variables with literals or other variables" + test { + name: "bytes_gt_left_false" + expr: "x > b'\x00'" + value: { bool_value: false } + type_env: { + name: "x" + ident: { type: { primitive: BYTES } } + } + bindings: { + key: "x" + value: { value: { bytes_value: "\x00" } } + } + } + test { + name: "int_lte_right_true" + expr: "123 <= x" + value: { bool_value: true } + type_env: { + name: "x" + ident: { type: { primitive: INT64 } } + } + bindings: { + key: "x" + value: { value: { int64_value: 124 } } + } + } + test { + name: "bool_lt_right_true" + expr: "false < x" + value: { bool_value: true } + type_env: { + name: "x" + ident: { type: { primitive: BOOL } } + } + bindings: { + key: "x" + value: { value: { bool_value: true } } + } + } + test { + name: "double_ne_left_false" + expr: "x != 9.8" + value: { bool_value: false } + type_env: { + name: "x" + ident: { type: { primitive: DOUBLE } } + } + bindings: { + key: "x" + value: { value: { double_value: 9.8 } } + } + } + test { + name: "map_ne_right_false" + expr: "{'a':'b','c':'d'} != x" + value: { bool_value: false } + type_env: { + name: "x" + ident: { + type: { + map_type: { + key_type: { primitive: STRING } + value_type: { primitive: STRING } + } + } + } + } + bindings: { + key: "x" + value: { + value: { + map_value { + entries { + key: { string_value: "c" } + value: { string_value: "d" } + } + entries { + key: { string_value: "a" } + value: { string_value: "b" } + } + } + } + } + } + } + test { + name: "null_eq_left_true" + description: "A comparison _==_ against null only binds if the type is determined to be null or we skip the type checking" + expr: "x == null" + value: { bool_value: true } + type_env: { + name: "x" + ident: { type: { null: NULL_VALUE } } + } + bindings: { + key: "x" + value: { value: { null_value: NULL_VALUE } } + } + } + test { + name: "list_eq_right_false" + expr: "[1, 2] == x" + value: { bool_value: false } + type_env: { + name: "x" + ident: { + type: { + list_type: { + elem_type: { primitive: INT64 } + } + } + } + } + bindings: { + key: "x" + value: { + value: { + list_value { + values: { int64_value: 2 } + values: { int64_value: 1 } + } + } + } + } + } + test { + name: "string_gte_right_true" + expr: "'abcd' >= x" + value: { bool_value: true } + type_env: { + name: "x" + ident: { + type: { primitive: STRING } + } + } + bindings: { + key: "x" + value: { value: { string_value: "abc" } } + } + } + test { + name: "uint_eq_right_false" + expr: "999u == x" + value: { bool_value: false } + type_env: { + name: "x" + ident: { + type: { primitive: UINT64 } + } + } + bindings: { + key: "x" + value: { value: { uint64_value: 1000 } } + } + } + test { + name: "null_lt_right_no_such_overload" + description: "There is no _<_ operation for null, even if both operands are null" + expr: "null < x" + eval_error: { + errors: { message: "no such overload" } + } + disable_check: true + bindings: { + key: "x" + value: { value: { null_value: NULL_VALUE } } + } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/conversions.textproto b/packages/cel-spec/src/testdata/textproto/conversions.textproto new file mode 100644 index 00000000..0e4d4b24 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/conversions.textproto @@ -0,0 +1,622 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "conversions" +description: "Tests for type conversions." +section { + name: "bytes" + description: "Conversions to bytes." + test { + name: "string_empty" + expr: "bytes('')" + value: { bytes_value: "" } + } + test { + name: "string" + expr: "bytes('abc')" + value: { bytes_value: "abc" } + } + test { + name: "string_unicode" + expr: "bytes('ÿ')" + value: { bytes_value: "\303\277" } + } + test { + name: "string_unicode_vs_literal" + expr: "bytes('\\377') == b'\\377'" + value: { bool_value: false } + } +} +section { + name: "double" + description: "Conversions to double." + test { + name: "int_zero" + expr: "double(0)" + value: { double_value: 0.0 } + } + test { + name: "int_pos" + expr: "double(1000000000000)" + value: { double_value: 1e12 } + } + test { + name: "int_neg" + expr: "double(-1000000000000000)" + value: { double_value: -1e15 } + } + test { + name: "int_min_exact" + description: "Smallest contiguous representable int (-2^53)." + expr: "double(-9007199254740992)" + value { double_value: -9.007199254740992e15 } + } + test { + name: "int_max_exact" + description: "Largest contiguous representable int (2^53)." + expr: "double(9007199254740992)" + value { double_value: 9.007199254740992e15 } + } + test { + name: "int_range" + description: "Largest signed 64-bit. Rounds to nearest double." + expr: "double(9223372036854775807)" + value: { double_value: 9.223372036854775807e18 } + } + test { + name: "uint_zero" + expr: "double(0u)" + value: { double_value: 0.0 } + } + test { + name: "uint_pos" + expr: "double(123u)" + value: { double_value: 123.0 } + } + test { + name: "uint_max_exact" + description: "Largest contiguous representable int (2^53)." + expr: "double(9007199254740992u)" + value { double_value: 9.007199254740992e15 } + } + test { + name: "uint_range" + description: "Largest unsigned 64-bit." + expr: "double(18446744073709551615u)" + value: { double_value: 1.8446744073709551615e19 } + } + test { + name: "string_zero" + expr: "double('0')" + value: { double_value: 0.0 } + } + test { + name: "string_zero_dec" + expr: "double('0.0')" + value: { double_value: 0.0 } + } + test { + name: "string_neg_zero" + expr: "double('-0.0')" + value: { double_value: -0.0 } + } + test { + name: "string_no_dec" + expr: "double('123')" + value: { double_value: 123.0 } + } + test { + name: "string_pos" + expr: "double('123.456')" + value: { double_value: 123.456 } + } + test { + name: "string_neg" + expr: "double('-987.654')" + value: { double_value: -987.654 } + } + test { + name: "string_exp_pos_pos" + expr: "double('6.02214e23')" + value: { double_value: 6.02214e23 } + } + test { + name: "string_exp_pos_neg" + expr: "double('1.38e-23')" + value: { double_value: 1.38e-23 } + } + test { + name: "string_exp_neg_pos" + expr: "double('-84.32e7')" + value: { double_value: -8.432e8 } + } + test { + name: "string_exp_neg_neg" + expr: "double('-5.43e-21')" + value: { double_value: -5.43e-21 } + } +} +section { + name: "dyn" + description: "Tests for dyn annotation." + test { + name: "dyn_heterogeneous_list" + description: "No need to disable type checking." + expr: "type(dyn([1, 'one']))" + value: { type_value: "list" } + } +} +section { + name: "int" + description: "Conversions to int." + test { + name: "uint" + expr: "int(42u)" + value: { int64_value: 42 } + } + test { + name: "uint_zero" + expr: "int(0u)" + value: { int64_value: 0 } + } + test { + name: "uint_max_exact" + expr: "int(9223372036854775807u)" + value { int64_value: 9223372036854775807 } + } + test { + name: "uint_range" + expr: "int(18446744073709551615u)" + eval_error { + errors { message: "range error" } + } + } + test { + name: "double_round_neg" + expr: "int(-123.456)" + value: { int64_value: -123 } + } + test { + name: "double_truncate" + expr: "int(1.9)" + value: { int64_value: 1 } + } + test { + name: "double_truncate_neg" + expr: "int(-7.9)" + value: { int64_value: -7 } + } + test { + name: "double_half_pos" + expr: "int(11.5)" + value: { int64_value: 11 } + } + test { + name: "double_half_neg" + expr: "int(-3.5)" + value: { int64_value: -3 } + } + test { + name: "double_big_exact" + description: "Beyond exact range (2^53), but no loss of precision (2^55)." + expr: "int(double(36028797018963968))" + value { int64_value: 36028797018963968 } + } + test { + name: "double_big_precision" + description: "Beyond exact range (2^53), but loses precision (2^55 + 1)." + expr: "int(double(36028797018963969))" + value { int64_value: 36028797018963968 } + } + test { + name: "double_int_max_range" + description: "The double(2^63-1) cast produces a floating point value outside the int range" + expr: "int(9223372036854775807.0)" + eval_error { + errors: { message: "range" } + } + } + test { + name: "double_int_min_range" + description: "The double(-2^63) cast produces a floating point value outside the int range" + expr: "int(-9223372036854775808.0)" + eval_error { + errors: { message: "range" } + } + } + test { + name: "double_range" + expr: "int(1e99)" + eval_error { + errors: { message: "range" } + } + } + test { + name: "string" + expr: "int('987')" + value: { int64_value: 987 } + } + test { + name: "timestamp" + expr: "int(timestamp('2004-09-16T23:59:59Z'))" + value: { int64_value: 1095379199 } + } +} +section { + name: "string" + description: "Conversions to string." + test { + name: "int" + expr: "string(123)" + value: { string_value: "123" } + } + test { + name: "int_neg" + expr: "string(-456)" + value: { string_value: "-456" } + } + test { + name: "uint" + expr: "string(9876u)" + value: { string_value: "9876" } + } + test { + name: "double" + expr: "string(123.456)" + value: { string_value: "123.456" } + } + test { + name: "double_hard" + expr: "string(-4.5e-3)" + value: { string_value: "-0.0045" } + } + test { + name: "bytes" + expr: "string(b'abc')" + value: { string_value: "abc" } + } + test { + name: "bytes_unicode" + expr: "string(b'\\303\\277')" + value: { string_value: "ÿ" } + } + test { + name: "bytes_invalid" + expr: "string(b'\\000\\xff')" + eval_error { + errors { message: "invalid UTF-8" } + } + } +} +section { + name: "type" + description: "Type reflection tests." + test { + name: "bool" + expr: "type(true)" + value: { type_value: "bool" } + } + test { + name: "bool_denotation" + expr: "bool" + value: { type_value: "bool" } + } + test { + name: "dyn_no_denotation" + expr: "dyn" + disable_check: true + eval_error { + errors { message: "unknown variable" } + } + } + test { + name: "int" + expr: "type(0)" + value: { type_value: "int" } + } + test { + name: "int_denotation" + expr: "int" + value: { type_value: "int" } + } + test { + name: "eq_same" + expr: "type(true) == type(false)" + value: { bool_value: true } + } + test { + name: "uint" + expr: "type(64u)" + value: { type_value: "uint" } + } + test { + name: "uint_denotation" + expr: "uint" + value: { type_value: "uint" } + } + test { + name: "double" + expr: "type(3.14)" + value: { type_value: "double" } + } + test { + name: "double_denotation" + expr: "double" + value: { type_value: "double" } + } + test { + name: "null_type" + expr: "type(null)" + value: { type_value: "null_type" } + } + test { + name: "null_type_denotation" + expr: "null_type" + value: { type_value: "null_type" } + } + test { + name: "string" + expr: "type('foo')" + value: { type_value: "string" } + } + test { + name: "string_denotation" + expr: "string" + value: { type_value: "string" } + } + test { + name: "bytes" + expr: "type(b'\\xff')" + value: { type_value: "bytes" } + } + test { + name: "bytes_denotation" + expr: "bytes" + value: { type_value: "bytes" } + } + test { + name: "list" + expr: "type([1, 2, 3])" + value: { type_value: "list" } + } + test { + name: "list_denotation" + expr: "list" + value: { type_value: "list" } + } + test { + name: "lists_monomorphic" + expr: "type([1, 2, 3]) == type(['one', 'two', 'three'])" + value: { bool_value: true } + } + test { + name: "map" + expr: "type({4: 16})" + value: { type_value: "map" } + } + test { + name: "map_denotation" + expr: "map" + value: { type_value: "map" } + } + test { + name: "map_monomorphic" + expr: "type({'one': 1}) == type({1: 'one'})" + value: { bool_value: true } + } + test { + name: "eq_diff" + expr: "type(7) == type(7u)" + value: { bool_value: false } + } + test { + name: "neq_same" + expr: "type(0.0) != type(-0.0)" + value: { bool_value: false } + } + test { + name: "neq_diff" + expr: "type(0.0) != type(0)" + value: { bool_value: true } + } + test { + name: "meta" + expr: "type(type(7)) == type(type(7u))" + value: { bool_value: true } + } + test { + name: "type" + expr: "type(int)" + value: { type_value: "type" } + } + test { + name: "type_denotation" + expr: "type" + value: { type_value: "type" } + } + test { + name: "type_type" + expr: "type(type)" + value: { type_value: "type" } + } +} +section { + name: "uint" + description: "Conversions to uint." + test { + name: "int" + expr: "uint(1729)" + value: { uint64_value: 1729 } + } + test { + name: "int_max" + expr: "uint(9223372036854775807)" + value { uint64_value: 9223372036854775807 } + } + test { + name: "int_neg" + expr: "uint(-1)" + eval_error { + errors { message: "range" } + } + } + test { + name: "double" + expr: "uint(3.14159265)" + value: { uint64_value: 3 } + } + test { + name: "double_truncate" + expr: "uint(1.9)" + value: { uint64_value: 1 } + } + test { + name: "double_half" + expr: "uint(25.5)" + value: { uint64_value: 25 } + } + test { + name: "double_big_exact" + description: "Beyond exact range (2^53), but no loss of precision (2^55)." + expr: "uint(double(36028797018963968u))" + value { uint64_value: 36028797018963968 } + } + test { + name: "double_big_precision" + description: "Beyond exact range (2^53), but loses precision (2^55 + 1)." + expr: "uint(double(36028797018963969u))" + value { uint64_value: 36028797018963968 } + } + test { + name: "double_uint_max_range" + description: "The exact conversion of uint max as a double does not round trip." + expr: "int(18446744073709551615.0)" + eval_error { + errors: { message: "range" } + } + } + test { + name: "double_range_beyond_uint" + expr: "uint(6.022e23)" + eval_error { + errors { message: "range" } + } + } + test { + name: "string" + expr: "uint('300')" + value: { uint64_value: 300 } + } +} +section { + name: "bool" + description: "Conversions to bool" + test { + name: "string_1" + expr: "bool('1')" + value: { bool_value: true } + } + test { + name: "string_t" + expr: "bool('t')" + value: { bool_value: true } + } + test { + name: "string_true_lowercase" + expr: "bool('true')" + value: { bool_value: true } + } + test { + name: "string_true_uppercase" + expr: "bool('TRUE')" + value: { bool_value: true } + } + test { + name: "string_true_pascalcase" + expr: "bool('True')" + value: { bool_value: true } + } + test { + name: "string_0" + expr: "bool('0')" + value: { bool_value: false } + } + test { + name: "string_f" + expr: "bool('f')" + value: { bool_value: false } + } + test { + name: "string_false_lowercase" + expr: "bool('false')" + value: { bool_value: false } + } + test { + name: "string_false_uppercase" + expr: "bool('FALSE')" + value: { bool_value: false } + } + test { + name: "string_false_pascalcase" + expr: "bool('False')" + value: { bool_value: false } + } + test { + name: "string_true_badcase" + expr: "bool('TrUe')" + eval_error { + errors { message: "Type conversion error" } + } + } + test { + name: "string_false_badcase" + expr: "bool('FaLsE')" + eval_error { + errors { message: "Type conversion error" } + } + } +} +section { + name: "identity" + description: "Identity functions" + test { + name: "bool" + expr: "bool(true)" + value: { bool_value: true } + } + test { + name: "int" + expr: "int(1)" + value: { int64_value: 1 } + } + test { + name: "uint" + expr: "uint(1u)" + value: { uint64_value: 1 } + } + test { + name: "double" + expr: "double(5.5)" + value: { double_value: 5.5 } + } + test { + name: "string" + expr: "string('hello')" + value: { string_value: "hello" } + } + test { + name: "bytes" + expr: "bytes(b'abc')" + value: { bytes_value: "abc" } + } + test { + name: "duration" + expr: "duration(duration('100s')) == duration('100s')" + value: { bool_value: true } + } + test { + name: "timestamp" + expr: "timestamp(timestamp(1000000000)) == timestamp(1000000000)" + value: { bool_value: true } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/dynamic.textproto b/packages/cel-spec/src/testdata/textproto/dynamic.textproto new file mode 100644 index 00000000..d0e63a96 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/dynamic.textproto @@ -0,0 +1,2291 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "dynamic" +description: "Tests for 'dynamic' proto behavior, including JSON, wrapper, and Any messages." +section { + name: "int32" + description: "Tests for int32 conversion." + test { + name: "literal" + expr: "google.protobuf.Int32Value{value: -123}" + value { int64_value: -123 } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.Int32Value{value: -123}.value" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_zero" + expr: "google.protobuf.Int32Value{}" + value { int64_value: 0 } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.Int32Value" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.Int32Value] + { value: 2000000 } + } } } + } + value { int64_value: 2000000 } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int32_wrapper: 432}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_int32_wrapper { value: 432 } } + } + } + } + test { + name: "field_assign_proto2_zero" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int32_wrapper: 0}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_int32_wrapper { } } + } + } + } + test { + name: "field_assign_proto2_max" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int32_wrapper: 2147483647}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_int32_wrapper { value: 2147483647 } } + } + } + } + test { + name: "field_assign_proto2_min" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int32_wrapper: -2147483648}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_int32_wrapper { value: -2147483648 } } + } + } + } + test { + name: "field_assign_proto2_range" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int32_wrapper: 12345678900}" + eval_error { + errors { message: "range error" } + } + } + test { + name: "field_read_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int32_wrapper: 642}.single_int32_wrapper" + value { int64_value: 642 } + } + test { + name: "field_read_proto2_zero" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int32_wrapper: 0}.single_int32_wrapper" + value { int64_value: 0 } + } + test { + name: "field_read_proto2_unset" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_int32_wrapper" + value { null_value: NULL_VALUE } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int32_wrapper: -975}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_int32_wrapper { value: -975 } } + } + } + } + test { + name: "field_assign_proto3_zero" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int32_wrapper: 0}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_int32_wrapper { } } + } + } + } + test { + name: "field_assign_proto3_max" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int32_wrapper: 2147483647}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_int32_wrapper { value: 2147483647 } } + } + } + } + test { + name: "field_assign_proto3_min" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int32_wrapper: -2147483648}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_int32_wrapper { value: -2147483648 } } + } + } + } + test { + name: "field_assign_proto3_range" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int32_wrapper: -998877665544332211}" + eval_error { + errors { message: "range error" } + } + } + test { + name: "field_read_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int32_wrapper: 642}.single_int32_wrapper" + value { int64_value: 642 } + } + test { + name: "field_read_proto3_zero" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int32_wrapper: 0}.single_int32_wrapper" + value { int64_value: 0 } + } + test { + name: "field_read_proto3_unset" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_int32_wrapper" + value { null_value: NULL_VALUE } + } +} +section { + name: "int64" + description: "Tests for int64 conversion." + test { + name: "literal" + expr: "google.protobuf.Int64Value{value: -123}" + value { int64_value: -123 } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.Int64Value{value: -123}.value" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_zero" + expr: "google.protobuf.Int64Value{}" + value { int64_value: 0 } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.Int64Value" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.Int64Value] + { value: 2000000 } + } } } + } + value { int64_value: 2000000 } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int64_wrapper: 432}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_int64_wrapper { value: 432 } } + } + } + } + test { + name: "field_assign_proto2_zero" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int64_wrapper: 0}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_int64_wrapper { } } + } + } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int64_wrapper: -975}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_int64_wrapper { value: -975 } } + } + } + } + test { + name: "field_assign_proto3_zero" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int64_wrapper: 0}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_int64_wrapper { } } + } + } + } +} +section { + name: "uint32" + description: "Tests for uint32 conversion." + test { + name: "literal" + expr: "google.protobuf.UInt32Value{value: 123u}" + value { uint64_value: 123 } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.UInt32Value{value: 123u}.value" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_zero" + expr: "google.protobuf.UInt32Value{}" + value { uint64_value: 0 } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.UInt32Value" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.UInt32Value] + { value: 2000000 } + } } } + } + value { uint64_value: 2000000 } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_uint32_wrapper: 432u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_uint32_wrapper { value: 432 } } + } + } + } + test { + name: "field_assign_proto2_zero" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_uint32_wrapper: 0u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_uint32_wrapper { } } + } + } + } + test { + name: "field_assign_proto2_max" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_uint32_wrapper: 4294967295u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_uint32_wrapper { value: 4294967295} } + } + } + } + test { + name: "field_assign_proto2_range" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_uint32_wrapper: 6111222333u}" + eval_error { + errors { message: "range error" } + } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_uint32_wrapper: 975u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_uint32_wrapper { value: 975 } } + } + } + } + test { + name: "field_assign_proto3_zero" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_uint32_wrapper: 0u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_uint32_wrapper { } } + } + } + } + test { + name: "field_assign_proto3_max" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_uint32_wrapper: 4294967295u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_uint32_wrapper { value: 4294967295 } } + } + } + } + test { + name: "field_assign_proto3_range" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_uint32_wrapper: 6111222333u}" + eval_error { + errors { message: "range error" } + } + } + test { + name: "field_read_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_uint32_wrapper: 258u}.single_uint32_wrapper" + value { uint64_value: 258 } + } + test { + name: "field_read_proto2_zero" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_uint32_wrapper: 0u}.single_uint32_wrapper" + value { uint64_value: 0 } + } + test { + name: "field_read_proto2_unset" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_uint32_wrapper" + value { null_value: NULL_VALUE } + } +} +section { + name: "uint64" + description: "Tests for uint64 conversion." + test { + name: "literal" + expr: "google.protobuf.UInt64Value{value: 123u}" + value { uint64_value: 123 } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.UInt64Value{value: 123u}.value" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_zero" + expr: "google.protobuf.UInt64Value{}" + value { uint64_value: 0 } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.UInt64Value" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.UInt64Value] + { value: 2000000 } + } } } + } + value { uint64_value: 2000000 } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_uint64_wrapper: 432u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_uint64_wrapper { value: 432 } } + } + } + } + test { + name: "field_assign_proto2_zero" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_uint64_wrapper: 0u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_uint64_wrapper { } } + } + } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_uint64_wrapper: 975u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_uint64_wrapper { value: 975 } } + } + } + } + test { + name: "field_assign_proto3_zero" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_uint64_wrapper: 0u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_uint64_wrapper { } } + } + } + } + test { + name: "field_read_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_uint64_wrapper: 5123123123u}.single_uint64_wrapper" + value { uint64_value: 5123123123 } + } + test { + name: "field_read_proto2_zero" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_uint64_wrapper: 0u}.single_uint64_wrapper" + value { uint64_value: 0 } + } + test { + name: "field_read_proto2_unset" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_uint64_wrapper" + value { null_value: NULL_VALUE } + } +} +section { + name: "float" + description: "Tests for float conversion." + test { + name: "literal" + expr: "google.protobuf.FloatValue{value: -1.5e3}" + value { double_value: -1500.0 } + } + test { + name: "literal_not_double" + description: "Use a number with no exact representation to make sure we actually narrow to a float." + expr: "google.protobuf.FloatValue{value: 1.333} == 1.333" + value { bool_value: false } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.FloatValue{value: 3.1416}.value" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_zero" + expr: "google.protobuf.FloatValue{}" + value { double_value: 0.0 } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.FloatValue" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.FloatValue] + { value: -1.25e6 } + } } } + } + value { double_value: -1250000.0 } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_float_wrapper: 86.75}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_float_wrapper { value: 86.75 } } + } + } + } + test { + name: "field_assign_proto2_zero" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_float_wrapper: 0.0}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_float_wrapper { } } + } + } + } + test { + name: "field_assign_proto2_subnorm" + description: "Subnormal single floats range from ~1e-38 to ~1e-45." + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_float_wrapper: 1e-40}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_float_wrapper { value: 1e-40 } } + } + } + } + test { + name: "field_assign_proto2_round_to_zero" + description: "Subnormal single floats range from ~1e-38 to ~1e-45." + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_float_wrapper: 1e-50}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_float_wrapper { } } + } + } + } + test { + name: "field_assign_proto2_range" + description: "Single float max is about 3.4e38" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_float_wrapper: 1.4e55}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_float_wrapper { value: inf } } + } + } + } + test { + name: "field_read_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_float_wrapper: -12.375}.single_float_wrapper" + value { double_value: -12.375 } + } + test { + name: "field_read_proto2_zero" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_float_wrapper: 0.0}.single_float_wrapper" + value { double_value: 0.0 } + } + test { + name: "field_read_proto2_unset" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_float_wrapper" + value { null_value: NULL_VALUE } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_float_wrapper: -9.75}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_float_wrapper { value: -9.75 } } + } + } + } + test { + name: "field_assign_proto3_zero" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_float_wrapper: 0.0}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_float_wrapper { } } + } + } + } + test { + name: "field_assign_proto2_subnorm" + description: "Subnormal single floats range from ~1e-38 to ~1e-45." + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_float_wrapper: 1e-40}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_float_wrapper { value: 1e-40 } } + } + } + } + test { + name: "field_assign_proto3_round_to_zero" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_float_wrapper: -9.9e-100}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_float_wrapper { value: -0 } } + } + } + } + test { + name: "field_assign_proto3_range" + description: "Single float min is about -3.4e38" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_float_wrapper: -9.9e100}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_float_wrapper { value: -inf } } + } + } + } + test { + name: "field_read_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_float_wrapper: 64.25}.single_float_wrapper" + value { double_value: 64.25 } + } + test { + name: "field_read_proto3_zero" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_float_wrapper: 0.0}.single_float_wrapper" + value { double_value: 0.0 } + } + test { + name: "field_read_proto3_unset" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_float_wrapper" + value { null_value: NULL_VALUE } + } +} +section { + name: "double" + description: "Tests for double conversion." + test { + name: "literal" + expr: "google.protobuf.DoubleValue{value: -1.5e3}" + value { double_value: -1500.0 } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.DoubleValue{value: 3.1416}.value" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_zero" + expr: "google.protobuf.DoubleValue{}" + value { double_value: 0.0 } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.DoubleValue" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.DoubleValue] + { value: -1.25e6 } + } } } + } + value { double_value: -1250000.0 } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_double_wrapper: 86.75}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_double_wrapper { value: 86.75 } } + } + } + } + test { + name: "field_assign_proto2_zero" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_double_wrapper: 0.0}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_double_wrapper { } } + } + } + } + test { + name: "field_assign_proto2_range" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_double_wrapper: 1.4e55}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_double_wrapper { value: 1.4e55 } } + } + } + } + test { + name: "field_read_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_double_wrapper: -12.375}.single_double_wrapper" + value { double_value: -12.375 } + } + test { + name: "field_read_proto2_zero" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int32_wrapper: 0}.single_int32_wrapper" + value { int64_value: 0 } + } + test { + name: "field_read_proto2_unset" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_double_wrapper" + value { null_value: NULL_VALUE } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_double_wrapper: -9.75}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_double_wrapper { value: -9.75 } } + } + } + } + test { + name: "field_assign_proto3_zero" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_double_wrapper: 0.0}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_double_wrapper { } } + } + } + } + test { + name: "field_assign_proto3_range" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_double_wrapper: -9.9e100}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_double_wrapper { value: -9.9e100 } } + } + } + } + test { + name: "field_read_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_double_wrapper: 64.25}.single_double_wrapper" + value { double_value: 64.25 } + } + test { + name: "field_read_proto3_zero" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_double_wrapper: 0.0}.single_double_wrapper" + value { double_value: 0.0 } + } + test { + name: "field_read_proto3_unset" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_double_wrapper" + value { null_value: NULL_VALUE } + } +} +section { + name: "bool" + description: "Tests for bool conversion." + test { + name: "literal" + expr: "google.protobuf.BoolValue{value: true}" + value { bool_value: true } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.BoolValue{value: true}.value" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_empty" + expr: "google.protobuf.BoolValue{}" + value { bool_value: false } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.BoolValue" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.BoolValue] + { value: true } + } } } + } + value { bool_value: true } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_bool_wrapper: true}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_bool_wrapper { value: true } } + } + } + } + test { + name: "field_assign_proto2_false" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_bool_wrapper: false}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_bool_wrapper { } } + } + } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_bool_wrapper: true}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_bool_wrapper { value: true } } + } + } + } + test { + name: "field_assign_proto3_false" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_bool_wrapper: false}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_bool_wrapper { } } + } + } + } +} +section { + name: "string" + description: "Tests for string conversion." + test { + name: "literal" + expr: "google.protobuf.StringValue{value: 'foo'}" + value { string_value: "foo" } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.StringValue{value: 'foo'}.value" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_empty" + expr: "google.protobuf.StringValue{}" + value { string_value: "" } + } + test { + name: "literal_unicode" + expr: "google.protobuf.StringValue{value: 'flambé'}" + value { string_value: "flambé" } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.StringValue" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.StringValue] + { value: "bar" } + } } } + } + value { string_value: "bar" } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_string_wrapper: 'baz'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_string_wrapper { value: "baz" } } + } + } + } + test { + name: "field_assign_proto2_empty" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_string_wrapper: ''}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_string_wrapper { } } + } + } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_string_wrapper: 'bletch'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_string_wrapper { value: "bletch" } } + } + } + } + test { + name: "field_assign_proto3_empty" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_string_wrapper: ''}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_string_wrapper { } } + } + } + } +} +section { + name: "bytes" + description: "Tests for bytes conversion." + test { + name: "literal" + expr: "google.protobuf.BytesValue{value: b'foo\\123'}" + value { bytes_value: "foo\123" } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.BytesValue{value: b'foo'}.value" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_empty" + expr: "google.protobuf.BytesValue{}" + value { bytes_value: "" } + } + test { + name: "literal_unicode" + expr: "google.protobuf.BytesValue{value: b'flambé'}" + value { bytes_value: "flambé" } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.BytesValue" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.BytesValue] + { value: "bar" } + } } } + } + value { bytes_value: "bar" } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_bytes_wrapper: b'baz'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_bytes_wrapper { value: "baz" } } + } + } + } + test { + name: "field_assign_proto2_empty" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_bytes_wrapper: b''}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_bytes_wrapper { } } + } + } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_bytes_wrapper: b'bletch'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_bytes_wrapper { value: "bletch" } } + } + } + } + test { + name: "field_assign_proto3_empty" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_bytes_wrapper: b''}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_bytes_wrapper { } } + } + } + } +} +section { + name: "list" + description: "Tests for list conversion." + test { + name: "literal" + expr: "google.protobuf.ListValue{values: [3.0, 'foo', null]}" + value { + list_value { + values { double_value: 3.0 } + values { string_value: "foo" } + values { null_value: NULL_VALUE } + } + } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.ListValue{values: [3.0, 'foo', null]}.values" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_empty" + expr: "google.protobuf.ListValue{values: []}" + value { list_value { } } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.ListValue" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.ListValue] + { + values { string_value: "bar" } + values { list_value { + values { string_value: "a" } + values { string_value: "b" } + } } + } + } } } + } + value { + list_value { + values { string_value: "bar" } + values { + list_value { + values { string_value: "a" } + values { string_value: "b" } + } + } + } + } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{list_value: [1.0, 'one']}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { list_value { + values: { number_value: 1.0 } + values: { string_value: "one" } + } } + } + } + } + test { + name: "field_assign_proto2_empty" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{list_value: []}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { list_value { } } + } + } + } + test { + name: "field_read_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{list_value: [1.0, 'one']}.list_value" + value { + list_value { + values { double_value: 1.0 } + values { string_value: "one" } + } + } + } + test { + name: "field_read_proto2_empty" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{list_value: []}.list_value" + value { list_value { } } + } + test { + name: "field_read_proto2_unset" + description: "Not a wrapper type, so doesn't convert to null." + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.list_value" + value { list_value { } } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{list_value: [1.0, 'one']}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { list_value { + values: { number_value: 1.0 } + values: { string_value: "one" } + } } + } + } + } + test { + name: "field_assign_proto3_empty" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{list_value: []}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { list_value { } } + } + } + } + test { + name: "field_read_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{list_value: [1.0, 'one']}.list_value" + value { + list_value { + values { double_value: 1.0 } + values { string_value: "one" } + } + } + } + test { + name: "field_read_proto3_empty" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{list_value: []}.list_value" + value { list_value { } } + } + test { + name: "field_read_proto3_unset" + description: "Not a wrapper type, so doesn't convert to null." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.list_value" + value { list_value { } } + } +} +section { + name: "struct" + description: "Tests for struct conversion." + test { + name: "literal" + expr: "google.protobuf.Struct{fields: {'uno': 1.0, 'dos': 2.0}}" + value { + map_value { + entries { + key { string_value: "uno" } + value { double_value: 1.0 } + } + entries { + key { string_value: "dos" } + value { double_value: 2.0 } + } + } + } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.Struct{fields: {'uno': 1.0, 'dos': 2.0}}.fields" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_empty" + expr: "google.protobuf.Struct{fields: {}}" + value { map_value { } } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.Struct" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.Struct] + { + fields { + key: "first" + value { string_value: "Abraham" } + } + fields { + key: "last" + value { string_value: "Lincoln" } + } + } + } } } + } + value { + map_value { + entries { + key { string_value: "first" } + value { string_value: "Abraham" } + } + entries { + key { string_value: "last" } + value { string_value: "Lincoln" } + } + } + } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_struct: {'un': 1.0, 'deux': 2.0}}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_struct { + fields { + key: "un" + value { number_value: 1.0 } + } + fields { + key: "deux" + value { number_value: 2.0 } + } + } } + } + } + } + test { + name: "field_assign_proto2_empty" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_struct: {}}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_struct { } } + } + } + } + test { + name: "field_assign_proto2_bad" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_struct: {1: 'uno'}}" + disable_check: true + eval_error { + errors { message: "bad key type" } + } + } + test { + name: "field_read_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_struct: {'one': 1.0}}.single_struct" + value { + map_value { + entries { + key { string_value: "one" } + value { double_value: 1.0 } + } + } + } + } + test { + name: "field_read_proto2_empty" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_struct: {}}.single_struct" + value { map_value { } } + } + test { + name: "field_read_proto2_unset" + description: "Not a wrapper type, so doesn't convert to null." + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_struct" + value { map_value { } } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_struct: {'un': 1.0, 'deux': 2.0}}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_struct { + fields { + key: "un" + value { number_value: 1.0 } + } + fields { + key: "deux" + value { number_value: 2.0 } + } + } } + } + } + } + test { + name: "field_assign_proto3_empty" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_struct: {}}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_struct { } } + } + } + } + test { + name: "field_assign_proto3_bad" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_struct: {1: 'uno'}}" + disable_check: true + eval_error { + errors { message: "bad key type" } + } + } + test { + name: "field_read_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_struct: {'one': 1.0}}.single_struct" + value { + map_value { + entries { + key { string_value: "one" } + value { double_value: 1.0 } + } + } + } + } + test { + name: "field_read_proto3_empty" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_struct: {}}.single_struct" + value { map_value { } } + } + test { + name: "field_read_proto3_unset" + description: "Not a wrapper type, so doesn't convert to null." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_struct" + value { map_value { } } + } +} +section { + name: "value_null" + description: "Tests for null conversions." + test { + name: "literal" + container: "google.protobuf" + expr: "Value{null_value: NullValue.NULL_VALUE}" + value { null_value: NULL_VALUE } + } + test { + name: "literal_no_field_access" + container: "google.protobuf" + expr: "Value{null_value: NullValue.NULL_VALUE}.null_value" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_unset" + expr: "google.protobuf.Value{}" + value { null_value: NULL_VALUE } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.Value" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.Value] + { null_value: NULL_VALUE } + } } } + } + value { null_value: NULL_VALUE } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: null}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_value { null_value: NULL_VALUE } } + } + } + } + test { + name: "field_read_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: null}.single_value" + value { null_value: NULL_VALUE } + } + test { + name: "field_read_proto2_unset" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_value" + value { null_value: NULL_VALUE } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: null}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_value { null_value: NULL_VALUE } } + } + } + } + test { + name: "field_read_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: null}.single_value" + value { null_value: NULL_VALUE } + } + test { + name: "field_read_proto3_unset" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_value" + value { null_value: NULL_VALUE } + } +} +section { + name: "value_number" + description: "Tests for number conversions in Value." + test { + name: "literal" + expr: "google.protobuf.Value{number_value: 12.5}" + value { double_value: 12.5 } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.Value{number_value: 12.5}.number_value" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_zero" + expr: "google.protobuf.Value{number_value: 0.0}" + value { double_value: 0.0 } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.Value" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.Value] + { number_value: -26.375 } + } } } + } + value { double_value: -26.375 } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: 7e23}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_value { number_value: 7e23 } } + } + } + } + test { + name: "field_assign_proto2_zero" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: 0.0}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_value { number_value: 0.0 } } + } + } + } + test { + name: "field_read_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: 7e23}.single_value" + value { double_value: 7e23 } + } + test { + name: "field_read_proto2_zero" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: 0.0}.single_value" + value { double_value: 0.0 } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: 7e23}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_value { number_value: 7e23 } } + } + } + } + test { + name: "field_assign_proto3_zero" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: 0.0}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_value { number_value: 0.0 } } + } + } + } + test { + name: "field_read_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: 7e23}.single_value" + value { double_value: 7e23 } + } + test { + name: "field_read_proto3_zero" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: 0.0}.single_value" + value { double_value: 0.0 } + } +} +section { + name: "value_string" + description: "Tests for string conversions in Value." + test { + name: "literal" + expr: "google.protobuf.Value{string_value: 'foo'}" + value { string_value: "foo" } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.Value{string_value: 'foo'}.string_value" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_empty" + expr: "google.protobuf.Value{string_value: ''}" + value { string_value: "" } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.Value" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.Value] + { string_value: "bar" } + } } } + } + value { string_value: "bar" } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: 'baz'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_value { string_value: "baz" } } + } + } + } + test { + name: "field_assign_proto2_empty" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: ''}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_value { string_value: "" } } + } + } + } + test { + name: "field_read_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: 'bletch'}.single_value" + value { string_value: "bletch" } + } + test { + name: "field_read_proto2_zero" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: ''}.single_value" + value { string_value: "" } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: 'baz'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_value { string_value: "baz" } } + } + } + } + test { + name: "field_assign_proto3_empty" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: ''}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_value { string_value: "" } } + } + } + } + test { + name: "field_read_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: 'bletch'}.single_value" + value { string_value: "bletch" } + } + test { + name: "field_read_proto3_zero" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: ''}.single_value" + value { string_value: "" } + } +} +section { + name: "value_bool" + description: "Tests for boolean conversions in Value." + test { + name: "literal" + expr: "google.protobuf.Value{bool_value: true}" + value { bool_value: true } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.Value{bool_value: true}.bool_value" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_false" + expr: "google.protobuf.Value{bool_value: false}" + value { bool_value: false } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.Value" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.Value] + { bool_value: true } + } } } + } + value { bool_value: true } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: true}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_value { bool_value: true } } + } + } + } + test { + name: "field_assign_proto2_false" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: false}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_value { bool_value: false } } + } + } + } + test { + name: "field_read_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: true}.single_value" + value { bool_value: true } + } + test { + name: "field_read_proto2_false" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: false}.single_value" + value { bool_value: false } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: true}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_value { bool_value: true } } + } + } + } + test { + name: "field_assign_proto3_false" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: false}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_value { bool_value: false } } + } + } + } + test { + name: "field_read_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: true}.single_value" + value { bool_value: true } + } + test { + name: "field_read_proto3_false" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: false}.single_value" + value { bool_value: false } + } +} +section { + name: "value_struct" + description: "Tests for struct conversions in Value." + test { + name: "literal" + expr: "google.protobuf.Value{struct_value: {'a': 1.0, 'b': 'two'}}" + value { + map_value { + entries { + key { string_value: "a" } + value { double_value: 1.0 } + } + entries { + key { string_value: "b" } + value { string_value: "two" } + } + } + } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.Value{struct_value: {'a': 1.0, 'b': 'two'}}.struct_value" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_empty" + expr: "google.protobuf.Value{struct_value: {}}" + value { map_value: { } } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.Value" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.Value] + { struct_value { + fields { + key: "x" + value { null_value: NULL_VALUE } + } + fields { + key: "y" + value { bool_value: false } + } + } } + } } } + } + value { + map_value { + entries { + key { string_value: "x" } + value { null_value: NULL_VALUE } + } + entries { + key { string_value: "y" } + value { bool_value: false } + } + } + } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: {'un': 1.0, 'deux': 2.0}}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_value { struct_value { + fields { + key: "un" + value { number_value: 1.0 } + } + fields { + key: "deux" + value { number_value: 2.0 } + } + } } } + } + } + } + test { + name: "field_assign_proto2_empty" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: {}}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_value { struct_value: { } } } + } + } + } + test { + name: "field_read_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: {'i': true}}.single_value" + value { + map_value { + entries { + key { string_value: "i" } + value { bool_value: true } + } + } + } + } + test { + name: "field_read_proto2_empty" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: {}}.single_value" + value { map_value: { } } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: {'un': 1.0, 'deux': 2.0}}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_value { struct_value { + fields { + key: "un" + value { number_value: 1.0 } + } + fields { + key: "deux" + value { number_value: 2.0 } + } + } } } + } + } + } + test { + name: "field_assign_proto3_empty" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: {}}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_value { struct_value: { } } } + } + } + } + test { + name: "field_read_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: {'i': true}}.single_value" + value { + map_value { + entries { + key { string_value: "i" } + value { bool_value: true } + } + } + } + } + test { + name: "field_read_proto3_empty" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: {}}.single_value" + value { map_value: { } } + } +} +section { + name: "value_list" + description: "Tests for list conversions in Value." + test { + name: "literal" + expr: "google.protobuf.Value{list_value: ['a', 3.0]}" + value { + list_value { + values { string_value: "a" } + values { double_value: 3.0 } + } + } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.Value{list_value: []}.list_value" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_empty" + expr: "google.protobuf.Value{list_value: []}" + value { list_value: { } } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.Value" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.Value] + { list_value { + values { number_value: 1.0 } + values { bool_value: true } + values { string_value: "hi" } + } } + } } } + } + value { + list_value { + values { double_value: 1.0 } + values { bool_value: true } + values { string_value: "hi" } + } + } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: ['un', 1.0]}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_value { list_value { + values { string_value: "un" } + values { number_value: 1.0 } + } } } + } + } + } + test { + name: "field_assign_proto2_empty" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: []}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_value { list_value: { } } } + } + } + } + test { + name: "field_read_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: ['i', true]}.single_value" + value { + list_value { + values { string_value: "i" } + values { bool_value: true } + } + } + } + test { + name: "field_read_proto2_empty" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: []}.single_value" + value { list_value: { } } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: ['un', 1.0]}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_value { list_value { + values { string_value: "un" } + values { number_value: 1.0 } + } } } + } + } + } + test { + name: "field_assign_proto3_empty" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: []}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_value { list_value: { } } } + } + } + } + test { + name: "field_read_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: ['i', true]}.single_value" + value { + list_value { + values { string_value: "i" } + values { bool_value: true } + } + } + } + test { + name: "field_read_proto3_empty" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: []}.single_value" + value { list_value: { } } + } +} +section { + name: "any" + description: "Tests for Any conversion." + test { + name: "literal" + expr: "google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\x08\\x96\\x01'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_int32: 150 } + } + } + } + test { + name: "literal_no_field_access" + expr: "google.protobuf.Any{type_url: 'type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes', value: b'\\x08\\x96\\x01'}.type_url" + disable_check: true + eval_error { + errors { message: "no_matching_overload" } + } + } + test { + name: "literal_empty" + expr: "google.protobuf.Any{}" + eval_error { + errors { message: "conversion" } + } + } + test { + name: "var" + expr: "x" + type_env { + name: "x" + ident { type { message_type: "google.protobuf.Any" } } + } + bindings { + key: "x" + value { value { object_value { + [type.googleapis.com/google.protobuf.Any] + { + type_url: "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes" + value: "\x08\x96\x01" + } + } } } + } + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_int32: 150 } + } + } + } + test { + name: "field_assign_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_any: TestAllTypes{single_int32: 150}}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { + single_any { + type_url: "type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes" + value: "\x08\x96\x01" + } + } + } + } + } + test { + name: "field_read_proto2" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_any: TestAllTypes{single_int32: 150}}.single_any" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] + { single_int32: 150 } + } + } + } + test { + name: "field_assign_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: TestAllTypes{single_int32: 150}}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { + single_any { + type_url: "type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes" + value: "\x08\x96\x01" + } + } + } + } + } + test { + name: "field_read_proto3" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: TestAllTypes{single_int32: 150}}.single_any" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] + { single_int32: 150 } + } + } + } +} +section { + name: "complex" + description: "Tests combining various dynamic conversions." + test { + name: "any_list_map" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: [{'almost': 'done'}]}.single_any" + value { + list_value { + values { + map_value { + entries { + key { string_value: "almost" } + value { string_value: "done" } + } + } + } + } + } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/encoders_ext.textproto b/packages/cel-spec/src/testdata/textproto/encoders_ext.textproto new file mode 100644 index 00000000..07cf11d9 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/encoders_ext.textproto @@ -0,0 +1,44 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "encoders_ext" +description: "Tests for the encoders extension library." +section: { + name: "encode" + test: { + name: "hello" + expr: "base64.encode(b'hello')" + value: { + string_value: "aGVsbG8=" + } + } +} + +section: { + name: "decode" + test: { + name: "hello" + expr: "base64.decode('aGVsbG8=')" + value: { + bytes_value: "hello" + } + } + test: { + name: "hello_without_padding" + expr: "base64.decode('aGVsbG8')" + value: { + bytes_value: "hello" + } + } +} + +section: { + name: "round_trip" + test: { + name: "hello" + expr: "base64.decode(base64.encode(b'Hello World!'))" + value: { + bytes_value: "Hello World!" + } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/enums.textproto b/packages/cel-spec/src/testdata/textproto/enums.textproto new file mode 100644 index 00000000..558e9290 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/enums.textproto @@ -0,0 +1,933 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "enums" +description: "Tests for enum types." +section { + name: "legacy_proto2" + description: "Legacy semantics where all enums are ints, proto2." + test { + name: "literal_global" + container: "cel.expr.conformance.proto2" + expr: "GlobalEnum.GAZ" + value { int64_value: 2 } + } + test { + name: "literal_nested" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes.NestedEnum.BAR" + value { int64_value: 1 } + } + test { + name: "literal_zero" + container: "cel.expr.conformance.proto2" + expr: "GlobalEnum.GOO" + value { int64_value: 0 } + } + test { + name: "comparison" + container: "cel.expr.conformance.proto2" + expr: "GlobalEnum.GAR == 1" + value { bool_value: true } + } + test { + name: "arithmetic" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes.NestedEnum.BAR + 3" + value { int64_value: 4 } + } + test { + name: "type_global" + container: "cel.expr.conformance.proto2" + expr: "type(GlobalEnum.GOO)" + value { type_value: "int" } + } + test { + name: "type_nested" + container: "cel.expr.conformance.proto2" + expr: "type(TestAllTypes.NestedEnum.BAZ)" + value { type_value: "int" } + } + test { + name: "select_default" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.standalone_enum" + value { int64_value: 0 } + } + test { + name: "field_type" + container: "cel.expr.conformance.proto2" + expr: "type(TestAllTypes{}.standalone_enum)" + value { type_value: "int" } + } + test { + name: "assign_standalone_name" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.BAZ}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + standalone_enum: BAZ + } + } + } + } + test { + name: "assign_standalone_int" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{standalone_enum: 1}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + standalone_enum: BAR + } + } + } + } + test { + name: "assign_standalone_int_too_big" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{standalone_enum: 5000000000}" + eval_error { + errors { + message: "range" + } + } + } + test { + name: "assign_standalone_int_too_neg" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{standalone_enum: -7000000000}" + eval_error { + errors { + message: "range" + } + } + } + test { + name: "access_repeated_enum" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.repeated_nested_enum" + value { + list_value {} + } + } + test { + name: "assign_repeated_enum" + container: "cel.expr.conformance.proto2" + expr: + "TestAllTypes{" + " repeated_nested_enum: [" + " TestAllTypes.NestedEnum.FOO," + " TestAllTypes.NestedEnum.BAR]}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + repeated_nested_enum: FOO + repeated_nested_enum: BAR + } + } + } + } + test { + name: "list_enum_as_list_int" + container: "cel.expr.conformance.proto2" + expr: + "0 in " + "TestAllTypes{" + " repeated_nested_enum: [" + " TestAllTypes.NestedEnum.FOO," + " TestAllTypes.NestedEnum.BAR]}" + ".repeated_nested_enum" + value: { bool_value: true } + } + test { + name: "enum_as_int" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.FOO}.standalone_enum in [0]" + value: { bool_value: true } + } +} +section { + name: "legacy_proto3" + description: "Legacy semantics where all enums are ints, proto3" + test { + name: "literal_global" + container: "cel.expr.conformance.proto3" + expr: "GlobalEnum.GAZ" + value { int64_value: 2 } + } + test { + name: "literal_nested" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes.NestedEnum.BAR" + value { int64_value: 1 } + } + test { + name: "literal_zero" + container: "cel.expr.conformance.proto3" + expr: "GlobalEnum.GOO" + value { int64_value: 0 } + } + test { + name: "comparison" + container: "cel.expr.conformance.proto3" + expr: "GlobalEnum.GAR == 1" + value { bool_value: true } + } + test { + name: "arithmetic" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes.NestedEnum.BAR + 3" + value { int64_value: 4 } + } + test { + name: "type_global" + container: "cel.expr.conformance.proto3" + expr: "type(GlobalEnum.GOO)" + value { type_value: "int" } + } + test { + name: "type_nested" + container: "cel.expr.conformance.proto3" + expr: "type(TestAllTypes.NestedEnum.BAZ)" + value { type_value: "int" } + } + test { + name: "select_default" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.standalone_enum" + value { int64_value: 0 } + } + test { + name: "select" + container: "cel.expr.conformance.proto3" + expr: "x.standalone_enum" + type_env { + name: "x" + ident { + type { message_type: "cel.expr.conformance.proto3.TestAllTypes" } + } + } + bindings { + key: "x" + value { + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + standalone_enum: 2 + } + } + } + } + } + value { int64_value: 2 } + } + test { + name: "select_big" + container: "cel.expr.conformance.proto3" + expr: "x.standalone_enum" + type_env { + name: "x" + ident { + type { message_type: "cel.expr.conformance.proto3.TestAllTypes" } + } + } + bindings { + key: "x" + value { + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + standalone_enum: 108 + } + } + } + } + } + value { int64_value: 108 } + } + test { + name: "select_neg" + container: "cel.expr.conformance.proto3" + expr: "x.standalone_enum" + type_env { + name: "x" + ident { + type { message_type: "cel.expr.conformance.proto3.TestAllTypes" } + } + } + bindings { + key: "x" + value { + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + standalone_enum: -3 + } + } + } + } + } + value { int64_value: -3 } + } + test { + name: "field_type" + container: "cel.expr.conformance.proto3" + expr: "type(TestAllTypes{}.standalone_enum)" + value { type_value: "int" } + } + test { + name: "assign_standalone_name" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.BAZ}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + standalone_enum: BAZ + } + } + } + } + test { + name: "assign_standalone_int" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{standalone_enum: 1}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + standalone_enum: BAR + } + } + } + } + test { + name: "assign_standalone_int_big" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{standalone_enum: 99}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + standalone_enum: 99 + } + } + } + } + test { + name: "assign_standalone_int_neg" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{standalone_enum: -1}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + standalone_enum: -1 + } + } + } + } + test { + name: "assign_standalone_int_too_big" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{standalone_enum: 5000000000}" + eval_error { + errors { + message: "range" + } + } + } + test { + name: "assign_standalone_int_too_neg" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{standalone_enum: -7000000000}" + eval_error { + errors { + message: "range" + } + } + } + test { + name: "access_repeated_enum" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.repeated_nested_enum" + value { + list_value {} + } + } + test { + name: "assign_repeated_enum" + container: "cel.expr.conformance.proto2" + expr: + "TestAllTypes{" + " repeated_nested_enum: [" + " TestAllTypes.NestedEnum.FOO," + " TestAllTypes.NestedEnum.BAR]}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + repeated_nested_enum: FOO + repeated_nested_enum: BAR + } + } + } + } + test { + name: "list_enum_as_list_int" + container: "cel.expr.conformance.proto2" + expr: + "0 in " + "TestAllTypes{" + " repeated_nested_enum: [" + " TestAllTypes.NestedEnum.FOO," + " TestAllTypes.NestedEnum.BAR]}" + ".repeated_nested_enum" + value: { bool_value: true } + } + test { + name: "enum_as_int" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.FOO}.standalone_enum in [0]" + value: { bool_value: true } + } +} +section { + name: "strong_proto2" + description: "String semantics where enums are distinct types, proto2." + test { + name: "literal_global" + container: "cel.expr.conformance.proto2" + expr: "GlobalEnum.GAZ" + value { + enum_value { + type: "cel.expr.conformance.proto2.GlobalEnum" + value: 2 + } + } + } + test { + name: "literal_nested" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes.NestedEnum.BAR" + value { + enum_value { + type: "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" + value: 1 + } + } + } + test { + name: "literal_zero" + container: "cel.expr.conformance.proto2" + expr: "GlobalEnum.GOO" + value { + enum_value { + type: "cel.expr.conformance.proto2.GlobalEnum" + value: 0 + } + } + } + test { + name: "comparison_true" + container: "cel.expr.conformance.proto2" + expr: "GlobalEnum.GAR == GlobalEnum.GAR" + value { bool_value: true } + } + test { + name: "comparison_false" + container: "cel.expr.conformance.proto2" + expr: "GlobalEnum.GAR == GlobalEnum.GAZ" + value { bool_value: false } + } + test { + name: "type_global" + container: "cel.expr.conformance.proto2" + expr: "type(GlobalEnum.GOO)" + value { type_value: "cel.expr.conformance.proto2.GlobalEnum" } + } + test { + name: "type_nested" + container: "cel.expr.conformance.proto2" + expr: "type(TestAllTypes.NestedEnum.BAZ)" + value { + type_value: "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" + } + } + test { + name: "select_default" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.standalone_enum" + value { + enum_value { + type: "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" + value: 0 + } + } + } + test { + name: "field_type" + container: "cel.expr.conformance.proto2" + expr: "type(TestAllTypes{}.standalone_enum)" + value { + type_value: "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" + } + } + test { + name: "assign_standalone_name" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.BAZ}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + standalone_enum: BAZ + } + } + } + } + test { + name: "assign_standalone_int" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum(1)}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + standalone_enum: BAR + } + } + } + } + test { + name: "convert_symbol_to_int" + container: "cel.expr.conformance.proto2" + expr: "int(GlobalEnum.GAZ)" + value { int64_value: 2 } + } + test { + name: "convert_unnamed_to_int" + description: "Disable check - missing way to declare enums." + expr: "int(x)" + disable_check: true + bindings { + key: "x" + value { + value { + enum_value { + type: "cel.expr.conformance.proto2.GlobalEnum" + value: 444 + } + } + } + } + value { int64_value: 444 } + } + test { + name: "convert_int_inrange" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes.NestedEnum(2)" + value { + enum_value { + type: "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" + value: 2 + } + } + } + test { + name: "convert_int_big" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes.NestedEnum(20000)" + value { + enum_value { + type: "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" + value: 20000 + } + } + } + test { + name: "convert_int_neg" + container: "cel.expr.conformance.proto2" + expr: "GlobalEnum(-33)" + value { + enum_value { + type: "cel.expr.conformance.proto2.GlobalEnum" + value: -33 + } + } + } + test { + name: "convert_int_too_big" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes.NestedEnum(5000000000)" + eval_error { + errors { + message: "range" + } + } + } + test { + name: "convert_int_too_neg" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes.NestedEnum(-7000000000)" + eval_error { + errors { + message: "range" + } + } + } + test { + name: "convert_string" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes.NestedEnum('BAZ')" + value { + enum_value { + type: "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" + value: 2 + } + } + } + test { + name: "convert_string_bad" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes.NestedEnum('BLETCH')" + eval_error { + errors { + message: "invalid" + } + } + } +} +section { + name: "strong_proto3" + description: "String semantics where enums are distinct types, proto3." + test { + name: "literal_global" + container: "cel.expr.conformance.proto3" + expr: "GlobalEnum.GAZ" + value { + enum_value { + type: "cel.expr.conformance.proto3.GlobalEnum" + value: 2 + } + } + } + test { + name: "literal_nested" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes.NestedEnum.BAR" + value { + enum_value { + type: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" + value: 1 + } + } + } + test { + name: "literal_zero" + container: "cel.expr.conformance.proto3" + expr: "GlobalEnum.GOO" + value { + enum_value { + type: "cel.expr.conformance.proto3.GlobalEnum" + value: 0 + } + } + } + test { + name: "comparison_true" + container: "cel.expr.conformance.proto3" + expr: "GlobalEnum.GAR == GlobalEnum.GAR" + value { bool_value: true } + } + test { + name: "comparison_false" + container: "cel.expr.conformance.proto3" + expr: "GlobalEnum.GAR == GlobalEnum.GAZ" + value { bool_value: false } + } + test { + name: "type_global" + container: "cel.expr.conformance.proto3" + expr: "type(GlobalEnum.GOO)" + value { type_value: "cel.expr.conformance.proto3.GlobalEnum" } + } + test { + name: "type_nested" + container: "cel.expr.conformance.proto3" + expr: "type(TestAllTypes.NestedEnum.BAZ)" + value { + type_value: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" + } + } + test { + name: "select_default" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.standalone_enum" + value { + enum_value { + type: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" + value: 0 + } + } + } + test { + name: "select" + container: "cel.expr.conformance.proto3" + expr: "x.standalone_enum" + type_env { + name: "x" + ident { + type { message_type: "cel.expr.conformance.proto3.TestAllTypes" } + } + } + bindings { + key: "x" + value { + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + standalone_enum: 2 + } + } + } + } + } + value { + enum_value { + type: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" + value: 2 + } + } + } + test { + name: "select_big" + container: "cel.expr.conformance.proto3" + expr: "x.standalone_enum" + type_env { + name: "x" + ident { + type { message_type: "cel.expr.conformance.proto3.TestAllTypes" } + } + } + bindings { + key: "x" + value { + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + standalone_enum: 108 + } + } + } + } + } + value { + enum_value { + type: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" + value: 108 + } + } + } + test { + name: "select_neg" + container: "cel.expr.conformance.proto3" + expr: "x.standalone_enum" + type_env { + name: "x" + ident { + type { message_type: "cel.expr.conformance.proto3.TestAllTypes" } + } + } + bindings { + key: "x" + value { + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + standalone_enum: -3 + } + } + } + } + } + value { + enum_value { + type: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" + value: -3 + } + } + } + test { + name: "field_type" + container: "cel.expr.conformance.proto3" + expr: "type(TestAllTypes{}.standalone_enum)" + value { + type_value: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" + } + } + test { + name: "assign_standalone_name" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.BAZ}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + standalone_enum: BAZ + } + } + } + } + test { + name: "assign_standalone_int" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum(1)}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + standalone_enum: BAR + } + } + } + } + test { + name: "assign_standalone_int_big" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum(99)}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + standalone_enum: 99 + } + } + } + } + test { + name: "assign_standalone_int_neg" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum(-1)}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + standalone_enum: -1 + } + } + } + } + test { + name: "convert_symbol_to_int" + container: "cel.expr.conformance.proto3" + expr: "int(GlobalEnum.GAZ)" + value { int64_value: 2 } + } + test { + name: "convert_unnamed_to_int" + description: "Disable check - missing way to declare enums." + expr: "int(x)" + disable_check: true + bindings { + key: "x" + value { + value { + enum_value { + type: "cel.expr.conformance.proto3.GlobalEnum" + value: 444 + } + } + } + } + value { int64_value: 444 } + } + test { + name: "convert_unnamed_to_int_select" + expr: "int(x.standalone_enum)" + type_env { + name: "x" + ident { + type { message_type: "cel.expr.conformance.proto3.TestAllTypes" } + } + } + bindings { + key: "x" + value { + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + standalone_enum: -987 + } + } + } + } + } + value { int64_value: -987 } + } + test { + name: "convert_int_inrange" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes.NestedEnum(2)" + value { + enum_value { + type: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" + value: 2 + } + } + } + test { + name: "convert_int_big" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes.NestedEnum(20000)" + value { + enum_value { + type: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" + value: 20000 + } + } + } + test { + name: "convert_int_neg" + container: "cel.expr.conformance.proto3" + expr: "GlobalEnum(-33)" + value { + enum_value { + type: "cel.expr.conformance.proto3.GlobalEnum" + value: -33 + } + } + } + test { + name: "convert_int_too_big" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes.NestedEnum(5000000000)" + eval_error { + errors { + message: "range" + } + } + } + test { + name: "convert_int_too_neg" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes.NestedEnum(-7000000000)" + eval_error { + errors { + message: "range" + } + } + } + test { + name: "convert_string" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes.NestedEnum('BAZ')" + value { + enum_value { + type: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" + value: 2 + } + } + } + test { + name: "convert_string_bad" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes.NestedEnum('BLETCH')" + eval_error { + errors { + message: "invalid" + } + } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/fields.textproto b/packages/cel-spec/src/testdata/textproto/fields.textproto new file mode 100644 index 00000000..66eb5d41 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/fields.textproto @@ -0,0 +1,674 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "fields" +description: "Tests for field access in maps." +section { + name: "map_fields" + description: "select an element in a map" + test { + name: "map_key_int64" + expr: "{0:1,2:2,5:true}[5]" + value: { bool_value: true } + } + test { + name: "map_key_uint64" + expr: "{0u:1u,2u:'happy',5u:3u}[2u]" + value: { string_value: "happy" } + } + test { + name: "map_key_string" + expr: "{'name':100u}['name']" + value: { uint64_value: 100 } + } + test { + name: "map_key_bool" + expr: "{true:5}[true]" + value: { int64_value: 5 } + } + test { + name: "map_key_mixed_type" + expr: "{true:1,2:2,5u:3}[true]" + value: { int64_value: 1 } + } + test { + name: "map_key_mixed_numbers_double_key" + expr: "{1u: 1.0, 2: 2.0, 3u: 3.0}[3.0]" + value: { double_value: 3.0 } + } + test { + name: "map_key_mixed_numbers_lossy_double_key" + expr: "{1u: 1.0, 2: 2.0, 3u: 3.0}[3.1]" + eval_error: { + errors: { message: "no such key" } + } + } + test { + name: "map_key_mixed_numbers_uint_key" + expr: "{1u: 1.0, 2: 2.0, 3u: 3.0}[2u]" + value: { double_value: 2.0 } + } + test { + name: "map_key_mixed_numbers_int_key" + expr: "{1u: 1.0, 2: 2.0, 3u: 3.0}[1]" + value: { double_value: 1.0 } + } + test { + name: "map_field_access" + expr: "x.name" + type_env: { + name: "x" + ident: { + type: { + map_type: { + key_type: { primitive: STRING } + value_type: { primitive: INT64 } + } + } + } + } + bindings: { + key: "x" + value: { + value: { + map_value: { + entries { + key: { string_value: "name" } + value: { int64_value: 1024 } + } + } + } + } + } + value: { int64_value: 1024 } + } + test { + name: "map_no_such_key" + expr: "{0:1,2:2,5:3}[1]" + eval_error: { + errors: { message: "no such key" } + } + } + test { + name: "map_no_such_key_or_false" + expr: "dyn({0:1,2:2,5:3}[1]) || false" + eval_error: { + errors: { message: "no such key" } + } + } + test { + name: "map_no_such_key_or_true" + expr: "dyn({0:1,2:2,5:3}[1]) || true" + value: { bool_value: true } + } + test { + name: "map_no_such_key_and_false" + expr: "dyn({0:1,2:2,5:3}[1]) && false" + value: { bool_value: false } + } + test { + name: "map_no_such_key_and_true" + expr: "dyn({0:1,2:2,5:3}[1]) && true" + eval_error: { + errors: { message: "no such key" } + } + } + test { + name: "map_bad_key_type" + expr: "{0:1,2:2,5:3}[dyn(b'')]" + eval_error: { + errors: { message: "no such key" } + } + } + test { + name: "map_bad_key_type_or_false" + expr: "dyn({0:1,2:2,5:3}[dyn(b'')]) || false" + eval_error: { + errors: { message: "no such key" } + } + } + test { + name: "map_bad_key_type_or_true" + expr: "dyn({0:1,2:2,5:3}[dyn(b'')]) || true" + value: { bool_value: true } + } + test { + name: "map_bad_key_type_and_false" + expr: "dyn({0:1,2:2,5:3}[dyn(b'')]) && false" + value: { bool_value: false } + } + test { + name: "map_bad_key_type_and_true" + expr: "dyn({0:1,2:2,5:3}[dyn(b'')]) && true" + eval_error: { + errors: { message: "no such key" } + } + } + test { + name: "map_field_select_no_such_key" + expr: "x.name" + type_env: { + name: "x" + ident: { + type: { + map_type: { + key_type: { primitive: STRING } + value_type: { primitive: STRING } + } + } + } + } + bindings: { + key: "x" + value: { + value: { + map_value: { + entries { + key: { string_value: "holiday" } + value: { string_value: "field" } + } + } + } + } + } + eval_error: { + errors: { message: "no such key: 'name'" } + } + } + test { + name: "map_field_select_no_such_key_or_false" + expr: "dyn(x.name) || false" + type_env: { + name: "x" + ident: { + type: { + map_type: { + key_type: { primitive: STRING } + value_type: { primitive: STRING } + } + } + } + } + bindings: { + key: "x" + value: { + value: { + map_value: { + entries { + key: { string_value: "holiday" } + value: { string_value: "field" } + } + } + } + } + } + eval_error: { + errors: { message: "no such key: 'name'" } + } + } + test { + name: "map_field_select_no_such_key_or_true" + expr: "dyn(x.name) || true" + type_env: { + name: "x" + ident: { + type: { + map_type: { + key_type: { primitive: STRING } + value_type: { primitive: STRING } + } + } + } + } + bindings: { + key: "x" + value: { + value: { + map_value: { + entries { + key: { string_value: "holiday" } + value: { string_value: "field" } + } + } + } + } + } + value: { bool_value: true } + } + test { + name: "map_field_select_no_such_key_and_false" + expr: "dyn(x.name) && false" + type_env: { + name: "x" + ident: { + type: { + map_type: { + key_type: { primitive: STRING } + value_type: { primitive: STRING } + } + } + } + } + bindings: { + key: "x" + value: { + value: { + map_value: { + entries { + key: { string_value: "holiday" } + value: { string_value: "field" } + } + } + } + } + } + value: { bool_value: false } + } + test { + name: "map_field_select_no_such_key_and_true" + expr: "dyn(x.name) && true" + type_env: { + name: "x" + ident: { + type: { + map_type: { + key_type: { primitive: STRING } + value_type: { primitive: STRING } + } + } + } + } + bindings: { + key: "x" + value: { + value: { + map_value: { + entries { + key: { string_value: "holiday" } + value: { string_value: "field" } + } + } + } + } + } + eval_error: { + errors: { message: "no such key: 'name'" } + } + } + test { + name: "map_value_null" + expr: "{true:null}[true]" + value: { null_value: NULL_VALUE } + } + test { + name: "map_value_bool" + expr: "{27:false}[27]" + value: { bool_value: false } + } + test { + name: "map_value_string" + expr: "{'n':'x'}['n']" + value: { string_value: "x" } + } + test { + name: "map_value_float" + expr: "{3:15.15}[3]" + value: { double_value: 15.15 } + } + test { + name: "map_value_uint64" + expr: "{0u:1u,2u:2u,5u:3u}[0u]" + value: { uint64_value: 1 } + } + test { + name: "map_value_int64" + expr: "{true:1,false:2}[true]" + value: { int64_value: 1 } + } + test { + name: "map_value_bytes" + expr: "{0:b''}[0]" + value: { bytes_value: "" } + } + test { + name: "map_value_list" + expr: "{0u:[1]}[0u]" + value: { + list_value: { + values: { int64_value: 1 } + } + } + } + test { + name: "map_value_map" + expr: "{'map': {'k': 'v'}}['map']" + value: { + map_value { + entries { + key: { string_value: "k" } + value: { string_value: "v" } + } + } + } + } + test { + name: "map_value_mix_type" + expr: "{'map': {'k': 'v'}, 'list': [1]}['map']" + value: { + map_value { + entries { + key: { string_value: "k" } + value: { string_value: "v" } + } + } + } + } +} +section { + name: "map_has" + description: "Has macro for map entries." + test { + name: "has" + expr: "has({'a': 1, 'b': 2}.a)" + value: { bool_value: true } + } + test { + name: "has_not" + expr: "has({'a': 1, 'b': 2}.c)" + value: { bool_value: false } + } + test { + name: "has_empty" + expr: "has({}.a)" + value: { bool_value: false } + } +} +section { + name: "quoted_map_fields" + description: "Field accesses using the quote syntax" + test { + name: "field_access_slash" + expr: "{'/api/v1': true, '/api/v2': false}.`/api/v1`" + value: { bool_value: true } + } + test { + name: "field_access_dash" + expr: "{'content-type': 'application/json', 'content-length': 145}.`content-type` == 'application/json'" + value: { bool_value: true } + } + test { + name: "field_access_dot" + expr: "{'foo.txt': 32, 'bar.csv': 1024}.`foo.txt`" + value: { int64_value: 32 } + } + test { + name: "has_field_slash" + expr: "has({'/api/v1': true, '/api/v2': false}.`/api/v3`)" + value: { bool_value: false } + } + test { + name: "has_field_dash" + expr: "has({'content-type': 'application/json', 'content-length': 145}.`content-type`)" + value: { bool_value: true } + } + test { + name: "has_field_dot" + expr: "has({'foo.txt': 32, 'bar.csv': 1024}.`foo.txt`)" + value: { bool_value: true } + } +} +section { + name: "qualified_identifier_resolution" + description: "Tests for qualified identifier resolution." + test { + name: "qualified_ident" + expr: "a.b.c" + type_env: { + name: "a.b.c" + ident: { type: { primitive: STRING } } + } + bindings: { + key: "a.b.c" + value: { value: { string_value: "yeah" } } + } + value: { string_value: "yeah" } + } + test { + name: "map_field_select" + expr: "a.b.c" + type_env: { + name: "a.b" + ident: { + type: { + map_type: { + key_type: { primitive: STRING } + value_type: { primitive: STRING } + } + } + } + } + bindings: { + key: "a.b" + value: { + value: { + map_value: { + entries { + key: { string_value: "c" } + value: { string_value: "yeah" } + } + } + } + } + } + value: { string_value: "yeah" } + } + test { + name: "qualified_identifier_resolution_unchecked" + description: "namespace resolution should try to find the longest prefix for the evaluator." + expr: "a.b.c" + type_env: { + name: "a.b.c" + ident: { type: { primitive: STRING } } + } + bindings: { + key: "a.b.c" + value: { value: { string_value: "yeah" } } + } + type_env: { + name: "a.b" + ident: { + type: { + map_type: { + key_type: { primitive: STRING } + value_type: { primitive: STRING } + } + } + } + } + bindings: { + key: "a.b" + value: { + value: { + map_value: { + entries { + key: { string_value: "c" } + value: { string_value: "oops" } + } + } + } + } + } + disable_check: true ## when check is disabled, the evaluator should evaluate it in the correct order + value: { string_value: "yeah" } + } + test { + name: "list_field_select_unsupported" + expr: "a.b.pancakes" + disable_check: true + type_env: { + name: "a.b" + ident: { + type: { + list_type: { + elem_type: { primitive: STRING } + } + } + } + } + bindings: { + key: "a.b" + value: { + value: { + list_value: { + values: { string_value: "pancakes" } + } + } + } + } + eval_error: { + errors: { + message: "type 'list_type: > ' does not support field selection" + } + } + } + test { + name: "int64_field_select_unsupported" + expr: "a.pancakes" + disable_check: true + type_env: { + name: "a" + ident: { + type: { + primitive: INT64 + } + } + } + bindings: { + key: "a" + value: { + value: { + int64_value: 15 + } + } + } + eval_error: { + errors: { + message: "type 'int64_type' does not support field selection" + } + } + } + test { + name: "ident_with_longest_prefix_check" + description: "namespace resolution should try to find the longest prefix for the checker." + expr: "a.b.c" + type_env: { + name: "a.b.c" + ident: { type: { primitive: STRING } } + } + bindings: { + key: "a.b.c" + value: { value: { string_value: "yeah" } } + } + type_env: { + name: "a.b" + ident: { + type: { + map_type: { + key_type: { primitive: STRING } + value_type: { primitive: STRING } + } + } + } + } + bindings: { + key: "a.b" + value: { + value: { + map_value: { + entries { + key: { string_value: "c" } + value: { string_value: "oops" } + } + } + } + } + } + value: { string_value: "yeah" } + } + test { + name: "map_key_float" + description: "map should not support float as the key." + expr: "{3.3:15.15, 1.0: 5}[1.0]" + disable_check: true # need to make it fail in the evaluation phase + eval_error: { + errors: { message: "unsupported key type" } + } + ## Current behavior + ## value: { int64_value: 5 } + } + test { + name: "map_key_null" + description: "map should not support null as the key." + expr: "{null:false}[null]" + disable_check: true # need to make it fail in the evaluation phase + eval_error: { + errors: { message: "unsupported key type" } + } + ## Current behavior + ## value: { bool_value: false } + } + test { + name: "map_value_repeat_key" + description: "map should not support repeated key." + expr: "{true:1,false:2,true:3}[true]" + eval_error: { + errors: { message: "Failed with repeated key" } + } + ## Current behavior: + ## value: { int64_value: 1 } + } + test { + name: "map_value_repeat_key_heterogeneous" + description: "map should not support repeated key." + expr: "{0: 1, 0u: 2}[0.0]" + eval_error: { + errors: { message: "Failed with repeated key" } + } + ## Current behavior: + ## value: { int64_value: 1 } + } +} +section { + name: "in" + description: "Tests for 'in' operator for maps." + test { + name: "empty" + expr: "7 in {}" + value: { bool_value: false } + } + test { + name: "singleton" + expr: "true in {true: 1}" + value: { bool_value: true } + } + test { + name: "present" + expr: "'George' in {'John': 'smart', 'Paul': 'cute', 'George': 'quiet', 'Ringo': 'funny'}" + value: { bool_value: true } + } + test { + name: "absent" + expr: "'spider' in {'ant': 6, 'fly': 6, 'centipede': 100}" + value: { bool_value: false } + } + test { + name: "mixed_numbers_and_keys_present" + expr: "3.0 in {1: 1, 2: 2, 3u: 3} && 2u in {1u: 1, 2: 2} && 1 in {1u: 1, 2: 2}" + value: { bool_value: true } + } + test { + name: "mixed_numbers_and_keys_absent" + expr: "3.1 in {1: 1, 2: 2, 3u: 3}" + value: { bool_value: false } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/fp_math.textproto b/packages/cel-spec/src/testdata/textproto/fp_math.textproto new file mode 100644 index 00000000..72474bc7 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/fp_math.textproto @@ -0,0 +1,167 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "fp_math" +description: "Tests for floating-point math." +section { + name: "fp_math" + description: "Simple tests for floating point." + test { + name: "add_positive_positive" + expr: "4.25 + 15.25" + value: { double_value: 19.5 } + } + test { + name: "add_positive_negative" + expr: "17.75 + (-7.75)" + value: { double_value: 10 } + } + test { + name: "add_negative_negative" + expr: "-4.125 + (-2.125)" + value: { double_value: -6.25 } + } + test { + name: "sub_positive_positive" + expr: "42.0 - 12.0" + value: { double_value: 30 } + } + test { + name: "sub_positive_negative" + expr: "42.875 - (-22.0)" + value: { double_value: 64.875 } + } + test { + name: "sub_negative_negative" + expr: "-4.875 - (-0.125)" + value: { double_value: -4.75 } + } + test { + name: "multiply_positive_positive" + expr: "42.5 * 0.2" + value: { double_value: 8.5 } + } + test { + name: "multiply_positive_negative" + expr: "40.75 * (-2.25)" + value: { double_value: -91.6875 } + } + test { + name: "multiply_negative_negative" + expr: "-3.0 * (-2.5)" + value: { double_value: 7.5 } + } + test { + name: "divide_positive_positive" + expr: "0.0625 / 0.002" + value: { double_value: 31.25 } + } + test { + name: "divide_positive_negative" + expr: "-2.0 / 2.0" + value: { double_value: -1 } + } + test { + name: "divide_negative_negative" + expr: "-8.875 / (-0.0625)" + value: { double_value: 142 } + } + test { + name: "mod_not_support" + expr: "47.5 % 5.5" + disable_check: true + eval_error: { + errors: { message:"found no matching overload for '_%_' applied to '(double, double)'" } + } + } + test { + name: "negative" + expr: "-(4.5)" + value: { double_value: -4.5 } + } + test { + name: "double_negative" + expr: "-(-1.25)" + value: { double_value: 1.25 } + } + test { + name: "negative_zero" + expr: "-(0.0)" + value: { double_value: -0.0 } + } + test { + name: "divide_zero" + expr: "15.75 / 0.0" + value: { double_value: Infinity } + } + test { + name: "multiply_zero" + expr: "15.36 * 0.0" + value: { double_value: 0 } + } + test { + name: "add_left_identity" + expr: "0.0 + 1.75" + value: { double_value: 1.75} + } + test { + name: "add_right_identity" + expr: " 2.5 + 0.0" + value: { double_value: 2.5 } + } + test { + name: "add_commutative" + expr: "7.5 + 1.5 == 1.5 + 7.5" + value: { bool_value: true } + } + test { + name: "add_associative" + expr: "5.625 + (15.75 + 2.0) == (5.625 + 15.75) + 2.0" + value: { bool_value: true } + } + test { + name: "mul_left_identity" + expr: "1.0 * 45.25" + value: { double_value: 45.25 } + } + test { + name: "mul_right_identity" + expr: "-25.25 * 1.0" + value: { double_value: -25.25 } + } + test { + name: "mul_commutative" + expr: "1.5 * 25.875 == 25.875 * 1.5" + value: { bool_value: true } + } + test { + name: "mul_associative" + expr: "1.5 * (23.625 * 0.75) == (1.5 * 23.625) * 0.75" + value: { bool_value: true } + } + test { + name: "add_mul_distribute" + expr: "5.75 * (1.5 + 2.5) == 5.75 * 1.5 + 5.75 * 2.5" + ## overflow or underflow may cause this not equal. + value: { bool_value: true } + } + test { + name: "fp_overflow_positive" + description: "DBL_MAX(2^1023) times two" + expr: "2.0 * 8.988466e+307 " + value: {double_value: inf} + } + test { + name: "fp_overflow_negative" + description: "-DBL_MAX(-2^1023) times two" + expr: "2.0 * -8.988466e+307 " + value: {double_value: -inf} + } + test { + name: "fp_underflow" + description: "DBL_MIN(2^-1074) divided by two" + expr: "1e-324 / 2.0" + ## Expect it to be the closest number to the exact result. + value: {double_value: 0} + } +} diff --git a/packages/cel-spec/src/testdata/textproto/integer_math.textproto b/packages/cel-spec/src/testdata/textproto/integer_math.textproto new file mode 100644 index 00000000..c0d4f514 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/integer_math.textproto @@ -0,0 +1,386 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "integer_math" +description: "Tests for int and uint math." +section { + name: "int64_math" + description: "Simple tests for int64." + test { + name: "add_positive_positive" + expr: "40 + 2" + value: { int64_value: 42 } + } + test { + name: "add_positive_negative" + expr: "42 + (-7)" + value: { int64_value: 35 } + } + test { + name: "add_negative_negative" + expr: "-4 + (-2)" + value: { int64_value: -6 } + } + test { + name: "sub_positive_positive" + expr: "42 - 12" + value: { int64_value: 30 } + } + test { + name: "sub_positive_negative" + expr: "42 - (-22)" + value: { int64_value: 64 } + } + test { + name: "sub_negative_negative" + expr: "-42 - (-12)" + value: { int64_value: -30 } + } + test { + name: "multiply_positive_positive" + expr: "42 * 2" + value: { int64_value: 84 } + } + test { + name: "multiply_positive_negative" + expr: "40 * (-2)" + value: { int64_value: -80 } + } + test { + name: "multiply_negative_negative" + expr: "-30 * (-2)" + value: { int64_value: 60 } + } + test { + name: "divide_positive_positive" + expr: "42 / 2" + value: { int64_value: 21 } + } + test { + name: "divide_positive_negative" + expr: "-20 / 2" + value: { int64_value: -10 } + } + test { + name: "divide_negative_negative" + expr: "-80 / (-2)" + value: { int64_value: 40 } + } + test { + name: "mod_positive_positive" + expr: "47 % 5" + value: { int64_value: 2 } + } + test { + name: "mod_positive_negative" + expr: "43 % (-5)" + value: { int64_value: 3 } + } + test { + name: "mod_negative_negative" + expr: "-42 % (-5)" + value: { int64_value: -2 } + } + test { + name: "mod_negative_positive" + expr: "-3 % 5" + value: { int64_value: -3 } + } + test { + name: "unary_minus_pos" + expr: "-(42)" + value: { int64_value: -42 } + } + test { + name: "unary_minus_neg" + expr: "-(-42)" + value: { int64_value: 42 } + } + test { + name: "unary_minus_no_overload" + expr: "-(42u)" + disable_check: true + eval_error: { + errors: { message:"no_such_overload" } + } + } + test { + name: "unary_minus_not_bool" + expr: "-false" + disable_check: true + eval_error: { + errors: { message:"no_such_overload" } + } + } + test { + name: "mod_zero" + expr: "34 % 0" + eval_error: { + errors: { message:"modulus by zero" } + } + } + test { + name: "negative_zero" + expr: "-(0)" + value: { int64_value: 0 } + } + test { + name: "double_negative" + expr: "-(-42)" + value: { int64_value: 42 } + } + test { + name: "divide_zero" + expr: "15 / 0" + eval_error: { + errors: { message:"divide by zero" } + } + } + test { + name: "multiply_zero" + expr: "15 * 0" + value: { int64_value: 0 } + } + test { + name: "add_left_identity" + expr: "0 + 17" + value: { int64_value: 17} + } + test { + name: "add_right_identity" + expr: " 29 + 0" + value: { int64_value: 29 } + } + test { + name: "add_commutative" + expr: "75 + 15 == 15 + 75" + value: { bool_value: true } + } + test { + name: "add_associative" + expr: "5 + (15 + 20) == (5 + 15) + 20" + value: { bool_value: true } + } + test { + name: "mul_left_identity" + expr: "1 * 45" + value: { int64_value: 45 } + } + test { + name: "mul_right_identity" + expr: "-25 * 1" + value: { int64_value: -25 } + } + test { + name: "mul_commutative" + expr: "15 * 25 == 25 * 15" + value: { bool_value: true } + } + test { + name: "mul_associative" + expr: "15 * (23 * 88) == (15 * 23) * 88" + value: { bool_value: true } + } + test { + name: "add_mul_distribute" + expr: "5 * (15 + 25) == 5 * 15 + 5 * 25" + value: { bool_value: true } + } + test { + name: "int64_overflow_positive" + description: "LLONG_MAX plus one." + expr: "9223372036854775807 + 1" + eval_error: { + errors: { message: "return error for overflow" } + } + } + test { + name: "int64_overflow_negative" + description: "LLONG_MIN minus one." + expr: "-9223372036854775808 - 1" + eval_error: { + errors: { message: "return error for overflow" } + } + } + test { + name: "int64_overflow_add_negative" + description: "negative overflow via addition" + expr: "-9223372036854775808 + (-1)" + eval_error: { + errors: { message: "return error for overflow" } + } + } + test { + name: "int64_overflow_sub_positive" + description: "positive overflow via subtraction" + expr: "1 - (-9223372036854775807)" + eval_error: { + errors: { message: "return error for overflow" } + } + } + test { + name: "int64_min_negate" + description: "Negated LLONG_MIN is not representable." + expr: "-(-9223372036854775808)" + eval_error: { + errors: { message: "return error for overflow" } + } + } + test { + name: "int64_min_negate_mul" + description: "Negate LLONG_MIN via multiplication" + expr: "(-9223372036854775808) * -1" + eval_error: { + errors: { message: "return error for overflow" } + } + } + test { + name: "int64_min_negate_div" + description: "Negate LLONG_MIN via division." + expr: "(-9223372036854775808)/-1" + eval_error: { + errors: { message: "return error for overflow" } + } + } + test { + name: "int64_overflow_mul_positive" + description: "Overflow via multiplication." + expr: "5000000000 * 5000000000" + eval_error: { + errors: { message: "return error for overflow" } + } + } + test { + name: "int64_overflow_mul_negative" + description: "Overflow via multiplication." + expr: "(-5000000000) * 5000000000" + eval_error: { + errors: { message: "return error for overflow" } + } + } + test { + name: "uint64_overflow_positive" + description: "ULLONG_MAX plus one." + expr: "18446744073709551615u + 1u" + eval_error: { + errors: { message: "return error for overflow" } + } + } + test { + name: "uint64_overflow_negative" + description: "zero minus one." + expr: "0u - 1u" + eval_error: { + errors: { message: "return error for overflow" } + } + } + test { + name: "uint64_overflow_mul_positive" + description: "Overflow via multiplication." + expr: "5000000000u * 5000000000u" + eval_error: { + errors: { message: "return error for overflow" } + } + } +} +section { + name: "uint64_math" + description: "Simple tests for uint64." + test { + name: "add" + expr: "42u + 2u" + value: { uint64_value: 44 } + } + test { + name: "sub" + expr: "42u - 12u" + value: { uint64_value: 30 } + } + test { + name: "multiply" + expr: "40u * 2u" + value: { uint64_value: 80 } + } + test { + name: "divide" + expr: "60u / 2u" + value: { uint64_value: 30 } + } + test { + name: "mod" + expr: "42u % 5u" + value: { uint64_value: 2 } + } + test { + name: "negative_no_overload" + expr: "-(5u)" + disable_check: true + eval_error: { + errors: { message:"no such overload" } + } + } + test { + name: "mod_zero" + expr: "34u % 0u" + eval_error: { + errors: { message:"modulus by zero" } + } + } + test { + name: "divide_zero" + expr: "15u / 0u" + eval_error: { + errors: { message:"divide by zero" } + } + } + test { + name: "multiply_zero" + expr: "15u * 0u" + value: { uint64_value: 0 } + } + test { + name: "add_left_identity" + expr: "0u + 17u" + value: { uint64_value: 17} + } + test { + name: "add_right_identity" + expr: " 29u + 0u" + value: { uint64_value: 29 } + } + test { + name: "add_commutative" + expr: "75u + 15u == 15u + 75u" + value: { bool_value: true } + } + test { + name: "add_associative" + expr: "5u + (15u + 20u) == (5u + 15u) + 20u" + value: { bool_value: true } + } + test { + name: "mul_left_identity" + expr: "1u * 45u" + value: { uint64_value: 45 } + } + test { + name: "mul_right_identity" + expr: "25u * 1u" + value: { uint64_value: 25 } + } + test { + name: "mul_commutative" + expr: "15u * 25u == 25u * 15u" + value: { bool_value: true } + } + test { + name: "mul_associative" + expr: "15u * (23u * 88u) == (15u * 23u) * 88u" + value: { bool_value: true } + } + test { + name: "add_mul_distribute" + expr: "5u * (15u + 25u) == 5u * 15u + 5u * 25u" + value: { bool_value: true } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/lists.textproto b/packages/cel-spec/src/testdata/textproto/lists.textproto new file mode 100644 index 00000000..2148118a --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/lists.textproto @@ -0,0 +1,245 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "lists" +description: "Tests for list operations." +section { + name: "concatenation" + description: "Tests for list concatenation." + test { + name: "list_append" + expr: "[0, 1, 2] + [3, 4, 5] == [0, 1, 2, 3, 4, 5]" + value: { bool_value: true } + } + test { + name: "list_not_commutative" + expr: "[0, 1, 2] + [3, 4, 5] == [3, 4, 5, 0, 1, 2]" + value: { bool_value: false } + } + test { + name: "list_repeat" + expr: "[2] + [2]" + value: { + list_value { + values: { int64_value: 2 } + values: { int64_value: 2 } + } + } + } + test { + name: "empty_empty" + expr: "[] + []" + value: { list_value { } } + } + test { + name: "left_unit" + expr: "[] + [3, 4]" + value: { + list_value { + values { int64_value: 3 } + values { int64_value: 4 } + } + } + } + test { + name: "right_unit" + expr: "[1, 2] + []" + value { + list_value { + values { int64_value: 1 } + values { int64_value: 2 } + } + } + } +} +section { + name: "index" + description: "List indexing tests." + test { + name: "zero_based" + expr: "[7, 8, 9][0]" + value: { int64_value: 7 } + } + test { + name: "zero_based_double" + expr: "[7, 8, 9][dyn(0.0)]" + value: { int64_value: 7 } + } + test { + name: "zero_based_double_error" + expr: "[7, 8, 9][dyn(0.1)]" + eval_error { + errors { message: "invalid_argument" } + } + } + test { + name: "zero_based_uint" + expr: "[7, 8, 9][dyn(0u)]" + value: { int64_value: 7 } + } + test { + name: "singleton" + expr: "['foo'][0]" + value: { string_value: "foo" } + } + test { + name: "middle" + expr: "[0, 1, 1, 2, 3, 5, 8, 13][4]" + value: { int64_value: 3 } + } + test { + name: "last" + expr: "['George', 'John', 'Paul', 'Ringo'][3]" + value: { string_value: "Ringo" } + } + test { + name: "index_out_of_bounds" + expr: "[1, 2, 3][3]" + eval_error { + errors { message: "invalid_argument" } + } + } + test { + name: "index_out_of_bounds_or_false" + expr: "dyn([1, 2, 3][3]) || false" + eval_error { + errors { message: "invalid_argument" } + } + } + test { + name: "index_out_of_bounds_or_true" + expr: "dyn([1, 2, 3][3]) || true" + value: { bool_value: true } + } + test { + name: "index_out_of_bounds_and_false" + expr: "dyn([1, 2, 3][3]) && false" + value: { bool_value: false } + } + test { + name: "index_out_of_bounds_and_true" + expr: "dyn([1, 2, 3][3]) && true" + eval_error { + errors { message: "invalid_argument" } + } + } + test { + name: "bad_index_type" + expr: "[1, 2, 3][dyn('')]" + eval_error { + errors { message: "invalid_argument" } + } + } + test { + name: "bad_index_type_or_false" + expr: "dyn([1, 2, 3][dyn('')]) || false" + eval_error { + errors { message: "invalid_argument" } + } + } + test { + name: "bad_index_type_or_true" + expr: "dyn([1, 2, 3][dyn('')]) || true" + value: { bool_value: true } + } + test { + name: "bad_index_type_and_false" + expr: "dyn([1, 2, 3][dyn('')]) && false" + value: { bool_value: false } + } + test { + name: "bad_index_type_and_true" + expr: "dyn([1, 2, 3][dyn('')]) && true" + eval_error { + errors { message: "invalid_argument" } + } + } +} +section { + name: "in" + description: "List membership tests." + test { + name: "empty" + expr: "7 in []" + value: { bool_value: false } + } + test { + name: "singleton" + expr: "4u in [4u]" + value: { bool_value: true } + } + test { + name: "first" + expr: "'alpha' in ['alpha', 'beta', 'gamma']" + value: { bool_value: true } + } + test { + name: "middle" + expr: "3 in [5, 4, 3, 2, 1]" + value: { bool_value: true } + } + test { + name: "last" + expr: "20u in [4u, 6u, 8u, 12u, 20u]" + value: { bool_value: true } + } + test { + name: "double_in_ints" + expr: "dyn(3.0) in [5, 4, 3, 2, 1]" + value: { bool_value: true } + } + test { + name: "uint_in_ints" + expr: "dyn(3u) in [5, 4, 3, 2, 1]" + value: { bool_value: true } + } + test { + name: "int_in_doubles" + expr: "dyn(3) in [5.0, 4.0, 3.0, 2.0, 1.0]" + value: { bool_value: true } + } + test { + name: "uint_in_doubles" + expr: "dyn(3u) in [5.0, 4.0, 3.0, 2.0, 1.0]" + value: { bool_value: true } + } + test { + name: "int_in_uints" + expr: "dyn(3) in [5u, 4u, 3u, 2u, 1u]" + value: { bool_value: true } + } + test { + name: "double_in_uints" + expr: "dyn(3.0) in [5u, 4u, 3u, 2u, 1u]" + value: { bool_value: true } + } + test { + name: "missing" + expr: "'hawaiian' in ['meat', 'veggie', 'margarita', 'cheese']" + value: { bool_value: false } + } +} +section { + name: "size" + description: "List and map size tests." + test { + name: "list_empty" + expr: "size([])" + value: { int64_value: 0 } + } + test { + name: "list" + expr: "size([1, 2, 3])" + value: { int64_value: 3 } + } + test { + name: "map_empty" + expr: "size({})" + value: { int64_value: 0 } + } + test { + name: "map" + expr: "size({1: 'one', 2: 'two', 3: 'three'})" + value: { int64_value: 3 } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/logic.textproto b/packages/cel-spec/src/testdata/textproto/logic.textproto new file mode 100644 index 00000000..384e5ce0 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/logic.textproto @@ -0,0 +1,198 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: google.api.expr.test.v1.SimpleTestFile + +name: "logic" +description: "Tests for logical special operators." +section { + name: "conditional" + description: "Tests for the conditional operator." + test { + name: "true_case" + expr: "true ? 1 : 2" + value: { int64_value: 1 } + } + test { + name: "false_case" + expr: "false ? 'foo' : 'bar'" + value: { string_value: "bar" } + } + test { + name: "error_case" + expr: "2 / 0 > 4 ? 'baz' : 'quux'" + eval_error: { + errors: { message: "division by zero" } + } + } + test { + name: "mixed_type" + expr: "true ? 'cows' : 17" + disable_check: true + value: { string_value: "cows" } + } + test { + name: "bad_type" + expr: "'cows' ? false : 17" + disable_check: true + eval_error: { + errors: { message: "no matching overload" } + } + } +} +section { + name: "AND" + description: "Tests for logical AND." + test { + name: "all_true" + expr: "true && true" + value: { bool_value: true } + } + test { + name: "all_false" + expr: "false && false" + value: { bool_value: false } + } + test { + name: "false_left" + expr: "false && true" + value: { bool_value: false } + } + test { + name: "false_right" + expr: "true && false" + value: { bool_value: false } + } + test { + name: "short_circuit_type_left" + expr: "false && 32" + disable_check: true + value: { bool_value: false } + } + test { + name: "short_circuit_type_right" + expr: "'horses' && false" + disable_check: true + value: { bool_value: false } + } + test { + name: "short_circuit_error_left" + expr: "false && (2 / 0 > 3 ? false : true)" + value: { bool_value: false } + } + test { + name: "short_circuit_error_right" + expr: "(2 / 0 > 3 ? false : true) && false" + value: { bool_value: false } + } + test { + name: "error_right" + expr: "true && 1/0 != 0" + eval_error: { + errors: { message: "no matching overload" } + } + } + test { + name: "error_left" + expr: "1/0 != 0 && true" + eval_error: { + errors: { message: "no matching overload" } + } + } + test { + name: "no_overload" + expr: "'less filling' && 'tastes great'" + disable_check: true + eval_error: { + errors: { message: "no matching overload" } + } + } +} +section { + name: "OR" + description: "Tests for logical OR" + test { + name: "all_true" + expr: "true || true" + value: { bool_value: true } + } + test { + name: "all_false" + expr: "false || false" + value: { bool_value: false } + } + test { + name: "false_left" + expr: "false || true" + value: { bool_value: true } + } + test { + name: "false_right" + expr: "true || false" + value: { bool_value: true } + } + test { + name: "short_circuit_type_left" + expr: "true || 32" + disable_check: true + value: { bool_value: true } + } + test { + name: "short_circuit_type_right" + expr: "'horses' || true" + disable_check: true + value: { bool_value: true } + } + test { + name: "short_circuit_error_left" + expr: "true || (2 / 0 > 3 ? false : true)" + value: { bool_value: true } + } + test { + name: "short_circuit_error_right" + expr: "(2 / 0 > 3 ? false : true) || true" + value: { bool_value: true } + } + test { + name: "error_right" + expr: "false || 1/0 != 0" + eval_error: { + errors: { message: "no matching overload" } + } + } + test { + name: "error_left" + expr: "1/0 != 0 || false" + eval_error: { + errors: { message: "no matching overload" } + } + } + test { + name: "no_overload" + expr: "'less filling' || 'tastes great'" + disable_check: true + eval_error: { + errors: { message: "no matching overload" } + } + } +} +section { + name: "NOT" + description: "Tests for logical NOT." + test { + name: "not_true" + expr: "!true" + value: { bool_value: false } + } + test { + name: "not_false" + expr: "!false" + value: { bool_value: true } + } + test { + name: "no_overload" + expr: "!0" + disable_check: true + eval_error: { + errors: { message: "no matching overload" } + } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/macros.textproto b/packages/cel-spec/src/testdata/textproto/macros.textproto new file mode 100644 index 00000000..26a201fa --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/macros.textproto @@ -0,0 +1,289 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: google.api.expr.test.v1.SimpleTestFile + +name: "macros" +description: "Tests for CEL macros." +section { + name: "exists" + description: "Tests for the .exists() macro, which is equivalent to joining the evaluated elements with logical-OR." + test { + name: "list_elem_all_true" + expr: "[1, 2, 3].exists(e, e > 0)" + value: { bool_value: true } + } + test { + name: "list_elem_some_true" + expr: "[1, 2, 3].exists(e, e == 2)" + value: { bool_value: true } + } + test { + name: "list_elem_none_true" + expr: "[1, 2, 3].exists(e, e > 3)" + value: { bool_value: false } + } + test { + name: "list_elem_type_shortcircuit" + description: "Exists filter is true for the last element." + expr: "[1, 'foo', 3].exists(e, e != '1')" + value: { bool_value: true } + } + test { + name: "list_elem_type_exhaustive" + description: "Exists filter is never true, but heterogenous equality ensure the result is false." + expr: "[1, 'foo', 3].exists(e, e == '10')" + value: { bool_value: false } + } + test { + name: "list_elem_exists_error" + expr: "[1, 2, 3].exists(e, e / 0 == 17)" + eval_error: { + errors: { message: "divide by zero" } + } + } + test { + name: "list_empty" + expr: "[].exists(e, e == 2)" + value: { bool_value: false } + } + test { + name: "map_key" + expr: "{'key1':1, 'key2':2}.exists(k, k == 'key2')" + value: { bool_value: true } + } + test { + name: "not_map_key" + expr: "!{'key1':1, 'key2':2}.exists(k, k == 'key3')" + value: { bool_value: true } + } + test { + name: "map_key_type_shortcircuit" + description: "Exists filter is true for the second key" + expr: "{'key':1, 1:21}.exists(k, k != 2)" + value: { bool_value: true } + } + test { + name: "map_key_type_exhaustive" + description: "Exists filter is never true, but heterogeneous equality ensures the result is false." + expr: "!{'key':1, 1:42}.exists(k, k == 2)" + value: { bool_value: true } + } +} +section { + name: "all" + description: "Tests for the .all() macro, which is equivalent to joining the evaluated elements with logical-AND." + test { + name: "list_elem_all_true" + expr: "[1, 2, 3].all(e, e > 0)" + value: { bool_value: true } + } + test { + name: "list_elem_some_true" + expr: "[1, 2, 3].all(e, e == 2)" + value: { bool_value: false } + } + test { + name: "list_elem_none_true" + expr: "[1, 2, 3].all(e, e == 17)" + value: { bool_value: false } + } + test { + name: "list_elem_type_shortcircuit" + expr: "[1, 'foo', 3].all(e, e == 1)" + value: { bool_value: false } + } + test { + name: "list_elem_type_exhaustive" + expr: "[1, 'foo', 3].all(e, e % 2 == 1)" + eval_error: { + errors: { message: "no_such_overload" } + } + } + test { + name: "list_elem_error_shortcircuit" + expr: "[1, 2, 3].all(e, 6 / (2 - e) == 6)" + value: { bool_value: false } + } + test { + name: "list_elem_error_exhaustive" + expr: "[1, 2, 3].all(e, e / 0 != 17)" + eval_error: { + errors: { message: "divide by zero" } + } + } + test { + name: "list_empty" + expr: "[].all(e, e > 0)" + value: { bool_value: true } + } + test { + name: "map_key" + expr: "{'key1':1, 'key2':2}.all(k, k == 'key2')" + value: { bool_value: false } + } +} +section { + name: "exists_one" + description: "Tests for exists_one() macro. An expression 'L.exists_one(I, E)' is equivalent to 'size(L.filter(I, E)) == 1'." + test { + name: "list_empty" + expr: "[].exists_one(a, a == 7)" + value: { bool_value: false } + } + test { + name: "list_one_true" + expr: "[7].exists_one(a, a == 7)" + value: { bool_value: true } + } + test { + name: "list_one_false" + expr: "[8].exists_one(a, a == 7)" + value: { bool_value: false } + } + test { + name: "list_none" + expr: "[1, 2, 3].exists_one(x, x > 20)" + value: { bool_value: false } + } + test { + name: "list_one" + expr: "[6, 7, 8].exists_one(foo, foo % 5 == 2)" + value: { bool_value: true } + } + test { + name: "list_many" + expr: "[0, 1, 2, 3, 4].exists_one(n, n % 2 == 1)" + value: { bool_value: false } + } + test { + name: "list_all" + expr: "['foal', 'foo', 'four'].exists_one(n, n.startsWith('fo'))" + value: { bool_value: false } + } + test { + name: "list_no_shortcircuit" + description: "Errors invalidate everything, even if already false." + expr: "[3, 2, 1, 0].exists_one(n, 12 / n > 1)" + eval_error { + errors: { message: "divide by zero" } + } + } + test { + name: "map_one" + expr: "{6: 'six', 7: 'seven', 8: 'eight'}.exists_one(foo, foo % 5 == 2)" + value: { bool_value: true } + } +} +section { + name: "map" + description: "Tests for map() macro." + test { + name: "list_empty" + expr: "[].map(n, n / 2)" + value: { list_value: {} } + } + test { + name: "list_one" + expr: "[3].map(n, n * n)" + value: { list_value { + values: { int64_value: 9 } + } + } + } + test { + name: "list_many" + expr: "[2, 4, 6].map(n, n / 2)" + value: { list_value { + values: { int64_value: 1 } + values: { int64_value: 2 } + values: { int64_value: 3 } + } + } + } + test { + name: "list_error" + expr: "[2, 1, 0].map(n, 4 / n)" + eval_error { + errors: { message: "divide by zero" } + } + } + test { + name: "map_extract_keys" + expr: "{'John': 'smart'}.map(key, key) == ['John']" + value: { bool_value: true } + } +} +section { + name: "filter" + description: "Tests for filter() macro." + test { + name: "list_empty" + expr: "[].filter(n, n % 2 == 0)" + value: { list_value {} } + } + test { + name: "list_one_true" + expr: "[2].filter(n, n == 2)" + value: { list_value { + values: { int64_value: 2 } + } + } + } + test { + name: "list_one_false" + expr: "[1].filter(n, n > 3)" + value: { list_value {} } + } + test { + name: "list_none" + expr: "[1, 2, 3].filter(e, e > 3)" + value: { list_value {} } + } + test { + name: "list_some" + expr: "[0, 1, 2, 3, 4].filter(x, x % 2 == 1)" + value: { list_value { + values: { int64_value: 1 } + values: { int64_value: 3 } + } + } + } + test { + name: "list_all" + expr: "[1, 2, 3].filter(n, n > 0)" + value: { list_value { + values: { int64_value: 1 } + values: { int64_value: 2 } + values: { int64_value: 3 } + } + } + } + test { + name: "list_no_shortcircuit" + expr: "[3, 2, 1, 0].filter(n, 12 / n > 4)" + eval_error { + errors: { message: "divide by zero" } + } + } + test { + name: "map_filter_keys" + expr: "{'John': 'smart', 'Paul': 'cute', 'George': 'quiet', 'Ringo': 'funny'}.filter(key, key == 'Ringo') == ['Ringo']" + value: { bool_value: true } + } +} +section { + name: "nested" + description: "Tests with nested macros." + test { + name: "filter_all" + expr: "['signer'].filter(signer, ['artifact'].all(artifact, true))" + value: { list_value { + values: { string_value: "signer" } + } + } + } + test { + name: "all_all" + expr: "['signer'].all(signer, ['artifact'].all(artifact, true))" + value: { bool_value: true } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/macros2.textproto b/packages/cel-spec/src/testdata/textproto/macros2.textproto new file mode 100644 index 00000000..a3f93011 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/macros2.textproto @@ -0,0 +1,354 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: google.api.expr.test.v1.SimpleTestFile + +name: "macros2" +description: "Tests for CEL comprehensions v2" +section { + name: "exists" + description: "Tests for the .exists() macro, which is equivalent to joining the evaluated elements with logical-OR." + test { + name: "list_elem_all_true" + expr: "[1, 2, 3].exists(i, v, i > -1 && v > 0)" + value: { bool_value: true } + } + test { + name: "list_elem_some_true" + expr: "[1, 2, 3].exists(i, v, i == 1 && v == 2)" + value: { bool_value: true } + } + test { + name: "list_elem_none_true" + expr: "[1, 2, 3].exists(i, v, i > 2 && v > 3)" + value: { bool_value: false } + } + test { + name: "list_elem_type_shortcircuit" + expr: "[1, 'foo', 3].exists(i, v, i == 1 && v != '1')" + value: { bool_value: true } + } + test { + name: "list_elem_type_exhaustive" + expr: "[1, 'foo', 3].exists(i, v, i == 3 || v == '10')" + value: { bool_value: false } + } + test { + name: "list_elem_exists_error" + expr: "[1, 2, 3].exists(i, v, v / i == 17)" + eval_error: { + errors: { message: "divide by zero" } + } + } + test { + name: "list_empty" + expr: "[].exists(i, v, i == 0 || v == 2)" + value: { bool_value: false } + } + test { + name: "map_key" + expr: "{'key1':1, 'key2':2}.exists(k, v, k == 'key2' && v == 2)" + value: { bool_value: true } + } + test { + name: "not_map_key" + expr: "!{'key1':1, 'key2':2}.exists(k, v, k == 'key3' || v == 3)" + value: { bool_value: true } + } + test { + name: "map_key_type_shortcircuit" + expr: "{'key':1, 1:21}.exists(k, v, k != 2 && v != 22)" + value: { bool_value: true } + } + test { + name: "map_key_type_exhaustive" + expr: "!{'key':1, 1:42}.exists(k, v, k == 2 && v == 43)" + value: { bool_value: true } + } +} +section { + name: "all" + description: "Tests for the .all() macro, which is equivalent to joining the evaluated elements with logical-AND." + test { + name: "list_elem_all_true" + expr: "[1, 2, 3].all(i, v, i > -1 && v > 0)" + value: { bool_value: true } + } + test { + name: "list_elem_some_true" + expr: "[1, 2, 3].all(i, v, i == 1 && v == 2)" + value: { bool_value: false } + } + test { + name: "list_elem_none_true" + expr: "[1, 2, 3].all(i, v, i == 3 || v == 4)" + value: { bool_value: false } + } + test { + name: "list_elem_type_shortcircuit" + expr: "[1, 'foo', 3].all(i, v, i == 0 || v == 1)" + value: { bool_value: false } + } + test { + name: "list_elem_type_exhaustive" + expr: "[0, 'foo', 3].all(i, v, v % 2 == i)" + value: { bool_value: false } + } + test { + name: "list_elem_type_error_exhaustive" + expr: "[0, 'foo', 5].all(i, v, v % 3 == i)" + eval_error: { + errors: { message: "no_such_overload" } + } + } + test { + name: "list_elem_error_shortcircuit" + expr: "[1, 2, 3].all(i, v, 6 / (2 - v) == i)" + value: { bool_value: false } + } + test { + name: "list_elem_error_exhaustive" + expr: "[1, 2, 3].all(i, v, v / i != 17)" + eval_error: { + errors: { message: "divide by zero" } + } + } + test { + name: "list_empty" + expr: "[].all(i, v, i > -1 || v > 0)" + value: { bool_value: true } + } + test { + name: "map_key" + expr: "{'key1':1, 'key2':2}.all(k, v, k == 'key2' && v == 2)" + value: { bool_value: false } + } +} +section { + name: "existsOne" + description: "Tests for existsOne() macro. An expression 'L.existsOne(I, E)' is equivalent to 'size(L.filter(I, E)) == 1'." + test { + name: "list_empty" + expr: "[].existsOne(i, v, i == 3 || v == 7)" + value: { bool_value: false } + } + test { + name: "list_one_true" + expr: "[7].existsOne(i, v, i == 0 && v == 7)" + value: { bool_value: true } + } + test { + name: "list_one_false" + expr: "[8].existsOne(i, v, i == 0 && v == 7)" + value: { bool_value: false } + } + test { + name: "list_none" + expr: "[1, 2, 3].existsOne(i, v, i > 2 || v > 3)" + value: { bool_value: false } + } + test { + name: "list_one" + expr: "[5, 7, 8].existsOne(i, v, v % 5 == i)" + value: { bool_value: true } + } + test { + name: "list_many" + expr: "[0, 1, 2, 3, 4].existsOne(i, v, v % 2 == i)" + value: { bool_value: false } + } + test { + name: "list_all" + expr: "['foal', 'foo', 'four'].existsOne(i, v, i > -1 && v.startsWith('fo'))" + value: { bool_value: false } + } + test { + name: "list_no_shortcircuit" + expr: "[3, 2, 1, 0].existsOne(i, v, v / i > 1)" + eval_error { + errors: { message: "divide by zero" } + } + } + test { + name: "map_one" + expr: "{6: 'six', 7: 'seven', 8: 'eight'}.existsOne(k, v, k % 5 == 2 && v == 'seven')" + value: { bool_value: true } + } +} +section { + name: "transformList" + description: "Tests for transformList() macro." + test { + name: "empty" + expr: "[].transformList(i, v, i / v)" + value: { list_value: {} } + } + test { + name: "empty_filter" + expr: "[].transformList(i, v, i > v, i / v)" + value: { list_value: {} } + } + test { + name: "one" + expr: "[3].transformList(i, v, v * v + i)" + value: { list_value { + values: { int64_value: 9 } + } + } + } + test { + name: "one_filter" + expr: "[3].transformList(i, v, i == 0 && v == 3, v * v + i)" + value: { list_value { + values: { int64_value: 9 } + } + } + } + test { + name: "many" + expr: "[2, 4, 6].transformList(i, v, v / 2 + i)" + value: { list_value { + values: { int64_value: 1 } + values: { int64_value: 3 } + values: { int64_value: 5 } + } + } + } + test { + name: "many_filter" + expr: "[2, 4, 6].transformList(i, v, i != 1 && v != 4, v / 2 + i)" + value: { list_value { + values: { int64_value: 1 } + values: { int64_value: 5 } + } + } + } + test { + name: "error" + expr: "[2, 1, 0].transformList(i, v, v / i)" + eval_error { + errors: { message: "divide by zero" } + } + } + test { + name: "error_filter" + expr: "[2, 1, 0].transformList(i, v, v / i > 0, v)" + eval_error { + errors: { message: "divide by zero" } + } + } +} +section { + name: "transformMap" + description: "Tests for transformMap() macro." + test { + name: "empty" + expr: "{}.transformMap(k, v, k + v)" + value: { map_value: {} } + } + test { + name: "empty_filter" + expr: "{}.transformMap(k, v, k == 'foo' && v == 'bar', k + v)" + value: { map_value: {} } + } + test { + name: "one" + expr: "{'foo': 'bar'}.transformMap(k, v, k + v)" + value: { + map_value: { + entries: { + key: { + string_value: "foo" + } + value: { + string_value: "foobar" + } + } + } + } + } + test { + name: "one_filter" + expr: "{'foo': 'bar'}.transformMap(k, v, k == 'foo' && v == 'bar', k + v)" + value: { + map_value: { + entries: { + key: { + string_value: "foo" + } + value: { + string_value: "foobar" + } + } + } + } + } + test { + name: "many" + expr: "{'foo': 'bar', 'baz': 'bux', 'hello': 'world'}.transformMap(k, v, k + v)" + value: { + map_value: { + entries: { + key: { + string_value: "foo" + } + value: { + string_value: "foobar" + } + } + entries: { + key: { + string_value: "baz" + } + value: { + string_value: "bazbux" + } + } + entries: { + key: { + string_value: "hello" + } + value: { + string_value: "helloworld" + } + } + } + } + } + test { + name: "many_filter" + expr: "{'foo': 'bar', 'baz': 'bux', 'hello': 'world'}.transformMap(k, v, k != 'baz' && v != 'bux', k + v)" + value: { + map_value: { + entries: { + key: { + string_value: "foo" + } + value: { + string_value: "foobar" + } + } + entries: { + key: { + string_value: "hello" + } + value: { + string_value: "helloworld" + } + } + } + } + } + test { + name: "error" + expr: "{'foo': 2, 'bar': 1, 'baz': 0}.transformMap(k, v, 4 / v)" + eval_error { + errors: { message: "divide by zero" } + } + } + test { + name: "error_filter" + expr: "{'foo': 2, 'bar': 1, 'baz': 0}.transformMap(k, v, k == 'baz' && 4 / v == 0, v)" + eval_error { + errors: { message: "divide by zero" } + } + } +} \ No newline at end of file diff --git a/packages/cel-spec/src/testdata/textproto/math_ext.textproto b/packages/cel-spec/src/testdata/textproto/math_ext.textproto new file mode 100644 index 00000000..333d9bd6 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/math_ext.textproto @@ -0,0 +1,1266 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: google.api.expr.test.v1.SimpleTestFile + +name: "math_ext" +description: "Tests for the math extension library." +section: { + name: "greatest_int_result" + test: { + name: "unary_negative" + expr: "math.greatest(-5)" + value: { + int64_value: -5 + } + } + test: { + name: "unary_positive" + expr: "math.greatest(5)" + value: { + int64_value: 5 + } + } + test: { + name: "binary_same_args" + expr: "math.greatest(1, 1)" + value: { + int64_value: 1 + } + } + test: { + name: "binary_with_decimal" + expr: "math.greatest(1, 1.0) == 1" + } + test: { + name: "binary_with_uint" + expr: "math.greatest(1, 1u) == 1" + } + test: { + name: "binary_first_arg_greater" + expr: "math.greatest(3, -3)" + value: { + int64_value: 3 + } + } + test: { + name: "binary_second_arg_greater" + expr: "math.greatest(-7, 5)" + value: { + int64_value: 5 + } + } + test: { + name: "binary_first_arg_int_max" + expr: "math.greatest(9223372036854775807, 1)" + value: { + int64_value: 9223372036854775807 + } + } + test: { + name: "binary_second_arg_int_max" + expr: "math.greatest(1, 9223372036854775807)" + value: { + int64_value: 9223372036854775807 + } + } + test: { + name: "binary_first_arg_int_min" + expr: "math.greatest(-9223372036854775808, 1)" + value: { + int64_value: 1 + } + } + test: { + name: "binary_second_arg_int_min" + expr: "math.greatest(1, -9223372036854775808)" + value: { + int64_value: 1 + } + } + test: { + name: "ternary_same_args" + expr: "math.greatest(1, 1, 1) == 1" + } + test: { + name: "ternary_with_decimal" + expr: "math.greatest(1, 1.0, 1.0) == 1" + } + test: { + name: "ternary_with_uint" + expr: "math.greatest(1, 1u, 1u) == 1" + } + test: { + name: "ternary_first_arg_greatest" + expr: "math.greatest(10, 1, 3) == 10" + } + test: { + name: "ternary_third_arg_greatest" + expr: "math.greatest(1, 3, 10) == 10" + } + test: { + name: "ternary_with_negatives" + expr: "math.greatest(-1, -2, -3) == -1" + } + test: { + name: "ternary_int_max" + expr: "math.greatest(9223372036854775807, 1, 5) == 9223372036854775807" + } + test: { + name: "ternary_int_min" + expr: "math.greatest(-9223372036854775807, -1, -5) == -1" + } + test: { + name: "quaternary_mixed" + expr: "math.greatest(5.4, 10, 3u, -5.0, 9223372036854775807) == 9223372036854775807" + } + test: { + name: "quaternary_mixed_array" + expr: "math.greatest([5.4, 10, 3u, -5.0, 3.5]) == 10" + } + test: { + name: "quaternary_mixed_dyn_array" + expr: "math.greatest([dyn(5.4), dyn(10), dyn(3u), dyn(-5.0), dyn(3.5)]) == 10" + } +} + +section: { + name: "greatest_double_result" + test: { + name: "unary_negative" + expr: "math.greatest(-5.0)" + value: { + double_value: -5.0 + } + } + test: { + name: "unary_positive" + expr: "math.greatest(5.0)" + value: { + double_value: 5.0 + } + } + test: { + name: "binary_same_args" + expr: "math.greatest(1.0, 1.0)" + value: { + double_value: 1.0 + } + } + test: { + name: "binary_with_int" + expr: "math.greatest(1.0, 1) == 1.0" + } + test: { + name: "binary_with_uint" + expr: "math.greatest(1.0, 1u) == 1.0" + } + test: { + name: "binary_first_arg_greater" + expr: "math.greatest(5.0, -7.0)" + value: { + double_value: 5.0 + } + } + test: { + name: "binary_second_arg_greater" + expr: "math.greatest(-3.0, 3.0)" + value: { + double_value: 3.0 + } + } + test: { + name: "binary_first_arg_double_max" + expr: "math.greatest(1.797693e308, 1)" + value: { + double_value: 1.797693e308 + } + } + test: { + name: "binary_second_arg_double_max" + expr: "math.greatest(1, 1.797693e308)" + value: { + double_value: 1.797693e308 + } + } + test: { + name: "binary_first_arg_double_min" + expr: "math.greatest(-1.797693e308, 1.5)" + value: { + double_value: 1.5 + } + } + test: { + name: "binary_second_arg_double_min" + expr: "math.greatest(1.5, -1.797693e308)" + value: { + double_value: 1.5 + } + } + test: { + name: "ternary_same_args" + expr: "math.greatest(1.0, 1.0, 1.0) == 1.0" + } + test: { + name: "ternary_with_int" + expr: "math.greatest(1.0, 1, 1) == 1.0" + } + test: { + name: "ternary_with_uint" + expr: "math.greatest(1.0, 1u, 1u) == 1.0" + } + test: { + name: "ternary_first_arg_greatest" + expr: "math.greatest(10.5, 1.5, 3.5) == 10.5" + } + test: { + name: "ternary_third_arg_greatest" + expr: "math.greatest(1.5, 3.5, 10.5) == 10.5" + } + test: { + name: "ternary_with_negatives" + expr: "math.greatest(-1.5, -2.5, -3.5) == -1.5" + } + test: { + name: "ternary_double_max" + expr: "math.greatest(1.797693e308, 1, 5) == 1.797693e308" + } + test: { + name: "ternary_double_min" + expr: "math.greatest(-1.797693e308, -1, -5) == -1" + } + test: { + name: "quaternary_mixed" + expr: "math.greatest(5.4, 10, 3u, -5.0, 1.797693e308) == 1.797693e308" + } + test: { + name: "quaternary_mixed_array" + expr: "math.greatest([5.4, 10.5, 3u, -5.0, 3.5]) == 10.5" + } + test: { + name: "quaternary_mixed_dyn_array" + expr: "math.greatest([dyn(5.4), dyn(10.5), dyn(3u), dyn(-5.0), dyn(3.5)]) == 10.5" + } +} + +section: { + name: "greatest_uint_result" + test: { + name: "unary" + expr: "math.greatest(5u)" + value: { + uint64_value: 5 + } + } + test: { + name: "binary_same_args" + expr: "math.greatest(1u, 1u)" + value: { + uint64_value: 1 + } + } + test: { + name: "binary_with_decimal" + expr: "math.greatest(1u, 1.0) == 1" + } + test: { + name: "binary_with_int" + expr: "math.greatest(1u, 1) == 1u" + } + test: { + name: "binary_first_arg_greater" + expr: "math.greatest(5u, -7)" + value: { + uint64_value: 5 + } + } + test: { + name: "binary_second_arg_greater" + expr: "math.greatest(-3, 3u)" + value: { + uint64_value: 3 + } + } + test: { + name: "binary_first_arg_uint_max" + expr: "math.greatest(18446744073709551615u, 1u)" + value: { + uint64_value: 18446744073709551615 + } + } + test: { + name: "binary_second_arg_uint_max" + expr: "math.greatest(1u, 18446744073709551615u)" + value: { + uint64_value: 18446744073709551615 + } + } + test: { + name: "ternary_same_args" + expr: "math.greatest(1u, 1u, 1u) == 1u" + } + test: { + name: "ternary_with_decimal" + expr: "math.greatest(1u, 1.0, 1.0) == 1u" + } + test: { + name: "ternary_with_int" + expr: "math.greatest(1u, 1, 1) == 1u" + } + test: { + name: "ternary_first_arg_greatest" + expr: "math.greatest(10u, 1u, 3u) == 10u" + } + test: { + name: "ternary_third_arg_greatest" + expr: "math.greatest(1u, 3u, 10u) == 10u" + } + test: { + name: "ternary_int_max" + expr: "math.greatest(18446744073709551615u, 1u, 5u) == 18446744073709551615u" + } + test: { + name: "quaternary_mixed" + expr: "math.greatest(5.4, 10, 3u, -5.0, 18446744073709551615u) == 18446744073709551615u" + } + test: { + name: "quaternary_mixed_array" + expr: "math.greatest([5.4, 10u, 3u, -5.0, 3.5]) == 10u" + } + test: { + name: "quaternary_mixed_dyn_array" + expr: "math.greatest([dyn(5.4), dyn(10u), dyn(3u), dyn(-5.0), dyn(3.5)]) == 10u" + } +} + +section: { + name: "least_int_result" + test: { + name: "unary_negative" + expr: "math.least(-5)" + value: { + int64_value: -5 + } + } + test: { + name: "unary_positive" + expr: "math.least(5)" + value: { + int64_value: 5 + } + } + test: { + name: "binary_same_args" + expr: "math.least(1, 1)" + value: { + int64_value: 1 + } + } + test: { + name: "binary_with_decimal" + expr: "math.least(1, 1.0) == 1" + } + test: { + name: "binary_with_uint" + expr: "math.least(1, 1u) == 1" + } + test: { + name: "binary_first_arg_least" + expr: "math.least(-3, 3)" + value: { + int64_value: -3 + } + } + test: { + name: "binary_second_arg_least" + expr: "math.least(5, -7)" + value: { + int64_value: -7 + } + } + test: { + name: "binary_first_arg_int_max" + expr: "math.least(9223372036854775807, 1)" + value: { + int64_value: 1 + } + } + test: { + name: "binary_second_arg_int_max" + expr: "math.least(1, 9223372036854775807)" + value: { + int64_value: 1 + } + } + test: { + name: "binary_first_arg_int_min" + expr: "math.least(-9223372036854775808, 1)" + value: { + int64_value: -9223372036854775808 + } + } + test: { + name: "binary_second_arg_int_min" + expr: "math.least(1, -9223372036854775808)" + value: { + int64_value: -9223372036854775808 + } + } + test: { + name: "ternary_same_args" + expr: "math.least(1, 1, 1) == 1" + } + test: { + name: "ternary_with_decimal" + expr: "math.least(1, 1.0, 1.0) == 1" + } + test: { + name: "ternary_with_uint" + expr: "math.least(1, 1u, 1u) == 1" + } + test: { + name: "ternary_first_arg_least" + expr: "math.least(0, 1, 3) == 0" + } + test: { + name: "ternary_third_arg_least" + expr: "math.least(1, 3, 0) == 0" + } + test: { + name: "ternary_with_negatives" + expr: "math.least(-1, -2, -3) == -3" + } + test: { + name: "ternary_int_max" + expr: "math.least(9223372036854775807, 1, 5) == 1" + } + test: { + name: "ternary_int_min" + expr: "math.least(-9223372036854775808, -1, -5) == -9223372036854775808" + } + test: { + name: "quaternary_mixed" + expr: "math.least(5.4, 10, 3u, -5.0, 9223372036854775807) == -5.0" + } + test: { + name: "quaternary_mixed_array" + expr: "math.least([5.4, 10, 3u, -5.0, 3.5]) == -5.0" + } + test: { + name: "quaternary_mixed_dyn_array" + expr: "math.least([dyn(5.4), dyn(10), dyn(3u), dyn(-5.0), dyn(3.5)]) == -5.0" + } +} + +section: { + name: "least_double_result" + test: { + name: "unary_negative" + expr: "math.least(-5.5)" + value: { + double_value: -5.5 + } + } + test: { + name: "unary_positive" + expr: "math.least(5.5)" + value: { + double_value: 5.5 + } + } + test: { + name: "binary_same_args" + expr: "math.least(1.5, 1.5)" + value: { + double_value: 1.5 + } + } + test: { + name: "binary_with_int" + expr: "math.least(1.0, 1) == 1" + } + test: { + name: "binary_with_uint" + expr: "math.least(1, 1u) == 1" + } + test: { + name: "binary_first_arg_least" + expr: "math.least(-3.5, 3.5)" + value: { + double_value: -3.5 + } + } + test: { + name: "binary_second_arg_least" + expr: "math.least(5.5, -7.5)" + value: { + double_value: -7.5 + } + } + test: { + name: "binary_first_arg_double_max" + expr: "math.least(1.797693e308, 1.5)" + value: { + double_value: 1.5 + } + } + test: { + name: "binary_second_arg_double_max" + expr: "math.least(1.5, 1.797693e308)" + value: { + double_value: 1.5 + } + } + test: { + name: "binary_first_arg_double_min" + expr: "math.least(-1.797693e308, 1.5)" + value: { + double_value: -1.797693e308 + } + } + test: { + name: "binary_second_arg_double_min" + expr: "math.least(1.5, -1.797693e308)" + value: { + double_value: -1.797693e308 + } + } + test: { + name: "ternary_same_args" + expr: "math.least(1.5, 1.5, 1.5) == 1.5" + } + test: { + name: "ternary_with_int" + expr: "math.least(1.0, 1, 1) == 1.0" + } + test: { + name: "ternary_with_uint" + expr: "math.least(1.0, 1u, 1u) == 1" + } + test: { + name: "ternary_first_arg_least" + expr: "math.least(0.5, 1.5, 3.5) == 0.5" + } + test: { + name: "ternary_third_arg_least" + expr: "math.least(1.5, 3.5, 0.5) == 0.5" + } + test: { + name: "ternary_with_negatives" + expr: "math.least(-1.5, -2.5, -3.5) == -3.5" + } + test: { + name: "ternary_double_max" + expr: "math.least(1.797693e308, 1, 5) == 1" + } + test: { + name: "ternary_double_min" + expr: "math.least(-1.797693e308, -1, -5) == -1.797693e308" + } + test: { + name: "quaternary_mixed" + expr: "math.least(5.4, 10, 3u, -5.0, 1.797693e308) == -5.0" + } + test: { + name: "quaternary_mixed_array" + expr: "math.least([5.4, 10.5, 3u, -5.0, 3.5]) == -5.0" + } + test: { + name: "quaternary_mixed_dyn_array" + expr: "math.least([dyn(5.4), dyn(10.5), dyn(3u), dyn(-5.0), dyn(3.5)]) == -5.0" + } +} + +section: { + name: "least_uint_result" + test: { + name: "unary" + expr: "math.least(5u)" + value: { + uint64_value: 5 + } + } + test: { + name: "binary_same_args" + expr: "math.least(1u, 1u)" + value: { + uint64_value: 1 + } + } + test: { + name: "binary_with_decimal" + expr: "math.least(1u, 1.0) == 1u" + } + test: { + name: "binary_with_int" + expr: "math.least(1u, 1) == 1u" + } + test: { + name: "binary_first_arg_least" + expr: "math.least(1u, 3u)" + value: { + uint64_value: 1 + } + } + test: { + name: "binary_second_arg_least" + expr: "math.least(5u, 2u)" + value: { + uint64_value: 2 + } + } + test: { + name: "binary_first_arg_uint_max" + expr: "math.least(18446744073709551615u, 1u)" + value: { + uint64_value: 1 + } + } + test: { + name: "binary_second_arg_uint_max" + expr: "math.least(1u, 18446744073709551615u)" + value: { + uint64_value: 1 + } + } + test: { + name: "ternary_same_args" + expr: "math.least(1u, 1u, 1u) == 1u" + } + test: { + name: "ternary_with_decimal" + expr: "math.least(1u, 1.0, 1.0) == 1u" + } + test: { + name: "ternary_with_int" + expr: "math.least(1u, 1, 1) == 1u" + } + test: { + name: "ternary_first_arg_least" + expr: "math.least(1u, 10u, 3u) == 1u" + } + test: { + name: "ternary_third_arg_least" + expr: "math.least(10u, 3u, 1u) == 1u" + } + test: { + name: "ternary_uint_max" + expr: "math.least(18446744073709551615u, 1u, 5u) == 1u" + } + test: { + name: "quaternary_mixed" + expr: "math.least(5.4, 10, 3u, 1u, 18446744073709551615u) == 1u" + } + test: { + name: "quaternary_mixed_array" + expr: "math.least([5.4, 10u, 3u, 1u, 3.5]) == 1u" + } + test: { + name: "quaternary_mixed_dyn_array" + expr: "math.least([dyn(5.4), dyn(10u), dyn(3u), dyn(1u), dyn(3.5)]) == 1u" + } +} + +section: { + name: "ceil" + test: { + name: "negative" + expr: "math.ceil(-1.2)" + value: { + double_value: -1.0 + } + } + test: { + name: "positive" + expr: "math.ceil(1.2)" + value: { + double_value: 2.0 + } + } + test: { + name: "dyn_error" + expr: "math.ceil(dyn(1))" + eval_error: { + errors: { + message: "no such overload" + } + } + } +} + +section: { + name: "floor" + test: { + name: "negative" + expr: "math.floor(-1.2)" + value: { + double_value: -2.0 + } + } + test: { + name: "positive" + expr: "math.floor(1.2)" + value: { + double_value: 1.0 + } + } + test: { + name: "dyn_error" + expr: "math.floor(dyn(1))" + eval_error: { + errors: { + message: "no such overload" + } + } + } +} + +section: { + name: "round" + test: { + name: "negative_down" + expr: "math.round(-1.6)" + value: { + double_value: -2.0 + } + } + test: { + name: "negative_up" + expr: "math.round(-1.4)" + value: { + double_value: -1.0 + } + } + test: { + name: "negative_mid" + expr: "math.round(-1.5)" + value: { + double_value: -2.0 + } + } + test: { + name: "positive_down" + expr: "math.round(1.2)" + value: { + double_value: 1.0 + } + } + test: { + name: "positive_up" + expr: "math.round(1.5)" + value: { + double_value: 2.0 + } + } + test: { + name: "nan" + expr: "math.isNaN(math.round(0.0/0.0))" + } + test: { + name: "dyn_error" + expr: "math.round(dyn(1))" + eval_error: { + errors: { + message: "no such overload" + } + } + } +} + +section: { + name: "trunc" + test: { + name: "negative" + expr: "math.trunc(-1.2)" + value: { + double_value: -1.0 + } + } + test: { + name: "positive" + expr: "math.trunc(1.2)" + value: { + double_value: 1.0 + } + } + test: { + name: "nan" + expr: "math.isNaN(math.trunc(0.0/0.0))" + } + test: { + name: "dyn_error" + expr: "math.trunc(dyn(1))" + eval_error: { + errors: { + message: "no such overload" + } + } + } +} + +section: { + name: "abs" + test: { + name: "uint" + expr: "math.abs(1u)" + value: { + uint64_value: 1 + } + } + test: { + name: "positive_int" + expr: "math.abs(1)" + value: { + int64_value: 1 + } + } + test: { + name: "negative_int" + expr: "math.abs(-11)" + value: { + int64_value: 11 + } + } + test: { + name: "positive_double" + expr: "math.abs(1.5)" + value: { + double_value: 1.5 + } + } + test: { + name: "negative_double" + expr: "math.abs(-11.5)" + value: { + double_value: 11.5 + } + } + test: { + name: "int_overflow" + expr: "math.abs(-9223372036854775808)" + eval_error: { + errors: { + message: "overflow" + } + } + } +} + +section: { + name: "sign" + test: { + name: "positive_uint" + expr: "math.sign(100u)" + value: { + uint64_value: 1 + } + } + test: { + name: "zero_uint" + expr: "math.sign(0u)" + value: { + uint64_value: 0 + } + } + test: { + name: "positive_int" + expr: "math.sign(100)" + value: { + int64_value: 1 + } + } + test: { + name: "negative_int" + expr: "math.sign(-11)" + value: { + int64_value: -1 + } + } + test: { + name: "zero_int" + expr: "math.sign(0)" + value: { + int64_value: 0 + } + } + test: { + name: "positive_double" + expr: "math.sign(100.5)" + value: { + double_value: 1.0 + } + } + test: { + name: "negative_double" + expr: "math.sign(-32.0)" + value: { + double_value: -1.0 + } + } + test: { + name: "zero_double" + expr: "math.sign(0.0)" + value: { + double_value: 0.0 + } + } + test: { + name: "dyn_error" + expr: "math.sign(dyn(true))" + eval_error: { + errors: { + message: "no such overload" + } + } + } +} + +section: { + name: "isNaN" + test: { + name: "true" + expr: "math.isNaN(0.0/0.0)" + } + test: { + name: "false" + expr: "!math.isNaN(1.0/0.0)" + } + test: { + name: "dyn_error" + expr: "math.isNaN(dyn(true))" + eval_error: { + errors: { + message: "no such overload" + } + } + } +} + +section: { + name: "isInf" + test: { + name: "true" + expr: "math.isInf(1.0/0.0)" + } + test: { + name: "false" + expr: "!math.isInf(0.0/0.0)" + } + test: { + name: "dyn_error" + expr: "math.isInf(dyn(true))" + eval_error: { + errors: { + message: "no such overload" + } + } + } +} + +section: { + name: "isFinite" + test: { + name: "true" + expr: "math.isFinite(1.0/1.5)" + } + test: { + name: "false_nan" + expr: "!math.isFinite(0.0/0.0)" + } + test: { + name: "false_inf" + expr: "!math.isFinite(-1.0/0.0)" + } + test: { + name: "dyn_error" + expr: "math.isFinite(dyn(true))" + eval_error: { + errors: { + message: "no such overload" + } + } + } +} + +section: { + name: "bit_and" + test: { + name: "int_int_non_intersect" + expr: "math.bitAnd(1, 2)" + value: { + int64_value: 0 + } + } + test: { + name: "int_int_intersect" + expr: "math.bitAnd(1, 3)" + value: { + int64_value: 1 + } + } + test: { + name: "int_int_intersect_neg" + expr: "math.bitAnd(1, -1)" + value: { + int64_value: 1 + } + } + test: { + name: "uint_uint_non_intersect" + expr: "math.bitAnd(1u, 2u)" + value: { + uint64_value: 0 + } + } + test: { + name: "uint_uint_intersect" + expr: "math.bitAnd(1u, 3u)" + value: { + uint64_value: 1 + } + } + test: { + name: "int_dyn_error" + expr: "math.bitAnd(2u, dyn(''))" + eval_error: { + errors: { + message: "no such overload" + } + } + } +} + +section: { + name: "bit_or" + test: { + name: "int_int_positive" + expr: "math.bitOr(1, 2)" + value: { + int64_value: 3 + } + } + test: { + name: "int_int_positive_negative" + expr: "math.bitOr(4, -2)" + value: { + int64_value: -2 + } + } + test: { + name: "uint_uint" + expr: "math.bitOr(1u, 4u)" + value: { + uint64_value: 5 + } + } + test: { + name: "dyn_int_error" + expr: "math.bitOr(dyn(1.2), 1)" + eval_error: { + errors: { + message: "no such overload" + } + } + } +} + +section: { + name: "bit_xor" + test: { + name: "int_int_positive" + expr: "math.bitXor(1, 3)" + value: { + int64_value: 2 + } + } + test: { + name: "int_int_positive_negative" + expr: "math.bitXor(4, -2)" + value: { + int64_value: -6 + } + } + test: { + name: "uint_uint" + expr: "math.bitXor(1u, 3u)" + value: { + uint64_value: 2 + } + } + test: { + name: "dyn_dyn_error" + expr: "math.bitXor(dyn([]), dyn([1]))" + eval_error: { + errors: { + message: "no such overload" + } + } + } +} + +section: { + name: "bit_not" + test: { + name: "int_positive" + expr: "math.bitNot(1)" + value: { + int64_value: -2 + } + } + test: { + name: "int_negative" + expr: "math.bitNot(-1)" + value: { + int64_value: 0 + } + } + test: { + name: "int_zero" + expr: "math.bitNot(0)" + value: { + int64_value: -1 + } + } + test: { + name: "uint_positive" + expr: "math.bitNot(1u)" + value: { + uint64_value: 18446744073709551614 + } + } + test: { + name: "uint_zero" + expr: "math.bitNot(0u)" + value: { + uint64_value: 18446744073709551615 + } + } + test: { + name: "dyn_error" + expr: "math.bitNot(dyn(''))" + eval_error: { + errors: { + message: "no such overload" + } + } + } +} + +section: { + name: "bit_shift_left" + test: { + name: "int", + expr: "math.bitShiftLeft(1, 2)" + value: { + int64_value: 4 + } + } + test: { + name: "int_large_shift", + expr: "math.bitShiftLeft(1, 200)" + value: { + int64_value: 0 + } + } + test: { + name: "int_negative_large_shift", + expr: "math.bitShiftLeft(-1, 200)" + value: { + int64_value: 0 + } + } + test: { + name: "uint", + expr: "math.bitShiftLeft(1u, 2)" + value: { + uint64_value: 4 + } + } + test: { + name: "uint_large_shift", + expr: "math.bitShiftLeft(1u, 200)" + value: { + uint64_value: 0 + } + } + test: { + name: "bad_shift", + expr: "math.bitShiftLeft(1u, -1)" + eval_error: { + errors: { + message: "negative offset" + } + } + } + test: { + name: "dyn_int_error" + expr: "math.bitShiftLeft(dyn(4.3), 1)" + eval_error: { + errors: { + message: "no such overload" + } + } + } +} + +section: { + name: "bit_shift_right" + test: { + name: "int", + expr: "math.bitShiftRight(1024, 2)" + value: { + int64_value: 256 + } + } + test: { + name: "int_large_shift", + expr: "math.bitShiftRight(1024, 64)" + value: { + int64_value: 0 + } + } + test: { + name: "int_negative", + expr: "math.bitShiftRight(-1024, 3)" + value: { + int64_value: 2305843009213693824 + } + } + test: { + name: "int_negative_large_shift", + expr: "math.bitShiftRight(-1024, 64)" + value: { + int64_value: 0 + } + } + test: { + name: "uint", + expr: "math.bitShiftRight(1024u, 2)" + value: { + uint64_value: 256 + } + } + test: { + name: "uint_large_shift", + expr: "math.bitShiftRight(1024u, 200)" + value: { + uint64_value: 0 + } + } + test: { + name: "bad_shift", + expr: "math.bitShiftRight(1u, -1)" + eval_error: { + errors: { + message: "negative offset" + } + } + } + test: { + name: "dyn_int_error" + expr: "math.bitShiftRight(dyn(b'123'), 1)" + eval_error: { + errors: { + message: "no such overload" + } + } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/namespace.textproto b/packages/cel-spec/src/testdata/textproto/namespace.textproto new file mode 100644 index 00000000..15cc3ace --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/namespace.textproto @@ -0,0 +1,71 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: google.api.expr.test.v1.SimpleTestFile + +name: "namespace" +description: "Uses of qualified identifiers and namespaces." +section { + name: "qualified" + description: "Qualified variable lookups." + test { + name: "self_eval_qualified_lookup" + expr: "x.y" + value: { bool_value: true } + type_env: { + name: "x.y", + ident: { type: { primitive: BOOL } } + } + bindings: { + key: "x.y" + value: { value: { bool_value: true } } + } + } +} +section { + name: "namespace" + description: "Namespaced identifiers." + test { + name: "self_eval_container_lookup" + expr: "y" + container: "x" + type_env: { + name: "x.y", + ident: { type: { primitive: BOOL } } + } + type_env: { + name: "y", + ident: { type: { primitive: STRING } } + } + bindings: { + key: "x.y" + value: { value: { bool_value: true } } + } + bindings: { + key: "y" + value: { value: { string_value: "false" } } + } + value: { bool_value: true } + } + test { + name: "self_eval_container_lookup_unchecked" + expr: "y" + container: "x" + type_env: { + name: "x.y", + ident: { type: { primitive: BOOL } } + } + type_env: { + name: "y", + ident: { type: { primitive: BOOL } } + } + bindings: { + key: "x.y" + value: { value: { bool_value: true } } + } + bindings: { + key: "y" + value: { value: { bool_value: false } } + } + disable_check: true ## ensure unchecked ASTs resolve the same as checked ASTs + value: { bool_value: true } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/optionals.textproto b/packages/cel-spec/src/testdata/textproto/optionals.textproto new file mode 100644 index 00000000..6ad1cf9f --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/optionals.textproto @@ -0,0 +1,451 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "optionals" +description: "Tests for optionals." +section: { + name: "optionals" + test { + name: "null" + expr: "optional.of(null).hasValue()" + value: { bool_value: true } + } + test { + name: "null_non_zero_value" + expr: "optional.ofNonZeroValue(null).hasValue()" + value: { bool_value: false } + } + test { + name: "none_or_none_or_value" + expr: "optional.none().or(optional.none()).orValue(42)" + value: { int64_value: 42 } + } + test { + name: "none_optMap_hasValue" + expr: "optional.none().optMap(y, y + 1).hasValue()" + value: { bool_value: false } + } + test { + name: "empty_map_optFlatMap_hasValue" + expr: "{}.?key.optFlatMap(k, k.?subkey).hasValue()" + value: { bool_value: false } + } + test { + name: "map_empty_submap_optFlatMap_hasValue" + expr: "{'key': {}}.?key.optFlatMap(k, k.?subkey).hasValue()" + value: { bool_value: false } + } + test { + name: "map_null_entry_hasValue" + expr: "{'null_key': dyn(null)}.?null_key.hasValue()" + value: { bool_value: true } + } + test { + name: "map_null_entry_no_such_key" + expr: "{'null_key': dyn(null)}.?null_key.invalid.hasValue()" + eval_error: { + errors: { message: "no such key" } + } + } + test { + name: "map_absent_key_absent_field_none" + expr: "{true: dyn(0)}[?false].absent.hasValue()" + value: { bool_value: false } + } + test { + name: "map_present_key_invalid_field" + expr: "{true: dyn(0)}[?true].absent.hasValue()" + eval_error: { + errors: { message: "no such key" } + } + } + test { + name: "map_undefined_entry_hasValue" + expr: "{}.?null_key.invalid.hasValue()" + value: { bool_value: false } + } + test { + name: "map_submap_subkey_optFlatMap_value" + expr: "{'key': {'subkey': 'subvalue'}}.?key.optFlatMap(k, k.?subkey).value()" + value: { string_value: "subvalue" } + } + test { + name: "map_submap_optFlatMap_value" + expr: "{'key': {'subkey': ''}}.?key.optFlatMap(k, k.?subkey).value()" + value: { string_value: "" } + } + test { + name: "map_optindex_optFlatMap_optional_ofNonZeroValue_hasValue" + expr: "{'key': {'subkey': ''}}.?key.optFlatMap(k, optional.ofNonZeroValue(k.subkey)).hasValue()" + value: { bool_value: false } + } + test { + name: "optional_of_optMap_value" + expr: "optional.of(42).optMap(y, y + 1).value()" + value: { int64_value: 43 } + } + test { + name: "optional_ofNonZeroValue_or_optional_value" + expr: "optional.ofNonZeroValue(42).or(optional.of(20)).value() == 42" + value: { bool_value: true } + } + test { + name: "ternary_optional_hasValue" + expr: "(has({}.x) ? optional.of({}.x) : optional.none()).hasValue()" + value: { bool_value: false } + } + test { + name: "map_optindex_hasValue" + expr: "{}.?x.hasValue()" + value: { bool_value: false } + } + test { + name: "has_map_optindex" + expr: "has({}.?x.y)" + value: { bool_value: false } + } + test { + name: "has_map_optindex_field" + expr: "has({'x': {'y': 'z'}}.?x.y)" + value: { bool_value: true } + } + test { + name: "type" + expr: "type(optional.none()) == optional_type" + value: { bool_value: true } + } + test { + name: "optional_chaining_1" + expr: "optional.ofNonZeroValue('').or(optional.of({'c': {'dashed-index': 'goodbye'}}.c['dashed-index'])).orValue('default value')" + value: { string_value: "goodbye" } + } + test { + name: "optional_chaining_2" + expr: "{'c': {'dashed-index': 'goodbye'}}.c[?'dashed-index'].orValue('default value')" + value: { string_value: "goodbye" } + } + test { + name: "optional_chaining_3" + expr: "{'c': {}}.c[?'missing-index'].orValue('default value')" + value: { string_value: "default value" } + } + test { + name: "optional_chaining_4" + expr: "optional.of({'c': {'index': 'goodbye'}}).c.index.orValue('default value')" + value: { string_value: "goodbye" } + } + test { + name: "optional_chaining_5" + expr: "optional.of({'c': {}}).c.missing.or(optional.none()[0]).orValue('default value')" + value: { string_value: "default value" } + } + test { + name: "optional_chaining_6" + expr: "optional.of({'c': {}}).c.missing.or(optional.of(['list-value'])[0]).orValue('default value')" + value: { string_value: "list-value" } + } + test { + name: "optional_chaining_7" + expr: "optional.of({'c': {'index': 'goodbye'}}).c['index'].orValue('default value')" + value: { string_value: "goodbye" } + } + test { + name: "optional_chaining_8" + expr: "optional.of({'c': {}}).c['missing'].orValue('default value')" + value: { string_value: "default value" } + } + test { + name: "optional_chaining_9" + expr: "has(optional.of({'c': {'entry': 'hello world'}}).c) && !has(optional.of({'c': {'entry': 'hello world'}}).c.missing)" + value: { bool_value: true } + } + test { + name: "optional_chaining_10" + expr: "optional.ofNonZeroValue({'c': {'dashed-index': 'goodbye'}}.a.z).orValue({'c': {'dashed-index': 'goodbye'}}.c['dashed-index'])" + eval_error: { + errors: { message: "no such key" } + } + } + test { + name: "optional_chaining_11" + expr: "{'c': {'dashed-index': 'goodbye'}}.?c.missing.or({'c': {'dashed-index': 'goodbye'}}.?c['dashed-index']).orValue('').size()" + value: { int64_value: 7 } + } + test { + name: "optional_chaining_12" + expr: "{?'nested_map': optional.ofNonZeroValue({?'map': {'c': {'dashed-index': 'goodbye'}}.?c})}" + value: { + map_value: { + entries { + key: { string_value: "nested_map" } + value: { + map_value: { + entries { + key: { string_value: "map" } + value: { + map_value: { + entries { + key: { string_value: "dashed-index" } + value: { string_value: "goodbye" } + } + } + } + } + } + } + } + } + } + } + test { + name: "optional_chaining_13" + expr: "{?'nested_map': optional.ofNonZeroValue({?'map': {}.?c}), 'singleton': true}" + value: { + map_value: { + entries { + key: { string_value: "singleton" } + value: { bool_value: true } + } + } + } + } + test { + name: "optional_chaining_14" + expr: "[?{}.?c, ?optional.of(42), ?optional.none()]" + value: { list_value: { values: { int64_value: 42 } } } + } + test { + name: "optional_chaining_15" + expr: "[?optional.ofNonZeroValue({'c': []}.?c.orValue(dyn({})))]" + value: { list_value: {} } + } + test { + name: "optional_chaining_16" + expr: "optional.ofNonZeroValue({?'nested_map': optional.ofNonZeroValue({?'map': optional.of({}).?c})}).hasValue()" + value: { bool_value: false } + } + test { + name: "has_optional_ofNonZeroValue_struct_optional_ofNonZeroValue_map_optindex_field" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{?single_double_wrapper: optional.ofNonZeroValue(0.0)}.single_double_wrapper)" + value: { bool_value: false } + } + test { + name: "optional_ofNonZeroValue_struct_optional_ofNonZeroValue_map_optindex_field" + container: "cel.expr.conformance.proto2" + expr: "optional.ofNonZeroValue(TestAllTypes{?single_double_wrapper: optional.ofNonZeroValue(0.0)}).hasValue()" + value: { bool_value: false } + } + test { + name: "struct_map_optindex_field" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{?map_string_string: {'nested': {}}[?'nested']}.map_string_string" + value: { map_value: {} } + } + test { + name: "struct_optional_ofNonZeroValue_map_optindex_field" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{?map_string_string: optional.ofNonZeroValue({'nested': {}}[?'nested'].orValue({}))}.map_string_string" + value: { map_value: {} } + } + test { + name: "struct_map_optindex_field_nested" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{?map_string_string: {'nested': {'hello': 'world'}}[?'nested']}.map_string_string" + value: { + map_value: { + entries { + key: { string_value: "hello" } + value: { string_value: "world" } + } + } + } + } + test { + name: "struct_list_optindex_field" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{repeated_string: ['greetings', ?{'nested': {'hello': 'world'}}.nested.?hello]}.repeated_string" + value: { + list_value: { + values { + string_value: "greetings" + } + values { + string_value: "world" + } + } + } + } + test { + name: "optional_empty_map_optindex_hasValue" + expr: "optional.of({}).?c.hasValue()" + value: { + bool_value: false + } + } + test { + name: "empty_struct_optindex_hasValue" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.?repeated_string.hasValue()" + value: { + bool_value: false + } + } + test { + name: "optional_empty_struct_optindex_hasValue" + container: "cel.expr.conformance.proto2" + expr: "optional.of(TestAllTypes{}).?repeated_string.hasValue()" + value: { + bool_value: false + } + } + test { + name: "optional_none_optselect_hasValue" + expr: "optional.none().?repeated_string.hasValue()" + value: { + bool_value: false + } + } + test { + name: "struct_optindex_value" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{repeated_string: ['foo']}.?repeated_string.value()" + value: { + list_value: { + values { + string_value: "foo" + } + } + } + } + test { + name: "optional_struct_optindex_value" + container: "cel.expr.conformance.proto2" + expr: "optional.of(TestAllTypes{repeated_string: ['foo']}).?repeated_string.value()" + value: { + list_value: { + values { + string_value: "foo" + } + } + } + } + test { + name: "optional_struct_optindex_index_value" + container: "cel.expr.conformance.proto2" + expr: "optional.of(TestAllTypes{repeated_string: ['foo']}).?repeated_string[0].value()" + value: { + string_value: "foo" + } + } + test { + name: "empty_list_optindex_hasValue" + expr: "[][?0].hasValue()" + value: { + bool_value: false + } + } + test { + name: "optional_empty_list_optindex_hasValue" + expr: "optional.of([])[?0].hasValue()" + value: { + bool_value: false + } + } + test { + name: "optional_none_optindex_hasValue" + expr: "optional.none()[?0].hasValue()" + value: { + bool_value: false + } + } + test { + name: "list_optindex_value" + expr: "['foo'][?0].value()" + value: { + string_value: "foo" + } + } + test { + name: "optional_list_optindex_value" + expr: "optional.of(['foo'])[?0].value()" + value: { + string_value: "foo" + } + } + test { + name: "map_key_mixed_type_optindex_value" + expr: "{true: 1, 2: 2, 5u: 3}[?true].value()" + value: { int64_value: 1 } + } + test { + name: "map_key_mixed_numbers_double_key_optindex_value" + expr: "{1u: 1.0, 2: 2.0, 3u: 3.0}[?3.0].value()" + value: { double_value: 3.0 } + } + test { + name: "map_key_mixed_numbers_uint_key_optindex_value" + expr: "{1u: 1.0, 2: 2.0, 3u: 3.0}[?2u].value()" + value: { double_value: 2.0 } + } + test { + name: "map_key_mixed_numbers_int_key_optindex_value" + expr: "{1u: 1.0, 2: 2.0, 3u: 3.0}[?1].value()" + value: { double_value: 1.0 } + } + test { + name: "optional_eq_none_none" + expr: "optional.none() == optional.none()" + value: { bool_value: true } + } + test { + name: "optional_eq_none_int" + expr: "optional.none() == optional.of(1)" + value: { bool_value: false } + } + test { + name: "optional_eq_int_none" + expr: "optional.of(1) == optional.none()" + value: { bool_value: false } + } + test { + name: "optional_eq_int_int" + expr: "optional.of(1) == optional.of(1)" + value: { bool_value: true } + } + test { + name: "optional_ne_none_none" + expr: "optional.none() != optional.none()" + value: { bool_value: false } + } + test { + name: "optional_ne_none_int" + expr: "optional.none() != optional.of(1)" + value: { bool_value: true } + } + test { + name: "optional_ne_int_none" + expr: "optional.of(1) != optional.none()" + value: { bool_value: true } + } + test { + name: "optional_ne_int_int" + expr: "optional.of(1) != optional.of(1)" + value: { bool_value: false } + } + test { + name: "map_optional_has" + expr: "has({'foo': optional.none()}.foo)" + value: { bool_value: true } + } + test { + name: "map_optional_select_has" + expr: "has({'foo': optional.none()}.foo.bar)" + value: { bool_value: false } + } + test { + name: "map_optional_entry_has" + expr: "has({?'foo': optional.none()}.foo)" + value: { bool_value: false } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/parse.textproto b/packages/cel-spec/src/testdata/textproto/parse.textproto new file mode 100644 index 00000000..db94aef0 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/parse.textproto @@ -0,0 +1,1410 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "parse" +description: "End-to-end parsing tests." +section { + name: "nest" + description: "Deep parse trees which all implementations must support." + test { + name: "list_index" + description: "Member = Member '[' Expr ']'. Nested indices are supported up to 12 times." + expr: "a[a[a[a[a[a[a[a[a[a[a[a[0]]]]]]]]]]]]" + type_env { + name: "a" + ident { type { list_type { elem_type { primitive: INT64 } } } } + } + bindings { + key: "a" + value { value { list_value { values { int64_value: 0 } } } } + } + value { int64_value: 0 } + } + test { + name: "message_literal" + description: "Member = Member '{' [FieldInits] '}'. Nested messages supported up to 12 levels deep." + container: "cel.expr.conformance.proto3" + expr: "NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{child: NestedTestAllTypes{payload: TestAllTypes{single_int64: 137}}}}}}}}}}}}.payload.single_int64" + value { int64_value: 0 } + } + test { + name: "funcall" + description: "Primary = ['.'] IDENT ['(' [ExprList] ')']. Nested function calls supported up to 12 levels deep." + expr: "int(uint(int(uint(int(uint(int(uint(int(uint(int(uint(7))))))))))))" + value { int64_value: 7 } + } + test { + name: "list_literal" + description: "Primary = '[' [ExprList] ']'. Nested list literals up to 12 levels deep." + expr: "size([[[[[[[[[[[[0]]]]]]]]]]]])" + value { int64_value: 1 } + } + test { + name: "map_literal" + description: "Primary = '{' [MapInits] '}'. Nested map literals up to 12 levels deep." + expr: "size({0: {0: {0: {0: {0: {0: {0: {0: {0: {0: {0: {0: 'foo'}}}}}}}}}}}})" + value { int64_value: 1 } + } + test { + name: "parens" + description: "Primary = '(' Expr ')'" + expr: "((((((((((((((((((((((((((((((((7))))))))))))))))))))))))))))))))" + value { int64_value: 7 } + } +} +section { + name: "repeat" + description: "Repetitive parse trees which all implementations must support." + test { + name: "conditional" + description: "Expr = ConditionalOr ['?' ConditionalOr ':' Expr]. Chained ternary operators up to 24 levels." + expr: "true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : true ? true : false" + value { bool_value: true } + } + test { + name: "or" + description: "ConditionalOr = [ConditionalOr '||'] ConditionalAnd. Logical OR statements with 32 conditions." + expr: "false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || false || true" + value { bool_value: true } + } + test { + name: "and" + description: "ConditionalAnd = [ConditionalAnd '&&'] Relation. Logical AND statements with 32 conditions." + expr: "true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && true && false" + value { bool_value: false } + } + test { + name: "add_sub" + description: "Addition = [Addition ('+' | '-')] Multiplication. Addition operators are supported up to 24 times consecutively." + expr: "3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3 - 3 + 3" + value { int64_value: 3 } + } + test { + name: "mul_div" + description: "Multiplication = [Multiplication ('*' | '/' | '%')] Unary. Multiplication operators are supported up to 24 times consecutively." + expr: "4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4 * 4 / 4" + value { int64_value: 4 } + } + test { + name: "not" + description: "Unary = '!' {'!'} Member" + expr: "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!true" + value { bool_value: true } + } + test { + name: "unary_neg" + description: "Unary = '-' {'-'} Member" + expr: "--------------------------------19" + value { int64_value: 19 } + } + test { + name: "select" + description: "Member = Member '.' IDENT ['(' [ExprList] ')']. Selection is supported up to 12 times consecutively." + container: "cel.expr.conformance.proto3" + expr: "NestedTestAllTypes{}.child.child.child.child.child.child.child.child.child.child.payload.single_int32" + value { int64_value: 0 } + } + test { + name: "index" + description: "Member = Member '[' Expr ']'. Indexing is supported up to 12 times consecutively." + expr: "[[[[[[[[[[[['foo']]]]]]]]]]]][0][0][0][0][0][0][0][0][0][0][0][0]" + value { string_value: "foo" } + } + test { + name: "list_literal" + description: "Primary = '[' [ExprList] ']'. List literals with up to 32 elements." + expr: "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31][17]" + value { int64_value: 17 } + } + test { + name: "map_literal" + description: "Primary = '{' [MapInits] '}'. Map literals with up to 32 entries." + expr: "{0: 'zero', 1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten', 11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', 15: 'fifteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 19: 'nineteen', 20: 'twenty', 21: 'twenty-one', 22: 'twenty-two', 23: 'twenty-three', 24: 'twenty-four', 25: 'twenty-five', 26: 'twenty-six', 27: 'twenty-seven', 28: 'twenty-eight', 29: 'twenty-nine', 30: 'thirty', 31: 'thirty-one'}[17]" + value { string_value: 'seventeen' } + } + test { + name: "message_literal" + description: "Member = Member '{' [FieldInits] '}'. Message literals with up to 32 fields." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int32: 5, single_int64: 10, single_uint32: 15u, single_uint64: 20u, single_sint32: 25, single_sint64: 30, single_fixed32: 35u, single_fixed64: 40u, single_float: 45.0, single_double: 50.0, single_bool: true, single_string: 'sixty', single_bytes: b'sixty-five', single_value: 70.0, single_int64_wrapper: 75, single_int32_wrapper: 80, single_double_wrapper: 85.0, single_float_wrapper: 90.0, single_uint64_wrapper: 95u, single_uint32_wrapper: 100u, single_string_wrapper: 'one hundred five', single_bool_wrapper: true, repeated_int32: [115], repeated_int64: [120], repeated_uint32: [125u], repeated_uint64: [130u], repeated_sint32: [135], repeated_sint64: [140], repeated_fixed32: [145u], repeated_fixed64: [150u], repeated_sfixed32: [155], repeated_float: [160.0]}.single_sint64" + value { int64_value: 30 } + } +} +section { + name: "string_literals" + description: "Check that string literals are properly parsed" + test { + name: "single_quoted" + expr: "'hello'" + value: { string_value: "hello" } + } + test { + name: "double_quoted" + expr: '"hello"' + value: { string_value: "hello" } + } + test { + name: "triple_single_quoted" + expr: "'''hello'''" + value: { string_value: "hello" } + } + test { + name: "triple_double_quoted" + expr: '"""hello"""' + value: { string_value: "hello" } + } + + test { + name: "single_quoted_escaped_punctuation" + expr: "' \\\\ \\\? \\\" \\\' \\` '" + value: { string_value: " \\ \? \" \' ` " } + } + test { + name: "double_quoted_escaped_punctuation" + expr: '" \\\\ \\\? \\\" \\\' \\` "' + value: { string_value: " \\ \? \" \' ` " } + } + test { + name: "triple_single_quoted_escaped_punctuation" + expr: "''' \\\\ \\\? \\\" \\\' \\` '''" + value: { string_value: " \\ \? \" \' ` " } + } + test { + name: "triple_double_quoted_escaped_punctuation" + expr: '""" \\\\ \\\? \\\" \\\' \\` """' + value: { string_value: " \\ \? \" \' ` " } + } + test { + name: "triple_single_quoted_unescaped_punctuation" + expr: "''' ? \" \' ` '''" + value: { string_value: " \? \" \' ` " } + } + test { + name: "triple_double_quoted_unescaped_punctuation" + expr: '""" ? \" \' ` """' + value: { string_value: " \? \" \' ` " } + } + + test { + name: "single_quoted_escaped_special_control_characters" + expr: "' \\a \\b \\f \\t \\v '" + value: { string_value: " \a \b \f \t \v " } + } + test { + name: "double_quoted_escaped_special_control_characters" + expr: '" \\a \\b \\f \\t \\v "' + value: { string_value: " \a \b \f \t \v " } + } + test { + name: "single_quoted_unescaped_special_control_characters" + expr: "' \a \b \f \t \v '" + value: { string_value: " \a \b \f \t \v " } + } + test { + name: "double_quoted_unescaped_special_control_characters" + expr: '" \a \b \f \t \v "' + value: { string_value: " \a \b \f \t \v " } + } + + test { + name: "triple_single_quoted_escaped_special_control_characters" + expr: "''' \\a \\b \\f \\t \\v '''" + value: { string_value: " \a \b \f \t \v " } + } + test { + name: "triple_double_quoted_escaped_special_control_characters" + expr: '""" \\a \\b \\f \\t \\v """' + value: { string_value: " \a \b \f \t \v " } + } + test { + name: "triple_single_quoted_unescaped_special_control_characters" + expr: "''' \a \b \f \t \v '''" + value: { string_value: " \a \b \f \t \v " } + } + test { + name: "triple_double_quoted_unescaped_special_control_characters" + expr: '""" \a \b \f \t \v """' + value: { string_value: " \a \b \f \t \v " } + } + + test { + name: "single_quoted_escaped_line_feed" + expr: "' \\n '" + value: { string_value: " \n " } + } + test { + name: "double_quoted_escaped_line_feed" + expr: '" \\n "' + value: { string_value: " \n " } + } + + test { + name: "triple_single_quoted_escaped_line_feed" + expr: "''' \\n '''" + value: { string_value: " \n " } + } + test { + name: "triple_double_quoted_escaped_line_feed" + expr: '""" \\n """' + value: { string_value: " \n " } + } + test { + name: "triple_single_quoted_unescaped_line_feed" + expr: "''' \n '''" + value: { string_value: " \n " } + } + test { + name: "triple_double_quoted_unescaped_line_feed" + expr: '""" \n """' + value: { string_value: " \n " } + } + + test { + name: "single_quoted_escaped_carriage_return" + expr: "' \\r '" + value: { string_value: " \r " } + } + test { + name: "double_quoted_escaped_carriage_return" + expr: '" \\r "' + value: { string_value: " \r " } + } + + test { + name: "triple_single_quoted_escaped_carriage_return" + expr: "''' \\r '''" + value: { string_value: " \r " } + } + test { + name: "triple_double_quoted_escaped_carriage_return" + expr: '""" \\r """' + value: { string_value: " \r " } + } + + # See https://github.com/google/cel-spec/issues/490 + # test { + # name: "triple_single_quoted_unescaped_carriage_return" + # expr: "''' \r '''" + # value: { string_value: " \r " } + # } + # test { + # name: "triple_double_quoted_unescaped_carriage_return" + # expr: '""" \r """' + # value: { string_value: " \r " } + # } + + test { + name: "single_quoted_escaped_windows_line_end" + expr: "' \\r\\n '" + value: { string_value: " \r\n " } + } + test { + name: "double_quoted_escaped_windows_line_end" + expr: '" \\r\\n "' + value: { string_value: " \r\n " } + } + + test { + name: "triple_single_quoted_escaped_windows_line_end" + expr: "''' \\r\\n '''" + value: { string_value: " \r\n " } + } + test { + name: "triple_double_quoted_escaped_windows_line_end" + expr: '""" \\r\\n """' + value: { string_value: " \r\n " } + } + + # See https://github.com/google/cel-spec/issues/490 + # test { + # name: "triple_single_quoted_unescaped_windows_line_end" + # expr: "''' \r\n '''" + # value: { string_value: " \r\n " } + # } + # test { + # name: "triple_double_quoted_unescaped_windows_line_end" + # expr: '""" \r\n """' + # value: { string_value: " \r\n " } + # } + + test { + name: "single_quoted_escaped_all_control_characters" + expr: "' \\x01 \\x02 \\x03 \\x04 \\x05 \\x06 \\x07 \\x08 \\x09 \\x0B \\x0C \\x0E \\x0F \\x10 \\x11 \\x12 \\x13 \\x14 \\x15 \\x16 \\x17 \\x18 \\x19 \\x1A \\x1B \\x1C \\x1D \\x1E \\x1f \\x7F '" + value: { string_value: " \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F " } + } + test { + name: "double_quoted_escaped_all_control_characters" + expr: '" \\x01 \\x02 \\x03 \\x04 \\x05 \\x06 \\x07 \\x08 \\x09 \\x0B \\x0C \\x0E \\x0F \\x10 \\x11 \\x12 \\x13 \\x14 \\x15 \\x16 \\x17 \\x18 \\x19 \\x1A \\x1B \\x1C \\x1D \\x1E \\x1f \\x7F "' + value: { string_value: " \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F " } + } + test { + name: "single_quoted_unescaped_all_control_characters" + expr: "' \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F '" + value: { string_value: " \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F " } + } + test { + name: "double_quoted_unescaped_all_control_characters" + expr: '" \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F "' + value: { string_value: " \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F " } + } + + test { + name: "triple_single_quoted_escaped_all_control_characters" + expr: "''' \\x01 \\x02 \\x03 \\x04 \\x05 \\x06 \\x07 \\x08 \\x09 \\x0B \\x0C \\x0E \\x0F \\x10 \\x11 \\x12 \\x13 \\x14 \\x15 \\x16 \\x17 \\x18 \\x19 \\x1A \\x1B \\x1C \\x1D \\x1E \\x1f \\x7F '''" + value: { string_value: " \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F " } + } + test { + name: "triple_double_quoted_escaped_all_control_characters" + expr: '""" \\x01 \\x02 \\x03 \\x04 \\x05 \\x06 \\x07 \\x08 \\x09 \\x0B \\x0C \\x0E \\x0F \\x10 \\x11 \\x12 \\x13 \\x14 \\x15 \\x16 \\x17 \\x18 \\x19 \\x1A \\x1B \\x1C \\x1D \\x1E \\x1f \\x7F """' + value: { string_value: " \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F " } + } + test { + name: "triple_single_quoted_unescaped_all_control_characters" + expr: "''' \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F '''" + value: { string_value: " \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F " } + } + test { + name: "triple_double_quoted_unescaped_all_control_characters" + expr: '""" \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F """' + value: { string_value: " \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F " } + } + + test { + name: "single_quoted_octal_escapes" + expr: "' \\000 \\012 \\177 '" + value: { string_value: " \x00 \x0A \x7F " } + } + test { + name: "double_quoted_octal_escapes" + expr: '" \\000 \\012 \\177 "' + value: { string_value: " \x00 \x0A \x7F " } + } + test { + name: "triple_single_quoted_octal_escapes" + expr: "''' \\000 \\012 \\177 '''" + value: { string_value: " \x00 \x0A \x7F " } + } + test { + name: "triple_double_quoted_octal_escapes" + expr: '""" \\000 \\012 \\177 """' + value: { string_value: " \x00 \x0A \x7F " } + } + + test { + name: "single_quoted_lower_x_escapes" + expr: "' \\x00 \\x0A \\x7F '" + value: { string_value: " \x00 \x0A \x7F " } + } + test { + name: "double_quoted_lower_x_escapes" + expr: '" \\x00 \\x0A \\x7F "' + value: { string_value: " \x00 \x0A \x7F " } + } + test { + name: "triple_single_quoted_lower_x_escapes" + expr: "''' \\x00 \\x0A \\x7F '''" + value: { string_value: " \x00 \x0A \x7F " } + } + test { + name: "triple_double_quoted_lower_x_escapes" + expr: '""" \\x00 \\x0A \\x7F """' + value: { string_value: " \x00 \x0A \x7F " } + } + + test { + name: "single_quoted_upper_x_escapes" + expr: "' \\X00 \\X0A \\X7F '" + value: { string_value: " \x00 \x0A \x7F " } + } + test { + name: "double_quoted_upper_x_escapes" + expr: '" \\X00 \\X0A \\X7F "' + value: { string_value: " \x00 \x0A \x7F " } + } + test { + name: "triple_single_quoted_upper_x_escapes" + expr: "''' \\X00 \\X0A \\X7F '''" + value: { string_value: " \x00 \x0A \x7F " } + } + test { + name: "triple_double_quoted_upper_x_escapes" + expr: '""" \\X00 \\X0A \\X7F """' + value: { string_value: " \x00 \x0A \x7F " } + } + + test { + name: "single_quoted_lower_u_escapes" + expr: "' \\u0000 \\u000A \\u007F \\u0100 \\uFFFB '" + value: { string_value: " \x00 \x0A \x7F \u0100 \uFFFB " } + } + test { + name: "double_quoted_lower_u_escapes" + expr: '" \\u0000 \\u000A \\u007F \\u0100 \\uFFFB "' + value: { string_value: " \x00 \x0A \x7F \u0100 \uFFFB " } + } + test { + name: "triple_single_quoted_lower_u_escapes" + expr: "''' \\u0000 \\u000A \\u007F \\u0100 \\uFFFB '''" + value: { string_value: " \x00 \x0A \x7F \u0100 \uFFFB " } + } + test { + name: "triple_double_quoted_lower_u_escapes" + expr: '""" \\u0000 \\u000A \\u007F \\u0100 \\uFFFB """' + value: { string_value: " \x00 \x0A \x7F \u0100 \uFFFB " } + } + + test { + name: "single_quoted_upper_u_escapes" + expr: "' \\U00000000 \\U0000000A \\U0000007F \\U00000100 \\U0000FFFB \\U00010000 \\U0001F62C '" + value: { string_value: " \x00 \x0A \x7F \U00000100 \U0000FFFB \U00010000 \U0001F62C " } + } + test { + name: "double_quoted_upper_u_escapes" + expr: '" \\U00000000 \\U0000000A \\U0000007F \\U00000100 \\U0000FFFB \\U00010000 \\U0001F62C "' + value: { string_value: " \x00 \x0A \x7F \U00000100 \U0000FFFB \U00010000 \U0001F62C " } + } + test { + name: "triple_single_quoted_upper_u_escapes" + expr: "''' \\U00000000 \\U0000000A \\U0000007F \\U00000100 \\U0000FFFB \\U00010000 \\U0001F62C '''" + value: { string_value: " \x00 \x0A \x7F \U00000100 \U0000FFFB \U00010000 \U0001F62C " } + } + test { + name: "triple_double_quoted_upper_u_escapes" + expr: '""" \\U00000000 \\U0000000A \\U0000007F \\U00000100 \\U0000FFFB \\U00010000 \\U0001F62C """' + value: { string_value: " \x00 \x0A \x7F \U00000100 \U0000FFFB \U00010000 \U0001F62C " } + } + + test { + name: "mixed_case_hex_single_quoted_escapes" + expr: "' \\x4a \\x4B \\X4c \\X4D \\u01aB \\U000001aB '" + value: { string_value: " \x4a \x4B \x4c \x4D \u01aB \U000001aB " } + } + test { + name: "mixed_case_hex_double_quoted_escapes" + expr: '" \\x4a \\x4B \\X4c \\X4D \\u01aB \\U000001aB "' + value: { string_value: " \x4a \x4B \x4c \x4D \u01aB \U000001aB " } + } + test { + name: "mixed_case_hex_triple_single_quoted_escapes" + expr: "''' \\x4a \\x4B \\X4c \\X4D \\u01aB \\U000001aB '''" + value: { string_value: " \x4a \x4B \x4c \x4D \u01aB \U000001aB " } + } + test { + name: "mixed_case_hex_triple_double_quoted_escapes" + expr: '""" \\x4a \\x4B \\X4c \\X4D \\u01aB \\U000001aB """' + value: { string_value: " \x4a \x4B \x4c \x4D \u01aB \U000001aB " } + } + + test { + name: "unassigned_code_point_single_quoted_escapes" + expr: "' \\U00088888 '" + value: { string_value: " \U00088888 " } + } + test { + name: "unassigned_code_point_double_quoted_escapes" + expr: '" \\U00088888 "' + value: { string_value: " \U00088888 " } + } + test { + name: "unassigned_code_point_triple_single_quoted_escapes" + expr: "''' \\U00088888 '''" + value: { string_value: " \U00088888 " } + } + test { + name: "unassigned_code_point_triple_double_quoted_escapes" + expr: '""" \\U00088888 """' + value: { string_value: " \U00088888 " } + } + + test { + name: "unassigned_code_point_single_quoted_unescaped" + expr: "' \U00088888 '" + value: { string_value: " \U00088888 " } + } + test { + name: "unassigned_code_point_double_quoted_unescaped" + expr: '" \U00088888 "' + value: { string_value: " \U00088888 " } + } + test { + name: "unassigned_code_point_triple_single_quoted_unescaped" + expr: "''' \U00088888 '''" + value: { string_value: " \U00088888 " } + } + test { + name: "unassigned_code_point_triple_double_quoted_unescaped" + expr: '""" \U00088888 """' + value: { string_value: " \U00088888 " } + } + + test { + name: "raw_single_quoted_escapes" + expr: "r' \\\\ \\\? \\\" \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 '" + value: { string_value: " \\\\ \\\? \\\" \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " } + } + test { + name: "raw_double_quoted_escapes" + expr: 'r" \\\\ \\\? \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 "' + value: { string_value: " \\\\ \\\? \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " } + } + test { + name: "raw_triple_single_quoted_escapes" + expr: "r''' \\\\ \\\? \\\" \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 '''" + value: { string_value: " \\\\ \\\? \\\" \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " } + } + test { + name: "raw_triple_double_quoted_escapes" + expr: 'r""" \\\\ \\\? \\\" \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 """' + value: { string_value: " \\\\ \\\? \\\" \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " } + } + + test { + name: "upper_raw_single_quoted_escapes" + expr: "R' \\\\ \\\? \\\" \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 '" + value: { string_value: " \\\\ \\\? \\\" \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " } + } + test { + name: "upper_raw_double_quoted_escapes" + expr: 'R" \\\\ \\\? \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 "' + value: { string_value: " \\\\ \\\? \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " } + } + test { + name: "upper_raw_triple_single_quoted_escapes" + expr: "R''' \\\\ \\\? \\\" \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 '''" + value: { string_value: " \\\\ \\\? \\\" \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " } + } + test { + name: "upper_raw_triple_double_quoted_escapes" + expr: 'R""" \\\\ \\\? \\\" \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 """' + value: { string_value: " \\\\ \\\? \\\" \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " } + } +} +section { + name: "bytes_literals" + description: "Check that bytes literals are properly parsed" + test { + name: "single_quoted" + expr: "b'hello'" + value: { bytes_value: "hello" } + } + test { + name: "double_quoted" + expr: 'b"hello"' + value: { bytes_value: "hello" } + } + test { + name: "triple_single_quoted" + expr: "b'''hello'''" + value: { bytes_value: "hello" } + } + test { + name: "triple_double_quoted" + expr: 'b"""hello"""' + value: { bytes_value: "hello" } + } + + test { + name: "single_quoted_escaped_punctuation" + expr: "b' \\\\ \\\? \\\" \\\' \\` '" + value: { bytes_value: " \\ \? \" \' ` " } + } + test { + name: "double_quoted_escaped_punctuation" + expr: 'b" \\\\ \\\? \\\" \\\' \\` "' + value: { bytes_value: " \\ \? \" \' ` " } + } + test { + name: "triple_single_quoted_escaped_punctuation" + expr: "b''' \\\\ \\\? \\\" \\\' \\` '''" + value: { bytes_value: " \\ \? \" \' ` " } + } + test { + name: "triple_double_quoted_escaped_punctuation" + expr: 'b""" \\\\ \\\? \\\" \\\' \\` """' + value: { bytes_value: " \\ \? \" \' ` " } + } + test { + name: "triple_single_quoted_unescaped_punctuation" + expr: "b''' ? \" \' ` '''" + value: { bytes_value: " \? \" \' ` " } + } + test { + name: "triple_double_quoted_unescaped_punctuation" + expr: 'b""" ? \" \' ` """' + value: { bytes_value: " \? \" \' ` " } + } + + test { + name: "single_quoted_escaped_special_control_characters" + expr: "b' \\a \\b \\f \\t \\v '" + value: { bytes_value: " \a \b \f \t \v " } + } + test { + name: "double_quoted_escaped_special_control_characters" + expr: 'b" \\a \\b \\f \\t \\v "' + value: { bytes_value: " \a \b \f \t \v " } + } + test { + name: "single_quoted_unescaped_special_control_characters" + expr: "b' \a \b \f \t \v '" + value: { bytes_value: " \a \b \f \t \v " } + } + test { + name: "double_quoted_unescaped_special_control_characters" + expr: 'b" \a \b \f \t \v "' + value: { bytes_value: " \a \b \f \t \v " } + } + + test { + name: "triple_single_quoted_escaped_special_control_characters" + expr: "b''' \\a \\b \\f \\t \\v '''" + value: { bytes_value: " \a \b \f \t \v " } + } + test { + name: "triple_double_quoted_escaped_special_control_characters" + expr: 'b""" \\a \\b \\f \\t \\v """' + value: { bytes_value: " \a \b \f \t \v " } + } + test { + name: "triple_single_quoted_unescaped_special_control_characters" + expr: "b''' \a \b \f \t \v '''" + value: { bytes_value: " \a \b \f \t \v " } + } + test { + name: "triple_double_quoted_unescaped_special_control_characters" + expr: 'b""" \a \b \f \t \v """' + value: { bytes_value: " \a \b \f \t \v " } + } + + test { + name: "single_quoted_escaped_line_feed" + expr: "b' \\n '" + value: { bytes_value: " \n " } + } + test { + name: "double_quoted_escaped_line_feed" + expr: 'b" \\n "' + value: { bytes_value: " \n " } + } + + test { + name: "triple_single_quoted_escaped_line_feed" + expr: "b''' \\n '''" + value: { bytes_value: " \n " } + } + test { + name: "triple_double_quoted_escaped_line_feed" + expr: 'b""" \\n """' + value: { bytes_value: " \n " } + } + test { + name: "triple_single_quoted_unescaped_line_feed" + expr: "b''' \n '''" + value: { bytes_value: " \n " } + } + test { + name: "triple_double_quoted_unescaped_line_feed" + expr: 'b""" \n """' + value: { bytes_value: " \n " } + } + + test { + name: "single_quoted_escaped_carriage_return" + expr: "b' \\r '" + value: { bytes_value: " \r " } + } + test { + name: "double_quoted_escaped_carriage_return" + expr: 'b" \\r "' + value: { bytes_value: " \r " } + } + + test { + name: "triple_single_quoted_escaped_carriage_return" + expr: "b''' \\r '''" + value: { bytes_value: " \r " } + } + test { + name: "triple_double_quoted_escaped_carriage_return" + expr: 'b""" \\r """' + value: { bytes_value: " \r " } + } + + # See https://github.com/google/cel-spec/issues/490 + # test { + # name: "triple_single_quoted_unescaped_carriage_return" + # expr: "b''' \r '''" + # value: { bytes_value: " \r " } + # } + # test { + # name: "triple_double_quoted_unescaped_carriage_return" + # expr: 'b""" \r """' + # value: { bytes_value: " \r " } + # } + + test { + name: "single_quoted_escaped_windows_line_end" + expr: "b' \\r\\n '" + value: { bytes_value: " \r\n " } + } + test { + name: "double_quoted_escaped_windows_line_end" + expr: 'b" \\r\\n "' + value: { bytes_value: " \r\n " } + } + + test { + name: "triple_single_quoted_escaped_windows_line_end" + expr: "b''' \\r\\n '''" + value: { bytes_value: " \r\n " } + } + test { + name: "triple_double_quoted_escaped_windows_line_end" + expr: 'b""" \\r\\n """' + value: { bytes_value: " \r\n " } + } + + # See https://github.com/google/cel-spec/issues/490 + # test { + # name: "triple_single_quoted_unescaped_windows_line_end" + # expr: "b''' \r\n '''" + # value: { bytes_value: " \r\n " } + # } + # test { + # name: "triple_double_quoted_unescaped_windows_line_end" + # expr: 'b""" \r\n """' + # value: { bytes_value: " \r\n " } + # } + + test { + name: "single_quoted_escaped_all_control_characters" + expr: "b' \\x01 \\x02 \\x03 \\x04 \\x05 \\x06 \\x07 \\x08 \\x09 \\x0B \\x0C \\x0E \\x0F \\x10 \\x11 \\x12 \\x13 \\x14 \\x15 \\x16 \\x17 \\x18 \\x19 \\x1A \\x1B \\x1C \\x1D \\x1E \\x1f \\x7F '" + value: { bytes_value: " \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F " } + } + test { + name: "double_quoted_escaped_all_control_characters" + expr: 'b" \\x01 \\x02 \\x03 \\x04 \\x05 \\x06 \\x07 \\x08 \\x09 \\x0B \\x0C \\x0E \\x0F \\x10 \\x11 \\x12 \\x13 \\x14 \\x15 \\x16 \\x17 \\x18 \\x19 \\x1A \\x1B \\x1C \\x1D \\x1E \\x1f \\x7F "' + value: { bytes_value: " \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F " } + } + test { + name: "single_quoted_unescaped_all_control_characters" + expr: "b' \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F '" + value: { bytes_value: " \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F " } + } + test { + name: "double_quoted_unescaped_all_control_characters" + expr: 'b" \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F "' + value: { bytes_value: " \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F " } + } + + test { + name: "triple_single_quoted_escaped_all_control_characters" + expr: "b''' \\x01 \\x02 \\x03 \\x04 \\x05 \\x06 \\x07 \\x08 \\x09 \\x0B \\x0C \\x0E \\x0F \\x10 \\x11 \\x12 \\x13 \\x14 \\x15 \\x16 \\x17 \\x18 \\x19 \\x1A \\x1B \\x1C \\x1D \\x1E \\x1f \\x7F '''" + value: { bytes_value: " \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F " } + } + test { + name: "triple_double_quoted_escaped_all_control_characters" + expr: 'b""" \\x01 \\x02 \\x03 \\x04 \\x05 \\x06 \\x07 \\x08 \\x09 \\x0B \\x0C \\x0E \\x0F \\x10 \\x11 \\x12 \\x13 \\x14 \\x15 \\x16 \\x17 \\x18 \\x19 \\x1A \\x1B \\x1C \\x1D \\x1E \\x1f \\x7F """' + value: { bytes_value: " \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F " } + } + test { + name: "triple_single_quoted_unescaped_all_control_characters" + expr: "b''' \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F '''" + value: { bytes_value: " \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F " } + } + test { + name: "triple_double_quoted_unescaped_all_control_characters" + expr: 'b""" \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F """' + value: { bytes_value: " \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0B \x0C \x0E \x0F \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1A \x1B \x1C \x1D \x1E \x1f \x7F " } + } + + test { + name: "single_quoted_octal_escapes" + expr: "b' \\000 \\012 \\177 \\377 '" + value: { bytes_value: " \x00 \x0A \x7F \xFF " } + } + test { + name: "double_quoted_octal_escapes" + expr: 'b" \\000 \\012 \\177 \\377 "' + value: { bytes_value: " \x00 \x0A \x7F \xFF " } + } + test { + name: "triple_single_quoted_octal_escapes" + expr: "b''' \\000 \\012 \\177 \\377 '''" + value: { bytes_value: " \x00 \x0A \x7F \xFF " } + } + test { + name: "triple_double_quoted_octal_escapes" + expr: 'b""" \\000 \\012 \\177 \\377 """' + value: { bytes_value: " \x00 \x0A \x7F \xFF " } + } + + test { + name: "single_quoted_lower_x_escapes" + expr: "b' \\x00 \\x0A \\x7F \\xFF '" + value: { bytes_value: " \x00 \x0A \x7F \xFF " } + } + test { + name: "double_quoted_lower_x_escapes" + expr: 'b" \\x00 \\x0A \\x7F \\xFF "' + value: { bytes_value: " \x00 \x0A \x7F \xFF " } + } + test { + name: "triple_single_quoted_lower_x_escapes" + expr: "b''' \\x00 \\x0A \\x7F \\xFF '''" + value: { bytes_value: " \x00 \x0A \x7F \xFF " } + } + test { + name: "triple_double_quoted_lower_x_escapes" + expr: 'b""" \\x00 \\x0A \\x7F \\xFF """' + value: { bytes_value: " \x00 \x0A \x7F \xFF " } + } + + test { + name: "single_quoted_upper_x_escapes" + expr: "b' \\X00 \\X0A \\X7F \\XFF '" + value: { bytes_value: " \x00 \x0A \x7F \xFF " } + } + test { + name: "double_quoted_upper_x_escapes" + expr: 'b" \\X00 \\X0A \\X7F \\XFF "' + value: { bytes_value: " \x00 \x0A \x7F \xFF " } + } + test { + name: "triple_single_quoted_upper_x_escapes" + expr: "b''' \\X00 \\X0A \\X7F \\XFF '''" + value: { bytes_value: " \x00 \x0A \x7F \xFF " } + } + test { + name: "triple_double_quoted_upper_x_escapes" + expr: 'b""" \\X00 \\X0A \\X7F \\XFF """' + value: { bytes_value: " \x00 \x0A \x7F \xFF " } + } + + test { + name: "mixed_case_hex_single_quoted_escapes" + expr: "B' \\x4a \\x4B \\X4c \\X4D '" + value: { bytes_value: " \x4a \x4B \x4c \x4D " } + } + test { + name: "mixed_case_hex_double_quoted_escapes" + expr: 'B" \\x4a \\x4B \\X4c \\X4D "' + value: { bytes_value: " \x4a \x4B \x4c \x4D " } + } + test { + name: "mixed_case_hex_triple_single_quoted_escapes" + expr: "B''' \\x4a \\x4B \\X4c \\X4D '''" + value: { bytes_value: " \x4a \x4B \x4c \x4D " } + } + test { + name: "mixed_case_hex_triple_double_quoted_escapes" + expr: 'B""" \\x4a \\x4B \\X4c \\X4D """' + value: { bytes_value: " \x4a \x4B \x4c \x4D " } + } + + test { + name: "raw_single_quoted_escapes" + expr: "br' \\\\ \\\? \\\" \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 '" + value: { bytes_value: " \\\\ \\\? \\\" \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " } + } + test { + name: "raw_double_quoted_escapes" + expr: 'br" \\\\ \\\? \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 "' + value: { bytes_value: " \\\\ \\\? \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " } + } + test { + name: "raw_triple_single_quoted_escapes" + expr: "br''' \\\\ \\\? \\\" \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 '''" + value: { bytes_value: " \\\\ \\\? \\\" \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " } + } + test { + name: "raw_triple_double_quoted_escapes" + expr: 'br""" \\\\ \\\? \\\" \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 """' + value: { bytes_value: " \\\\ \\\? \\\" \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " } + } + + test { + name: "upper_raw_single_quoted_escapes" + expr: "bR' \\\\ \\\? \\\" \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 '" + value: { bytes_value: " \\\\ \\\? \\\" \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " } + } + test { + name: "upper_raw_double_quoted_escapes" + expr: 'bR" \\\\ \\\? \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 "' + value: { bytes_value: " \\\\ \\\? \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " } + } + test { + name: "upper_raw_triple_single_quoted_escapes" + expr: "bR''' \\\\ \\\? \\\" \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 '''" + value: { bytes_value: " \\\\ \\\? \\\" \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " } + } + test { + name: "upper_raw_triple_double_quoted_escapes" + expr: 'bR""" \\\\ \\\? \\\" \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 """' + value: { bytes_value: " \\\\ \\\? \\\" \\\' \\` \\a \\b \\f \\t \\v \\n \\r \\000 \\x00 \\X00 \\u0000 \\U00000000 " } + } +} +section { + name: "whitespace" + description: "Check that whitespace is ignored by the grammar." + test { + name: "spaces" + description: "Check that spaces are ignored." + expr: "[ . cel. expr .conformance. proto3. TestAllTypes { single_int64 : int ( 17 ) } . single_int64 ] [ 0 ] == ( 18 - 1 ) && ! false ? 1 : 2" + value { int64_value: 1 } + } + test { + name: "tabs" + description: "Check that tabs (`\\t`) are ignored." + expr: "[\t.\tcel.\texpr\t.conformance.\tproto3.\tTestAllTypes\t{\tsingle_int64\t:\tint\t(\t17\t)\t}\t.\tsingle_int64\t]\t[\t0\t]\t==\t(\t18\t-\t1\t)\t&&\t!\tfalse\t?\t1\t:\t2" + value { int64_value: 1 } + } + test { + name: "new_lines" + description: "Check that new lines (`\\n`) are ignored." + expr: "[\n.\ncel.\nexpr\n.conformance.\nproto3.\nTestAllTypes\n{\nsingle_int64\n:\nint\n(\n17\n)\n}\n.\nsingle_int64\n]\n[\n0\n]\n==\n(\n18\n-\n1\n)\n&&\n!\nfalse\n?\n1\n:\n2" + value { int64_value: 1 } + } + test { + name: "new_pages" + description: "Check that new pages (`\\f`) are ignored." + expr: "[\f.\fcel.\fexpr\f.conformance.\fproto3.\fTestAllTypes\f{\fsingle_int64\f:\fint\f(\f17\f)\f}\f.\fsingle_int64\f]\f[\f0\f]\f==\f(\f18\f-\f1\f)\f&&\f!\ffalse\f?\f1\f:\f2" + value { int64_value: 1 } + } + test { + name: "carriage_returns" + description: "Check that carriage returns (`\\r`) are ignored." + expr: "[\r.\rcel.\rexpr\r.conformance.\rproto3.\rTestAllTypes\r{\rsingle_int64\r:\rint\r(\r17\r)\r}\r.\rsingle_int64\r]\r[\r0\r]\r==\r(\r18\r-\r1\r)\r&&\r!\rfalse\r?\r1\r:\r2" + value { int64_value: 1 } + } +} +section { + name: "comments" + description: "Check that comments are ignored by the grammar. Note that carriage returns alone cannot terminate comments." + test { + name: "new_line_terminated" + description: "Check that new-line-terminated comments are ignored." + expr: "[// @\n.// @\ncel.// @\nexpr// @\n.conformance.// @\nproto3.// @\nTestAllTypes// @\n{// @\nsingle_int64// @\n:// @\nint// @\n(// @\n17// @\n)// @\n}// @\n.// @\nsingle_int64// @\n]// @\n[// @\n0// @\n]// @\n==// @\n(// @\n18// @\n-// @\n1// @\n)// @\n&&// @\n!// @\nfalse// @\n?// @\n1// @\n:// @\n2" + value { int64_value: 1 } + } +} +section { + name: "selectors" + description: "Check that reserved identifiers are permitted as selectors as long as they are not language keywords" + test { + name: "as" + description: "Check that `as` can be used as a selector." + expr: "{ 'as': 1 }.as" + value { int64_value: 1 } + } + test { + name: "break" + description: "Check that `break` can be used as a selector." + expr: "{ 'break': 1 }.break" + value { int64_value: 1 } + } + test { + name: "const" + description: "Check that `const` can be used as a selector." + expr: "{ 'const': 1 }.const" + value { int64_value: 1 } + } + test { + name: "continue" + description: "Check that `continue` can be used as a selector." + expr: "{ 'continue': 1 }.continue" + value { int64_value: 1 } + } + test { + name: "else" + description: "Check that `else` can be used as a selector." + expr: "{ 'else': 1 }.else" + value { int64_value: 1 } + } + test { + name: "for" + description: "Check that `for` can be used as a selector." + expr: "{ 'for': 1 }.for" + value { int64_value: 1 } + } + test { + name: "function" + description: "Check that `function` can be used as a selector." + expr: "{ 'function': 1 }.function" + value { int64_value: 1 } + } + test { + name: "if" + description: "Check that `if` can be used as a selector." + expr: "{ 'if': 1 }.if" + value { int64_value: 1 } + } + test { + name: "import" + description: "Check that `import` can be used as a selector." + expr: "{ 'import': 1 }.import" + value { int64_value: 1 } + } + test { + name: "let" + description: "Check that `let` can be used as a selector." + expr: "{ 'let': 1 }.let" + value { int64_value: 1 } + } + test { + name: "loop" + description: "Check that `loop` can be used as a selector." + expr: "{ 'loop': 1 }.loop" + value { int64_value: 1 } + } + test { + name: "package" + description: "Check that `package` can be used as a selector." + expr: "{ 'package': 1 }.package" + value { int64_value: 1 } + } + test { + name: "namespace" + description: "Check that `namespace` can be used as a selector." + expr: "{ 'namespace': 1 }.namespace" + value { int64_value: 1 } + } + test { + name: "return" + description: "Check that `return` can be used as a selector." + expr: "{ 'return': 1 }.return" + value { int64_value: 1 } + } + test { + name: "var" + description: "Check that `var` can be used as a selector." + expr: "{ 'var': 1 }.var" + value { int64_value: 1 } + } + test { + name: "void" + description: "Check that `void` can be used as a selector." + expr: "{ 'void': 1 }.void" + value { int64_value: 1 } + } + test { + name: "while" + description: "Check that `while` can be used as a selector." + expr: "{ 'while': 1 }.while" + value { int64_value: 1 } + } +} +section { + name: "receiver_function_names" + description: "Check that reserved identifiers are permitted as receiver function names as long as they are not language keywords" + test { + name: "as" + description: "Check that `as` can be used as a receiver function." + expr: "a.as() || true" + disable_check: true + value { bool_value: true } + } + test { + name: "break" + description: "Check that `break` can be used as a receiver function." + expr: "a.break() || true" + disable_check: true + value { bool_value: true } + } + test { + name: "const" + description: "Check that `const` can be used as a receiver function." + expr: "a.const() || true" + disable_check: true + value { bool_value: true } + } + test { + name: "continue" + description: "Check that `continue` can be used as a receiver function." + expr: "a.continue() || true" + disable_check: true + value { bool_value: true } + } + test { + name: "else" + description: "Check that `else` can be used as a receiver function." + expr: "a.else() || true" + disable_check: true + value { bool_value: true } + } + test { + name: "for" + description: "Check that `for` can be used as a receiver function." + expr: "a.for() || true" + disable_check: true + value { bool_value: true } + } + test { + name: "function" + description: "Check that `function` can be used as a receiver function." + expr: "a.function() || true" + disable_check: true + value { bool_value: true } + } + test { + name: "if" + description: "Check that `if` can be used as a receiver function." + expr: "a.if() || true" + disable_check: true + value { bool_value: true } + } + test { + name: "import" + description: "Check that `import` can be used as a receiver function." + expr: "a.import() || true" + disable_check: true + value { bool_value: true } + } + test { + name: "let" + description: "Check that `let` can be used as a receiver function." + expr: "a.let() || true" + disable_check: true + value { bool_value: true } + } + test { + name: "loop" + description: "Check that `loop` can be used as a receiver function." + expr: "a.loop() || true" + disable_check: true + value { bool_value: true } + } + test { + name: "package" + description: "Check that `package` can be used as a receiver function." + expr: "a.package() || true" + disable_check: true + value { bool_value: true } + } + test { + name: "namespace" + description: "Check that `namespace` can be used as a receiver function." + expr: "a.namespace() || true" + disable_check: true + value { bool_value: true } + } + test { + name: "return" + description: "Check that `return` can be used as a receiver function." + expr: "a.return() || true" + disable_check: true + value { bool_value: true } + } + test { + name: "var" + description: "Check that `var` can be used as a receiver function." + expr: "a.var() || true" + disable_check: true + value { bool_value: true } + } + test { + name: "void" + description: "Check that `void` can be used as a receiver function." + expr: "a.void() || true" + disable_check: true + value { bool_value: true } + } + test { + name: "while" + description: "Check that `while` can be used as a receiver function." + expr: "a.while() || true" + disable_check: true + value { bool_value: true } + } +} +section { + name: "struct_field_names" + description: "Check that reserved identifiers are permitted as struct field names as long as they are not language keywords" + test { + name: "as" + description: "Check that `as` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ as: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { as: true } + } + } + } + test { + name: "break" + description: "Check that `break` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ break: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { break: true } + } + } + } + test { + name: "const" + description: "Check that `const` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ const: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { const: true } + } + } + } + test { + name: "continue" + description: "Check that `continue` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ continue: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { continue: true } + } + } + } + test { + name: "else" + description: "Check that `else` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ else: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { else: true } + } + } + } + test { + name: "for" + description: "Check that `for` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ for: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { for: true } + } + } + } + test { + name: "function" + description: "Check that `function` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ function: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { function: true } + } + } + } + test { + name: "if" + description: "Check that `if` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ if: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { if: true } + } + } + } + test { + name: "import" + description: "Check that `import` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ import: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { import: true } + } + } + } + test { + name: "let" + description: "Check that `let` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ let: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { let: true } + } + } + } + test { + name: "loop" + description: "Check that `loop` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ loop: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { loop: true } + } + } + } + test { + name: "package" + description: "Check that `package` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ package: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { package: true } + } + } + } + test { + name: "namespace" + description: "Check that `namespace` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ namespace: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { namespace: true } + } + } + } + test { + name: "return" + description: "Check that `return` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ return: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { return: true } + } + } + } + test { + name: "var" + description: "Check that `var` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ var: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { var: true } + } + } + } + test { + name: "void" + description: "Check that `void` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ void: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { void: true } + } + } + } + test { + name: "while" + description: "Check that `while` can be used as a struct field name." + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{ while: true }" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { while: true } + } + } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/plumbing.textproto b/packages/cel-spec/src/testdata/textproto/plumbing.textproto new file mode 100644 index 00000000..7b347aa1 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/plumbing.textproto @@ -0,0 +1,74 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: google.api.expr.test.v1.SimpleTestFile + +name: "plumbing" +description: "Check that the ConformanceService server can accept all arguments and return all responses." +section { + name: "min" + description: "Minimal programs." + test { + name: "min_program" + description: "Smallest functionality: expr in, result out." + expr: "17" + value: { int64_value: 17 } + } +} +section { + name: "eval_results" + description: "All evaluation result kinds." + test { + name: "error_result" + description: "Check that error results go through." + expr: "1 / 0" + eval_error: { + errors: { message: "foo" } + } + } + test { + name: "eval_map_results" + description: "Check that map literals results are order independent." + expr: '{"k1":"v1","k":"v"}' + value: { + map_value { + entries { + key: { string_value: "k" } + value: { string_value: "v" } + } + entries { + key: { string_value: "k1" } + value: { string_value: "v1" } + } + } + } + } +} +section { + name: "check_inputs" + description: "All inputs to Check phase." + test { + name: "skip_check" + description: "Make sure we can skip type checking." + expr: "[17, 'pancakes']" + disable_check: true + value: { + list_value { + values: { int64_value: 17 } + values: { string_value: "pancakes" } + } + } + } +} +section { + name: "eval_inputs" + description: "All inputs to Eval phase." + test { + name: "one_ignored_value_arg" + description: "Check that value bindings can be given, even if ignored." + expr: "'foo'" + bindings: { + key: "x" + value: { value: { int64_value: 17 } } + } + value: { string_value: "foo" } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/proto2.textproto b/packages/cel-spec/src/testdata/textproto/proto2.textproto new file mode 100644 index 00000000..0662b061 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/proto2.textproto @@ -0,0 +1,1229 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "proto2" +description: "Protocol buffer version 2 tests. See notes for the available set of protos for tests." + +section { + name: "literal_singular" + description: "Literals with singular fields set." + + test { + name: "int64_nocontainer" + expr: "cel.expr.conformance.proto2.TestAllTypes{single_int64: 17}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_int64: 17 } + } + } + } + + test { + name: "int32" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int32: -34}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_int32: -34 } + } + } + } + + test { + name: "int32_eq_uint" + container: "google.protobuf" + expr: "Int32Value{value: 34} == dyn(UInt64Value{value: 34u})" + value { bool_value: true } + } + + test { + name: "not_int32_eq_uint" + container: "google.protobuf" + expr: "Int32Value{value: 34} == dyn(UInt64Value{value: 18446744073709551615u})" + value { bool_value: false } + } + + test { + name: "int32_eq_double" + container: "google.protobuf" + expr: "Int32Value{value: 34} == dyn(DoubleValue{value: 34.0})" + value { bool_value: true } + } + + test { + name: "not_int32_eq_double" + container: "google.protobuf" + expr: "Int32Value{value: 34} == dyn(DoubleValue{value: -9223372036854775809.0})" + value { bool_value: false } + } + + test { + name: "int64" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int64: 17}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_int64: 17 } + } + } + } + + test { + name: "uint32" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_uint32: 1u}" + value { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_uint32: 1 } + } + } + } + + test { + name: "uint32_eq_int" + container: "google.protobuf" + expr: "UInt32Value{value: 34u} == dyn(Int64Value{value: 34})" + value { bool_value: true } + } + + test { + name: "not_uint32_eq_int" + container: "google.protobuf" + expr: "UInt32Value{value: 34u} == dyn(Int64Value{value: -1})" + value { bool_value: false } + } + + test { + name: "uint32_eq_double" + container: "google.protobuf" + expr: "UInt32Value{value: 34u} == dyn(DoubleValue{value: 34.0})" + value { bool_value: true } + } + + test { + name: "not_uint32_eq_double" + container: "google.protobuf" + expr: "UInt32Value{value: 34u} == dyn(DoubleValue{value: 18446744073709551616.0})" + value { bool_value: false } + } + + test { + name: "uint64" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_uint64: 9999u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_uint64: 9999 } + } + } + } + + test { + name: "sint32" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_sint32: -3}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_sint32: -3 } + } + } + } + + test { + name: "sint64" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_sint64: 255}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_sint64: 255 } + } + } + } + + test { + name: "fixed32" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_fixed32: 43u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_fixed32: 43 } + } + } + } + + test { + name: "fixed64" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_fixed64: 1880u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_fixed64: 1880 } + } + } + } + + test { + name: "sfixed32" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_sfixed32: -404}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_sfixed32: -404 } + } + } + } + + test { + name: "sfixed64" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_sfixed64: -1}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_sfixed64: -1 } + } + } + } + + test { + name: "float" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_float: 3.1416}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_float: 3.1416 } + } + } + } + + test { + name: "float_eq_int" + container: "google.protobuf" + expr: "FloatValue{value: 3.0} == dyn(Int64Value{value: 3})" + value { bool_value: true } + } + + test { + name: "not_float_eq_int" + container: "google.protobuf" + expr: "FloatValue{value: -1.14} == dyn(Int64Value{value: -1})" + value { bool_value: false } + } + + test { + name: "float_eq_uint" + container: "google.protobuf" + expr: "FloatValue{value: 34.0} == dyn(UInt64Value{value: 34u})" + value { bool_value: true } + } + + test { + name: "not_float_eq_uint" + container: "google.protobuf" + expr: "FloatValue{value: -1.0} == dyn(UInt64Value{value: 18446744073709551615u})" + value { bool_value: false } + } + + test { + name: "double" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_double: 6.022e23}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_double: 6.022e23 } + } + } + } + + test { + name: "bool" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_bool: true}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_bool: true } + } + } + } + + test { + name: "string" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_string: 'foo'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_string: "foo" } + } + } + } + + test { + name: "bytes" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_bytes: b'\\377'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_bytes: "\377" } + } + } + } +} + +section { + name: "literal_wellknown" + description: "Literals with well-known fields set." + + test { + name: "any" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_any: TestAllTypes{single_int32: 1}}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + single_any { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + single_int32: 1 + } + } + } + } + } + } + + test { + name: "duration" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_duration: duration('123s')}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + single_duration { + seconds: 123 + } + } + } + } + } + + test { + name: "timestamp" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_timestamp: timestamp('2009-02-13T23:31:30Z')}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + single_timestamp { + seconds: 1234567890 + } + } + } + } + } + + test { + name: "struct" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_struct: {'one': 1, 'two': 2}}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + single_struct { + fields { + key: "one" + value { number_value: 1.0 } + } + fields { + key: "two" + value { number_value: 2.0 } + } + } + } + } + } + } + + test { + name: "value" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: 'foo'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + single_value { + string_value: "foo" + } + } + } + } + } + + test { + name: "int64_wrapper" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int64_wrapper: -321}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + single_int64_wrapper { + value: -321 + } + } + } + } + } + + test { + name: "int32_wrapper" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_int32_wrapper: -456}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + single_int32_wrapper { + value: -456 + } + } + } + } + } + + test { + name: "double_wrapper" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_double_wrapper: 2.71828}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + single_double_wrapper { + value: 2.71828 + } + } + } + } + } + + test { + name: "float_wrapper" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_float_wrapper: 2.99792e8}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + single_float_wrapper { + value: 2.99792e8 + } + } + } + } + } + + test { + name: "uint64_wrapper" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_uint64_wrapper: 8675309u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + single_uint64_wrapper { + value: 8675309 + } + } + } + } + } + + test { + name: "uint32_wrapper" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_uint32_wrapper: 987u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + single_uint32_wrapper { + value: 987 + } + } + } + } + } + + test { + name: "string_wrapper" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_string_wrapper: 'hubba'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + single_string_wrapper { + value: "hubba" + } + } + } + } + } + + test { + name: "bool_wrapper" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_bool_wrapper: true}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + single_bool_wrapper { + value: true + } + } + } + } + } + + test { + name: "bytes_wrapper" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_bytes_wrapper: b'\\301\\103'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { + single_bytes_wrapper { + value: "\301\103" + } + } + } + } + } + +} + +section { + name: "singular_bind" + description: "Binding the singular fields." + + test { + name: "int32" + expr: "x.single_int32" + type_env: { + name: "x" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "x" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_int32: 17 } + } + } + } + } + value: { int64_value: 17 } + } + + test { + name: "int64" + expr: "x.single_int64" + type_env: { + name: "x" + ident { type { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "x" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { single_int64: -99 } + } + } + } + } + value: { int64_value: -99 } + } +} + +section { + name: "empty_field" + description: "Tests on empty fields." + + test { + name: "scalar_with_default" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_int32" + value: { int64_value: -32 } + } + + test { + name: "scalar_no_default" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_fixed32" + value: { uint64_value: 0 } + } + + test { + name: "nested_message" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_nested_message" + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes.NestedMessage] {} + } + } + } + + test { + name: "nested_message_subfield" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_nested_message.bb" + value: { int64_value: 0 } + } + + test { + name: "wkt" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.single_int64_wrapper" + value: { null_value: NULL_VALUE } + } + + test { + name: "repeated_scalar" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.repeated_int64" + value: { list_value: {} } + } + + test { + name: "repeated_enum" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.repeated_nested_enum" + value: { list_value: {} } + } + + test { + name: "repeated_nested" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.repeated_nested_message" + value: { list_value: {} } + } + + test { + name: "map" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{}.map_string_string" + value: { map_value: {} } + } +} +section { + name: "has" + description: "Tests for the has() macro on proto2 messages." + test { + name: "undefined" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{}.no_such_field)" + disable_check: true + eval_error: { + errors: { message: "no_such_field" } + } + } + test { + name: "repeated_none_implicit" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{}.repeated_int32)" + value { bool_value: false } + } + test { + name: "repeated_none_explicit" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{repeated_int32: []}.repeated_int32)" + value { bool_value: false } + } + test { + name: "repeated_one" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{repeated_int32: [1]}.repeated_int32)" + value { bool_value: true } + } + test { + name: "repeated_many" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{repeated_int32: [1, 2, 3]}.repeated_int32)" + value { bool_value: true } + } + test { + name: "map_none_implicit" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{}.map_string_string)" + value { bool_value: false } + } + test { + name: "map_none_explicit" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{map_string_string: {}}.map_string_string)" + value { bool_value: false } + } + test { + name: "map_one_default" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{map_string_string: {'MT': ''}}.map_string_string)" + value { bool_value: true } + } + test { + name: "map_one" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{map_string_string: {'one': 'uno'}}.map_string_string)" + value { bool_value: true } + } + test { + name: "map_many" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{map_string_string: {'one': 'uno', 'two': 'dos'}}.map_string_string)" + value { bool_value: true } + } + test { + name: "required" + container: "cel.expr.conformance.proto2" + expr: "has(TestRequired{required_int32: 4}.required_int32)" + value { bool_value: true } + } + test { + name: "optional_unset_no_default" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{}.single_sint32)" + value { bool_value: false } + } + test { + name: "optional_set_no_default" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{single_sint32: -4}.single_sint32)" + value { bool_value: true } + } + test { + name: "optional_unset_with_default" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{}.single_int32)" + value { bool_value: false } + } + test { + name: "optional_set_with_default" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{single_int32: 16}.single_int32)" + value { bool_value: true } + } + test { + name: "optional_set_to_default" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{single_int32: -32}.single_int32)" + value { bool_value: true } + } + test { + name: "optional_message_unset" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{}.standalone_message)" + value { bool_value: false } + } + test { + name: "optional_message_set" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{standalone_message: TestAllTypes.NestedMessage{}}.standalone_message)" + value { bool_value: true } + } + test { + name: "optional_enum_unset" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{}.standalone_enum)" + value { bool_value: false } + } + test { + name: "optional_enum_set" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.BAR}.standalone_enum)" + value { bool_value: true } + } + test { + name: "optional_enum_set_zero" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.FOO}.standalone_enum)" + value { bool_value: true } + } + test { + name: "oneof_unset" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{}.single_nested_message)" + value { bool_value: false } + } + test { + name: "oneof_other_set" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{single_nested_enum: TestAllTypes.NestedEnum.BAZ}.single_nested_message)" + value { bool_value: false } + } + test { + name: "oneof_set" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{single_nested_message: TestAllTypes.NestedMessage{}}.single_nested_message)" + value { bool_value: true } + } + test { + name: "oneof_set_default" + container: "cel.expr.conformance.proto2" + expr: "has(TestAllTypes{single_nested_enum: TestAllTypes.NestedEnum.FOO}.single_nested_enum)" + value { bool_value: true } + } +} +section { + name: "set_null" + test { + name: "single_message" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_nested_message: null} == TestAllTypes{}" + value: { bool_value: true } + } + test { + name: "single_any" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_any: null}.single_any" + value { null_value: NULL_VALUE } + } + test { + name: "single_value" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_value: null}.single_value" + value { null_value: NULL_VALUE } + } + test { + name: "single_duration" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_duration: null} == TestAllTypes{}" + value: { bool_value: true } + } + test { + name: "single_timestamp" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_timestamp: null} == TestAllTypes{}" + value: { bool_value: true } + } + test { + name: "single_scalar" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_bool: null} == TestAllTypes{}" + disable_check: true + eval_error: { + errors: { message: "unsupported field type" } + } + } + test { + name: "repeated" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{repeated_int32: null} == TestAllTypes{}" + disable_check: true + eval_error: { + errors: { message: "unsupported field type" } + } + } + test { + name: "map" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{map_string_string: null} == TestAllTypes{}" + disable_check: true + eval_error: { + errors: { message: "unsupported field type" } + } + } + test { + name: "list_value" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{list_value: null} == TestAllTypes{}" + disable_check: true + eval_error: { + errors: { message: "unsupported field type" } + } + } + test { + name: "single_struct" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{single_struct: null} == TestAllTypes{}" + disable_check: true + eval_error: { + errors: { message: "unsupported field type" } + } + } +} +section { + name: "quoted_fields" + test { + name: "set_field_with_quoted_name" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{`in`: true} == TestAllTypes{}" + value: { bool_value: false } + } + test { + name: "get_field_with_quoted_name" + container: "cel.expr.conformance.proto2" + expr: "TestAllTypes{`in`: true}.`in`" + value: { bool_value: true } + } +} +section: { + name: "extensions_has" + description: "Tests for presence checks on proto2 extension fields." + test: { + name: "package_scoped_int32" + expr: "has(msg.`cel.expr.conformance.proto2.int32_ext`)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.int32_ext]: 42 + } + } + } + } + } + } + test: { + name: "package_scoped_nested_ext" + expr: "has(msg.`cel.expr.conformance.proto2.nested_ext`)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.nested_ext]: {} + } + } + } + } + } + } + test: { + name: "package_scoped_test_all_types_ext" + expr: "has(msg.`cel.expr.conformance.proto2.test_all_types_ext`)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.test_all_types_ext]: {} + } + } + } + } + } + } + test: { + name: "package_scoped_test_all_types_nested_enum_ext" + expr: "has(msg.`cel.expr.conformance.proto2.nested_enum_ext`)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.nested_enum_ext]: BAR + } + } + } + } + } + } + test: { + name: "package_scoped_repeated_test_all_types" + expr: "has(msg.`cel.expr.conformance.proto2.repeated_test_all_types`)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.repeated_test_all_types]: [ { single_int64: 1 }, { single_bool: true } ] + } + } + } + } + } + } + test: { + name: "message_scoped_int64" + expr: "has(msg.`cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.int64_ext`)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.int64_ext]: 42 + } + } + } + } + } + } + test: { + name: "message_scoped_nested_ext" + expr: "has(msg.`cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_nested_ext`)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_nested_ext]: {} + } + } + } + } + } + } + test: { + name: "message_scoped_nested_enum_ext" + expr: "has(msg.`cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.nested_enum_ext`)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.nested_enum_ext]: BAR + } + } + } + } + } + } + test: { + name: "message_scoped_repeated_test_all_types" + expr: "has(msg.`cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_repeated_test_all_types`)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_repeated_test_all_types]: [ { single_int64: 1 }, { single_bool: true } ] + } + } + } + } + } + } +} +section { + name: "extensions_get" + description: "Tests for accessing proto2 extension fields." + test: { + name: "package_scoped_int32" + expr: "msg.`cel.expr.conformance.proto2.int32_ext` == 42" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.int32_ext]: 42 + } + } + } + } + } + } + test: { + name: "package_scoped_nested_ext" + expr: "msg.`cel.expr.conformance.proto2.nested_ext` == cel.expr.conformance.proto2.TestAllTypes{}" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.nested_ext]: {} + } + } + } + } + } + } + test: { + name: "package_scoped_test_all_types_ext" + expr: "msg.`cel.expr.conformance.proto2.test_all_types_ext` == cel.expr.conformance.proto2.TestAllTypes{}" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.test_all_types_ext]: {} + } + } + } + } + } + } + test: { + name: "package_scoped_test_all_types_nested_enum_ext" + expr: "msg.`cel.expr.conformance.proto2.nested_enum_ext` == cel.expr.conformance.proto2.TestAllTypes.NestedEnum.BAR" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.nested_enum_ext]: BAR + } + } + } + } + } + } + test: { + name: "package_scoped_repeated_test_all_types" + expr: "msg.`cel.expr.conformance.proto2.repeated_test_all_types` == [cel.expr.conformance.proto2.TestAllTypes{single_int64: 1}, cel.expr.conformance.proto2.TestAllTypes{single_bool: true}]" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.repeated_test_all_types]: [ { single_int64: 1 }, { single_bool: true } ] + } + } + } + } + } + } + test: { + name: "message_scoped_int64" + expr: "msg.`cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.int64_ext` == 42" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.int64_ext]: 42 + } + } + } + } + } + } + test: { + name: "message_scoped_nested_ext" + expr: "msg.`cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_nested_ext` == cel.expr.conformance.proto2.TestAllTypes{}" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_nested_ext]: {} + } + } + } + } + } + } + test: { + name: "message_scoped_nested_enum_ext" + expr: "msg.`cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.nested_enum_ext` == cel.expr.conformance.proto2.TestAllTypes.NestedEnum.BAR" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.nested_enum_ext]: BAR + } + } + } + } + } + } + test: { + name: "message_scoped_repeated_test_all_types" + expr: "msg.`cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_repeated_test_all_types` == [cel.expr.conformance.proto2.TestAllTypes{single_int64: 1}, cel.expr.conformance.proto2.TestAllTypes{single_bool: true}]" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_repeated_test_all_types]: [ { single_int64: 1 }, { single_bool: true } ] + } + } + } + } + } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/proto2_ext.textproto b/packages/cel-spec/src/testdata/textproto/proto2_ext.textproto new file mode 100644 index 00000000..efd3fa4b --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/proto2_ext.textproto @@ -0,0 +1,372 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "proto2_ext" +description: "Tests for the proto extension library." +section: { + name: "has_ext" + test: { + name: "package_scoped_int32" + expr: "proto.hasExt(msg, cel.expr.conformance.proto2.int32_ext)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.int32_ext]: 42 + } + } + } + } + } + } + test: { + name: "package_scoped_nested_ext" + expr: "proto.hasExt(msg, cel.expr.conformance.proto2.nested_ext)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.nested_ext]: {} + } + } + } + } + } + } + test: { + name: "package_scoped_test_all_types_ext" + expr: "proto.hasExt(msg, cel.expr.conformance.proto2.test_all_types_ext)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.test_all_types_ext]: {} + } + } + } + } + } + } + test: { + name: "package_scoped_test_all_types_nested_enum_ext" + expr: "proto.hasExt(msg, cel.expr.conformance.proto2.nested_enum_ext)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.nested_enum_ext]: BAR + } + } + } + } + } + } + test: { + name: "package_scoped_repeated_test_all_types" + expr: "proto.hasExt(msg, cel.expr.conformance.proto2.repeated_test_all_types)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.repeated_test_all_types]: [ { single_int64: 1 }, { single_bool: true } ] + } + } + } + } + } + } + test: { + name: "message_scoped_int64" + expr: "proto.hasExt(msg, cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.int64_ext)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.int64_ext]: 42 + } + } + } + } + } + } + test: { + name: "message_scoped_nested_ext" + expr: "proto.hasExt(msg, cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_nested_ext)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_nested_ext]: {} + } + } + } + } + } + } + test: { + name: "message_scoped_nested_enum_ext" + expr: "proto.hasExt(msg, cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.nested_enum_ext)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.nested_enum_ext]: BAR + } + } + } + } + } + } + test: { + name: "message_scoped_repeated_test_all_types" + expr: "proto.hasExt(msg, cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_repeated_test_all_types)" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_repeated_test_all_types]: [ { single_int64: 1 }, { single_bool: true } ] + } + } + } + } + } + } +} + +section: { + name: "get_ext" + test: { + name: "package_scoped_int32" + expr: "proto.getExt(msg, cel.expr.conformance.proto2.int32_ext) == 42" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.int32_ext]: 42 + } + } + } + } + } + } + test: { + name: "package_scoped_nested_ext" + expr: "proto.getExt(msg, cel.expr.conformance.proto2.nested_ext) == cel.expr.conformance.proto2.TestAllTypes{}" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.nested_ext]: {} + } + } + } + } + } + } + test: { + name: "package_scoped_test_all_types_ext" + expr: "proto.getExt(msg, cel.expr.conformance.proto2.test_all_types_ext) == cel.expr.conformance.proto2.TestAllTypes{}" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.test_all_types_ext]: {} + } + } + } + } + } + } + test: { + name: "package_scoped_test_all_types_nested_enum_ext" + expr: "proto.getExt(msg, cel.expr.conformance.proto2.nested_enum_ext) == cel.expr.conformance.proto2.TestAllTypes.NestedEnum.BAR" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.nested_enum_ext]: BAR + } + } + } + } + } + } + test: { + name: "package_scoped_repeated_test_all_types" + expr: "proto.getExt(msg, cel.expr.conformance.proto2.repeated_test_all_types) == [cel.expr.conformance.proto2.TestAllTypes{single_int64: 1}, cel.expr.conformance.proto2.TestAllTypes{single_bool: true}]" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.repeated_test_all_types]: [ { single_int64: 1 }, { single_bool: true } ] + } + } + } + } + } + } + test: { + name: "message_scoped_int64" + expr: "proto.getExt(msg, cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.int64_ext) == 42" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.int64_ext]: 42 + } + } + } + } + } + } + test: { + name: "message_scoped_nested_ext" + expr: "proto.getExt(msg, cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_nested_ext) == cel.expr.conformance.proto2.TestAllTypes{}" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_nested_ext]: {} + } + } + } + } + } + } + test: { + name: "message_scoped_nested_enum_ext" + expr: "proto.getExt(msg, cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.nested_enum_ext) == cel.expr.conformance.proto2.TestAllTypes.NestedEnum.BAR" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.nested_enum_ext]: BAR + } + } + } + } + } + } + test: { + name: "message_scoped_repeated_test_all_types" + expr: "proto.getExt(msg, cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_repeated_test_all_types) == [cel.expr.conformance.proto2.TestAllTypes{single_int64: 1}, cel.expr.conformance.proto2.TestAllTypes{single_bool: true}]" + type_env: { + name: "msg" + ident: { type: { message_type: "cel.expr.conformance.proto2.TestAllTypes" } } + } + bindings: { + key: "msg" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes]: { + [cel.expr.conformance.proto2.Proto2ExtensionScopedMessage.message_scoped_repeated_test_all_types]: [ { single_int64: 1 }, { single_bool: true } ] + } + } + } + } + } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/proto3.textproto b/packages/cel-spec/src/testdata/textproto/proto3.textproto new file mode 100644 index 00000000..2a0378d8 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/proto3.textproto @@ -0,0 +1,758 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "proto3" +description: "Protocol buffer version 3 tests. See notes for the available set of protos for tests." + +section { + name: "literal_singular" + description: "Literals with singular fields set." + + test { + name: "int64_nocontainer" + expr: "cel.expr.conformance.proto3.TestAllTypes{single_int64: 17}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_int64: 17 } + } + } + } + + test { + name: "int32" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int32: -34}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_int32: -34 } + } + } + } + + test { + name: "int64" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int64: 17}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_int64: 17 } + } + } + } + + test { + name: "uint32" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_uint32: 1u}" + value { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_uint32: 1 } + } + } + } + + test { + name: "uint64" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_uint64: 9999u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_uint64: 9999 } + } + } + } + + test { + name: "sint32" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_sint32: -3}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_sint32: -3 } + } + } + } + + test { + name: "sint64" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_sint64: 255}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_sint64: 255 } + } + } + } + + test { + name: "fixed32" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_fixed32: 43u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_fixed32: 43 } + } + } + } + + test { + name: "fixed64" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_fixed64: 1880u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_fixed64: 1880 } + } + } + } + + test { + name: "sfixed32" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_sfixed32: -404}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_sfixed32: -404 } + } + } + } + + test { + name: "sfixed64" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_sfixed64: -1}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_sfixed64: -1 } + } + } + } + + test { + name: "float" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_float: 3.1416}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_float: 3.1416 } + } + } + } + + test { + name: "double" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_double: 6.022e23}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_double: 6.022e23 } + } + } + } + + test { + name: "bool" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_bool: true}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_bool: true } + } + } + } + + test { + name: "string" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_string: 'foo'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_string: "foo" } + } + } + } + + test { + name: "bytes" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_bytes: b'\\377'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_bytes: "\377" } + } + } + } +} + +section { + name: "literal_wellknown" + description: "Literals with well-known fields set." + + test { + name: "any" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: TestAllTypes{single_int32: 1}}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_any { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_int32: 1 + } + } + } + } + } + } + + test { + name: "duration" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_duration: duration('123s')}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_duration { + seconds: 123 + } + } + } + } + } + + test { + name: "timestamp" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_timestamp: timestamp('2009-02-13T23:31:30Z')}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_timestamp { + seconds: 1234567890 + } + } + } + } + } + + test { + name: "struct" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_struct: {'one': 1, 'two': 2}}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_struct { + fields { + key: "one" + value { number_value: 1.0 } + } + fields { + key: "two" + value { number_value: 2.0 } + } + } + } + } + } + } + + test { + name: "value" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: 'foo'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_value { + string_value: "foo" + } + } + } + } + } + + test { + name: "int64_wrapper" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int64_wrapper: -321}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_int64_wrapper { + value: -321 + } + } + } + } + } + + test { + name: "int32_wrapper" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int32_wrapper: -456}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_int32_wrapper { + value: -456 + } + } + } + } + } + + test { + name: "double_wrapper" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_double_wrapper: 2.71828}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_double_wrapper { + value: 2.71828 + } + } + } + } + } + + test { + name: "float_wrapper" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_float_wrapper: 2.99792e8}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_float_wrapper { + value: 2.99792e8 + } + } + } + } + } + + test { + name: "uint64_wrapper" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_uint64_wrapper: 8675309u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_uint64_wrapper { + value: 8675309 + } + } + } + } + } + + test { + name: "uint32_wrapper" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_uint32_wrapper: 987u}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_uint32_wrapper { + value: 987 + } + } + } + } + } + + test { + name: "string_wrapper" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_string_wrapper: 'hubba'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_string_wrapper { + value: "hubba" + } + } + } + } + } + + test { + name: "bool_wrapper" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_bool_wrapper: true}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_bool_wrapper { + value: true + } + } + } + } + } + + test { + name: "bytes_wrapper" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_bytes_wrapper: b'\\301\\103'}" + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_bytes_wrapper { + value: "\301\103" + } + } + } + } + } + +} + +section { + name: "singular_bind" + description: "Binding the singular fields." + + test { + name: "int32" + expr: "x.single_int32" + type_env: { + name: "x" + ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" } } + } + bindings: { + key: "x" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_int32: 17 } + } + } + } + } + value: { int64_value: 17 } + } + + test { + name: "int64" + expr: "x.single_int64" + type_env: { + name: "x" + ident { type { message_type: "cel.expr.conformance.proto3.TestAllTypes" } } + } + bindings: { + key: "x" + value: { + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_int64: -99 } + } + } + } + } + value: { int64_value: -99 } + } +} + +section { + name: "empty_field" + description: "Tests on empty fields." + + test { + name: "scalar" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_fixed32" + value: { uint64_value: 0 } + } + + test { + name: "nested_message" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_nested_message" + value: { + object_value: { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes.NestedMessage] {} + } + } + } + + test { + name: "nested_message_subfield" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_nested_message.bb" + value: { int64_value: 0 } + } + + test { + name: "wkt" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.single_int64_wrapper" + value: { null_value: NULL_VALUE } + } + + test { + name: "repeated_scalar" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.repeated_int64" + value: { list_value: {} } + } + + test { + name: "repeated_enum" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.repeated_nested_enum" + value: { list_value: {} } + } + + test { + name: "repeated_nested" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.repeated_nested_message" + value: { list_value: {} } + } + + test { + name: "map" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.map_string_string" + value: { map_value: {} } + } +} +section { + name: "has" + description: "Tests for the has() macro on proto3 messages." + test { + name: "undefined" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{}.no_such_field)" + disable_check: true + eval_error: { + errors: { message: "no_such_field" } + } + } + test { + name: "repeated_none_implicit" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{}.repeated_int32)" + value { bool_value: false } + } + test { + name: "repeated_none_explicit" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{repeated_int32: []}.repeated_int32)" + value { bool_value: false } + } + test { + name: "repeated_one" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{repeated_int32: [1]}.repeated_int32)" + value { bool_value: true } + } + test { + name: "repeated_many" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{repeated_int32: [1, 2, 3]}.repeated_int32)" + value { bool_value: true } + } + test { + name: "map_none_implicit" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{}.map_string_string)" + value { bool_value: false } + } + test { + name: "map_none_explicit" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{map_string_string: {}}.map_string_string)" + value { bool_value: false } + } + test { + name: "map_one_default" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{map_string_string: {'MT': ''}}.map_string_string)" + value { bool_value: true } + } + test { + name: "map_one" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{map_string_string: {'one': 'uno'}}.map_string_string)" + value { bool_value: true } + } + test { + name: "map_many" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{map_string_string: {'one': 'uno', 'two': 'dos'}}.map_string_string)" + value { bool_value: true } + } + test { + name: "single_unset" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{}.single_int32)" + value { bool_value: false } + } + test { + name: "single_set" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{single_int32: 16}.single_int32)" + value { bool_value: true } + } + test { + name: "single_set_to_default" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{single_int32: 0}.single_int32)" + value { bool_value: false } + } + test { + name: "single_message_unset" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{}.standalone_message)" + value { bool_value: false } + } + test { + name: "single_message_set" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{standalone_message: TestAllTypes.NestedMessage{bb: 123}}.standalone_message)" + value { bool_value: true } + } + test { + name: "single_message_set_to_default" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{standalone_message: TestAllTypes.NestedMessage{}}.standalone_message)" + value { bool_value: true } + } + test { + name: "single_enum_unset" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{}.standalone_enum)" + value { bool_value: false } + } + test { + name: "single_enum_set" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.BAR}.standalone_enum)" + value { bool_value: true } + } + test { + name: "single_enum_set_zero" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.FOO}.standalone_enum)" + value { bool_value: false } + } + test { + name: "oneof_unset" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{}.single_nested_message)" + value { bool_value: false } + } + test { + name: "oneof_other_set" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{single_nested_enum: TestAllTypes.NestedEnum.BAZ}.single_nested_message)" + value { bool_value: false } + } + test { + name: "oneof_set" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{single_nested_message: TestAllTypes.NestedMessage{}}.single_nested_message)" + value { bool_value: true } + } + test { + name: "oneof_set_default" + container: "cel.expr.conformance.proto3" + expr: "has(TestAllTypes{single_nested_enum: TestAllTypes.NestedEnum.FOO}.single_nested_enum)" + value { bool_value: true } + } +} +section { + name: "set_null" + test { + name: "single_message" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_nested_message: null} == TestAllTypes{}" + value: { bool_value: true } + } + test { + name: "single_any" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: null}.single_any" + value { null_value: NULL_VALUE } + } + test { + name: "single_value" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: null}.single_value" + value { null_value: NULL_VALUE } + } + test { + name: "single_duration" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_duration: null} == TestAllTypes{}" + value: { bool_value: true } + } + test { + name: "single_timestamp" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_timestamp: null} == TestAllTypes{}" + value: { bool_value: true } + } + test { + name: "single_scalar" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_bool: null} == TestAllTypes{}" + disable_check: true + eval_error: { + errors: { message: "unsupported field type" } + } + } + test { + name: "repeated" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{repeated_int32: null} == TestAllTypes{}" + disable_check: true + eval_error: { + errors: { message: "unsupported field type" } + } + } + test { + name: "map" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{map_string_string: null} == TestAllTypes{}" + disable_check: true + eval_error: { + errors: { message: "unsupported field type" } + } + } + test { + name: "list_value" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{list_value: null} == TestAllTypes{}" + disable_check: true + eval_error: { + errors: { message: "unsupported field type" } + } + } + test { + name: "single_struct" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_struct: null} == TestAllTypes{}" + disable_check: true + eval_error: { + errors: { message: "unsupported field type" } + } + } +} +section { + name: "quoted_fields" + test { + name: "set_field" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{`in`: true} == TestAllTypes{}" + value: { bool_value: false } + } + test { + name: "get_field" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{`in`: true}.`in`" + value: { bool_value: true } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/string.textproto b/packages/cel-spec/src/testdata/textproto/string.textproto new file mode 100644 index 00000000..3571b11f --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/string.textproto @@ -0,0 +1,288 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: google.api.expr.test.v1.SimpleTestFile + +name: "string" +description: "Tests for string and bytes operations." +section { + name: "size" + description: "Tests for the size() function." + test { + name: "empty" + expr: "size('')" + value: { int64_value: 0 } + } + test { + name: "one_ascii" + expr: "size('A')" + value: { int64_value: 1 } + } + test { + name: "one_unicode" + expr: "size('ÿ')" + value: { int64_value: 1 } + } + test { + name: "ascii" + expr: "size('four')" + value: { int64_value: 4 } + } + test { + name: "unicode" + expr: "size('πέντε')" + value: { int64_value: 5 } + } + test { + name: "bytes_empty" + expr: "size(b'')" + value: { int64_value: 0 } + } + test { + name: "bytes" + expr: "size(b'abc')" + value: { int64_value: 3 } + } +} +section { + name: "starts_with" + description: "Tests for the startsWith() function." + test { + name: "basic_true" + expr: "'foobar'.startsWith('foo')" + value: { bool_value: true } + } + test { + name: "basic_false" + expr: "'foobar'.startsWith('bar')" + value: { bool_value: false } + } + test { + name: "empty_target" + expr: "''.startsWith('foo')" + value: { bool_value: false } + } + test { + name: "empty_arg" + expr: "'foobar'.startsWith('')" + value: { bool_value: true } + } + test { + name: "empty_empty" + expr: "''.startsWith('')" + value: { bool_value: true } + } + test { + name: "unicode" + expr: "'завтра'.startsWith('за')" + value: { bool_value: true } + } + test { + name: "unicode_smp" + expr: "'\U0001F431\U0001F600\U0001F61B'.startsWith('\U0001F431')" + value: { bool_value: true } + } +} +section { + name: "ends_with" + description: "Tests for the endsWith() function." + test { + name: "basic_true" + expr: "'foobar'.endsWith('bar')" + value: { bool_value: true } + } + test { + name: "basic_false" + expr: "'foobar'.endsWith('foo')" + value: { bool_value: false } + } + test { + name: "empty_target" + expr: "''.endsWith('foo')" + value: { bool_value: false } + } + test { + name: "empty_arg" + expr: "'foobar'.endsWith('')" + value: { bool_value: true } + } + test { + name: "empty_empty" + expr: "''.endsWith('')" + value: { bool_value: true } + } + test { + name: "unicode" + expr: "'forté'.endsWith('té')" + value: { bool_value: true } + } + test { + name: "unicode_smp" + expr: "'\U0001F431\U0001F600\U0001F61B'.endsWith('\U0001F61B')" + value: { bool_value: true } + } +} +section { + name: "matches" + description: "Tests for regexp matching. For now, we will only test the subset of regular languages." + test { + name: "basic" + expr: "'hubba'.matches('ubb')" + value: { bool_value: true } + } + test { + name: "empty_target" + expr: "''.matches('foo|bar')" + value: { bool_value: false } + } + test { + name: "empty_arg" + expr: "'cows'.matches('')" + value: { bool_value: true } + } + test { + name: "empty_empty" + expr: "''.matches('')" + value: { bool_value: true } + } + test { + name: "re_concat" + expr: "'abcd'.matches('bc')" + value: { bool_value: true } + } + test { + name: "re_alt" + expr: "'grey'.matches('gr(a|e)y')" + value: { bool_value: true } + } + test { + name: "re_rep" + expr: "'banana'.matches('ba(na)*')" + value: { bool_value: true } + } + test { + name: "unicode" + expr: "'mañana'.matches('a+ñ+a+')" + value: { bool_value: true } + } + test { + name: "unicode_smp" + expr: "'\U0001F431\U0001F600\U0001F600'.matches('(a|\U0001F600){2}')" + value: { bool_value: true } + } +} +section { + name: "concatenation" + description: "Tests for string concatenation." + test { + name: "concat_true" + expr: "'he' + 'llo'" + value: { string_value: "hello" } + } + test { + name: "concat_with_spaces" + expr: "'hello' + ' ' == 'hello'" + value: { bool_value: false } + } + test { + name: "concat_empty_string_beginning" + expr: "'' + 'abc'" + value: { string_value: "abc" } + } + test { + name: "concat_empty_string_end" + expr: "'abc' + ''" + value: { string_value: "abc" } + } + test { + name: "concat_empty_with_empty" + expr: "'' + ''" + value: { string_value: "" } + } + test { + name: "unicode_unicode" + expr: "'¢' + 'ÿ' + 'Ȁ'" + value: { string_value: "¢ÿȀ" } + } + test { + name: "ascii_unicode" + expr: "'r' + 'ô' + 'le'" + value: { string_value: "rôle" } + } + test { + name: "ascii_unicode_unicode_smp" + expr: "'a' + 'ÿ' + '\U0001F431'" + value: { string_value: "aÿ\xf0\x9f\x90\xb1" } + } + test { + name: "empty_unicode" + expr: "'' + 'Ω' + ''" + value: { string_value: "Ω" } + } +} +section { + name: "contains" + description: "Tests for contains." + test { + name: "contains_true" + expr: "'hello'.contains('he')" + value: { bool_value: true } + } + test { + name: "contains_empty" + expr: "'hello'.contains('')" + value: { bool_value: true } + } + test { + name: "contains_false" + expr: "'hello'.contains('ol')" + value: { bool_value: false } + } + test { + name: "contains_multiple" + expr: "'abababc'.contains('ababc')" + value: { bool_value: true } + } + test { + name: "contains_unicode" + expr: "'Straße'.contains('aß')" + value: { bool_value: true } + } + test { + name: "contains_unicode_smp" + expr: "'\U0001F431\U0001F600\U0001F601'.contains('\U0001F600')" + value: { bool_value: true } + } + test { + name: "empty_contains" + expr: "''.contains('something')" + value: { bool_value: false } + } + test { + name: "empty_empty" + expr: "''.contains('')" + value: { bool_value: true } + } +} +section { + name: "bytes_concat" + description: "Tests for bytes concatenation." + test { + name: "concat" + expr: "b'abc' + b'def'" + value: { bytes_value: "abcdef" } + } + test { + name: "left_unit" + expr: "b'' + b'\\xffoo'" + value: { bytes_value: "\377oo" } + } + test { + name: "right_unit" + expr: "b'zxy' + b''" + value: { bytes_value: "zxy" } + } + test { + name: "empty_empty" + expr: "b'' + b''" + value: { bytes_value: "" } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/string_ext.textproto b/packages/cel-spec/src/testdata/textproto/string_ext.textproto new file mode 100644 index 00000000..fea2ad39 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/string_ext.textproto @@ -0,0 +1,1491 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "string_ext" +description: "Tests for the strings extension library." +section: { + name: "char_at" + test: { + name: "middle_index" + expr: "'tacocat'.charAt(3)" + value: { + string_value: "o" + } + } + test: { + name: "end_index" + expr: "'tacocat'.charAt(7)" + value: { + string_value: "" + } + } + test: { + name: "multiple" + expr: "'©αT'.charAt(0) == '©' && '©αT'.charAt(1) == 'α' && '©αT'.charAt(2) == 'T'" + } +} +section: { + name: "index_of" + test: { + name: "empty_index" + expr: "'tacocat'.indexOf('')" + value: { + int64_value: 0 + } + } + test: { + name: "string_index" + expr: "'tacocat'.indexOf('ac')" + value: { + int64_value: 1 + } + } + test: { + name: "nomatch" + expr: "'tacocat'.indexOf('none') == -1" + } + test: { + name: "empty_index" + expr: "'tacocat'.indexOf('', 3) == 3" + } + test: { + name: "char_index" + expr: "'tacocat'.indexOf('a', 3) == 5" + } + test: { + name: "string_index" + expr: "'tacocat'.indexOf('at', 3) == 5" + } + test: { + name: "unicode_char" + expr: "'ta©o©αT'.indexOf('©') == 2" + } + test: { + name: "unicode_char_index" + expr: "'ta©o©αT'.indexOf('©', 3) == 4" + } + test: { + name: "unicode_string_index" + expr: "'ta©o©αT'.indexOf('©αT', 3) == 4" + } + test: { + name: "unicode_string_nomatch_index" + expr: "'ta©o©αT'.indexOf('©α', 5) == -1" + } + test: { + name: "char_index" + expr: "'ijk'.indexOf('k') == 2" + } + test: { + name: "string_with_space_fullmatch" + expr: "'hello wello'.indexOf('hello wello') == 0" + } + test: { + name: "string_with_space_index" + expr: "'hello wello'.indexOf('ello', 6) == 7" + } + test: { + name: "string_nomatch_index" + expr: "'hello wello'.indexOf('elbo room!!') == -1" + } +} +section: { + name: "last_index_of" + test: { + name: "empty_string" + expr: "''.lastIndexOf('@@') == -1" + } + test: { + name: "empty_argument" + expr: "'tacocat'.lastIndexOf('') == 7" + } + test: { + name: "string" + expr: "'tacocat'.lastIndexOf('at') == 5" + } + test: { + name: "string_nomatch" + expr: "'tacocat'.lastIndexOf('none') == -1" + } + test: { + name: "empty_index" + expr: "'tacocat'.lastIndexOf('', 3) == 3" + } + test: { + name: "char_index" + expr: "'tacocat'.lastIndexOf('a', 3) == 1" + } + test: { + name: "unicode_char" + expr: "'ta©o©αT'.lastIndexOf('©') == 4" + } + test: { + name: "unicode_char_index" + expr: "'ta©o©αT'.lastIndexOf('©', 3) == 2" + } + test: { + name: "unicode_string_index" + expr: "'ta©o©αT'.lastIndexOf('©α', 4) == 4" + } + test: { + name: "string_with_space_string_index" + expr: "'hello wello'.lastIndexOf('ello', 6) == 1" + } + test: { + name: "string_with_space_string_nomatch" + expr: "'hello wello'.lastIndexOf('low') == -1" + } + test: { + name: "string_with_space_string_with_space_nomatch" + expr: "'hello wello'.lastIndexOf('elbo room!!') == -1" + } + test: { + name: "string_with_space_fullmatch" + expr: "'hello wello'.lastIndexOf('hello wello') == 0" + } + test: { + name: "repeated_string" + expr: "'bananananana'.lastIndexOf('nana', 7) == 6" + } +} +section: { + name: "ascii_casing" + test: { + name: "lowerascii" + expr: "'TacoCat'.lowerAscii() == 'tacocat'" + } + test: { + name: "lowerascii_unicode" + expr: "'TacoCÆt'.lowerAscii() == 'tacocÆt'" + } + test: { + name: "lowerascii_unicode_with_space" + expr: "'TacoCÆt Xii'.lowerAscii() == 'tacocÆt xii'" + } + test: { + name: "upperascii" + expr: "'tacoCat'.upperAscii() == 'TACOCAT'" + } + test: { + name: "upperascii_unicode" + expr: "'tacoCαt'.upperAscii() == 'TACOCαT'" + } + test: { + name: "upperascii_unicode_with_space" + expr: "'TacoCÆt Xii'.upperAscii() == 'TACOCÆT XII'" + } +} +section: { + name: "replace" + test: { + name: "no_placeholder" + expr: "'12 days 12 hours'.replace('{0}', '2') == '12 days 12 hours'" + } + test: { + name: "basic" + expr: "'{0} days {0} hours'.replace('{0}', '2') == '2 days 2 hours'" + } + test: { + name: "chained" + expr: "'{0} days {0} hours'.replace('{0}', '2', 1).replace('{0}', '23') == '2 days 23 hours'" + } + test: { + name: "unicode" + expr: "'1 ©αT taco'.replace('αT', 'o©α') == '1 ©o©α taco'" + } +} +section: { + name: "split" + test: { + name: "empty" + expr: "'hello world'.split(' ') == ['hello', 'world']" + } + test: { + name: "zero_limit" + expr: "'hello world events!'.split(' ', 0) == []" + } + test: { + name: "one_limit" + expr: "'hello world events!'.split(' ', 1) == ['hello world events!']" + } + test: { + name: "unicode_negative_limit" + expr: "'o©o©o©o'.split('©', -1) == ['o', 'o', 'o', 'o']" + } +} +section: { + name: "substring" + test: { + name: "start" + expr: "'tacocat'.substring(4) == 'cat'" + } + test: { + name: "start_with_max_length" + expr: "'tacocat'.substring(7) == ''" + } + test: { + name: "start_and_end" + expr: "'tacocat'.substring(0, 4) == 'taco'" + } + test: { + name: "start_and_end_equal_value" + expr: "'tacocat'.substring(4, 4) == ''" + } + test: { + name: "unicode_start_and_end" + expr: "'ta©o©αT'.substring(2, 6) == '©o©α'" + } + test: { + name: "unicode_start_and_end_equal_value" + expr: "'ta©o©αT'.substring(7, 7) == ''" + } +} +section: { + name: "trim" + test: { + name: "blank_spaces_escaped_chars" + expr: "' \\f\\n\\r\\t\\vtext '.trim() == 'text'" + } + test: { + name: "unicode_space_chars_1" + expr: "'\\u0085\\u00a0\\u1680text'.trim() == 'text'" + } + test: { + name: "unicode_space_chars_2" + expr: "'text\\u2000\\u2001\\u2002\\u2003\\u2004\\u2004\\u2006\\u2007\\u2008\\u2009'.trim() == 'text'" + } + test: { + name: "unicode_space_chars_3" + expr: "'\\u200atext\\u2028\\u2029\\u202F\\u205F\\u3000'.trim() == 'text'" + } + test: { + name: "unicode_no_trim" + expr: "'\\u180etext\\u200b\\u200c\\u200d\\u2060\\ufeff'.trim() == '\\u180etext\\u200b\\u200c\\u200d\\u2060\\ufeff'" + } +} +section: { + name: "join" + test: { + name: "empty_separator" + expr: "['x', 'y'].join() == 'xy'" + } + test: { + name: "dash_separator" + expr: "['x', 'y'].join('-') == 'x-y'" + } + test: { + name: "empty_string_empty_separator" + expr: "[].join() == ''" + } + test: { + name: "empty_string_dash_separator" + expr: "[].join('-') == ''" + } +} +section: { + name: "quote" + test: { + name: "multiline" + expr: "strings.quote(\"first\\nsecond\") == \"\\\"first\\\\nsecond\\\"\"" + } + test: { + name: "escaped" + expr: "strings.quote(\"bell\\a\") == \"\\\"bell\\\\a\\\"\"" + } + test: { + name: "backspace" + expr: "strings.quote(\"\\bbackspace\") == \"\\\"\\\\bbackspace\\\"\"" + } + test: { + name: "form_feed" + expr: "strings.quote(\"\\fform feed\") == \"\\\"\\\\fform feed\\\"\"" + } + test: { + name: "carriage_return" + expr: "strings.quote(\"carriage \\r return\") == \"\\\"carriage \\\\r return\\\"\"" + } + test: { + name: "horizontal_tab" + expr: "strings.quote(\"horizontal tab\\t\") == \"\\\"horizontal tab\\\\t\\\"\"" + } + test: { + name: "vertical_tab" + expr: "strings.quote(\"vertical \\v tab\") == \"\\\"vertical \\\\v tab\\\"\"" + } + test: { + name: "double_slash" + expr: "strings.quote(\"double \\\\\\\\ slash\") == \"\\\"double \\\\\\\\\\\\\\\\ slash\\\"\"" + } + test: { + name: "two_escape_sequences" + expr: "strings.quote(\"two escape sequences \\\\a\\\\n\") == \"\\\"two escape sequences \\\\\\\\a\\\\\\\\n\\\"\"" + } + test: { + name: "verbatim" + expr: "strings.quote(\"verbatim\") == \"\\\"verbatim\\\"\"" + } + test: { + name: "ends_with" + expr: "strings.quote(\"ends with \\\\\") == \"\\\"ends with \\\\\\\\\\\"\"" + } + test: { + name: "starts_with" + expr: "strings.quote(\"\\\\ starts with\") == \"\\\"\\\\\\\\ starts with\\\"\"" + } + test: { + name: "printable_unicode" + expr: "strings.quote(\"printable unicode😀\") == \"\\\"printable unicode😀\\\"\"" + } + test: { + name: "mid_string_quote" + expr: "strings.quote(\"mid string \\\" quote\") == \"\\\"mid string \\\\\\\" quote\\\"\"" + } + test: { + name: "single_quote_with_double_quote" + expr: "strings.quote('single-quote with \"double quote\"') == \"\\\"single-quote with \\\\\\\"double quote\\\\\\\"\\\"\"" + } + test: { + name: "size_unicode_char" + expr: "strings.quote(\"size('ÿ')\") == \"\\\"size('ÿ')\\\"\"" + } + test: { + name: "size_unicode_string" + expr: "strings.quote(\"size('πέντε')\") == \"\\\"size('πέντε')\\\"\"" + } + test: { + name: "unicode" + expr: "strings.quote(\"завтра\") == \"\\\"завтра\\\"\"" + } + test: { + name: "unicode_code_points" + expr: "strings.quote(\"\\U0001F431\\U0001F600\\U0001F61B\")" + value: { + string_value: "\"🐱😀😛\"" + } + } + test: { + name: "unicode_2" + expr: "strings.quote(\"ta©o©αT\") == \"\\\"ta©o©αT\\\"\"" + } + test: { + name: "empty_quote" + expr: "strings.quote(\"\")" + value: { + string_value: "\"\"" + } + } +} +section: { + name: "format" + test: { + name: "no-op" + expr: '"no substitution".format([])' + value: { + string_value: 'no substitution', + } + } + test: { + name: "mid-string substitution" + expr: '"str is %s and some more".format(["filler"])' + value: { + string_value: 'str is filler and some more', + } + } + test: { + name: "percent escaping" + expr: '"%% and also %%".format([])' + value: { + string_value: '% and also %', + } + } + test: { + name: "substitution inside escaped percent signs" + expr: '"%%%s%%".format(["text"])' + value: { + string_value: '%text%', + } + } + test: { + name: "substitution with one escaped percent sign on the right" + expr: '"%s%%".format(["percent on the right"])' + value: { + string_value: 'percent on the right%', + } + } + test: { + name: "substitution with one escaped percent sign on the left" + expr: '"%%%s".format(["percent on the left"])' + value: { + string_value: '%percent on the left', + } + } + test: { + name: "multiple substitutions" + expr: '"%d %d %d, %s %s %s, %d %d %d, %s %s %s".format([1, 2, 3, "A", "B", "C", 4, 5, 6, "D", "E", "F"])' + value: { + string_value: '1 2 3, A B C, 4 5 6, D E F', + } + } + test: { + name: "percent sign escape sequence support" + expr: '"%%escaped %s%%".format(["percent"])' + value: { + string_value: '%escaped percent%', + } + } + test: { + name: "fixed point formatting clause" + expr: '"%.3f".format([1.2345])' + value: { + string_value: '1.234', + } + } + test: { + name: "binary formatting clause" + expr: '"this is 5 in binary: %b".format([5])' + value: { + string_value: 'this is 5 in binary: 101', + } + } + test: { + name: "uint support for binary formatting" + expr: '"unsigned 64 in binary: %b".format([uint(64)])' + value: { + string_value: 'unsigned 64 in binary: 1000000', + } + } + test: { + name: "bool support for binary formatting" + expr: '"bit set from bool: %b".format([true])' + value: { + string_value: 'bit set from bool: 1', + } + } + test: { + name: "octal formatting clause" + expr: '"%o".format([11])' + value: { + string_value: '13', + } + } + test: { + name: "uint support for octal formatting clause" + expr: '"this is an unsigned octal: %o".format([uint(65535)])' + value: { + string_value: 'this is an unsigned octal: 177777', + } + } + test: { + name: "lowercase hexadecimal formatting clause" + expr: '"%x is 20 in hexadecimal".format([30])' + value: { + string_value: '1e is 20 in hexadecimal', + } + } + test: { + name: "uppercase hexadecimal formatting clause" + expr: '"%X is 20 in hexadecimal".format([30])' + value: { + string_value: '1E is 20 in hexadecimal', + } + } + test: { + name: "unsigned support for hexadecimal formatting clause" + expr: '"%X is 6000 in hexadecimal".format([uint(6000)])' + value: { + string_value: '1770 is 6000 in hexadecimal', + } + } + test: { + name: "string support with hexadecimal formatting clause" + expr: '"%x".format(["Hello world!"])' + value: { + string_value: '48656c6c6f20776f726c6421', + } + } + test: { + name: "string support with uppercase hexadecimal formatting clause" + expr: '"%X".format(["Hello world!"])' + value: { + string_value: '48656C6C6F20776F726C6421', + } + } + test: { + name: "byte support with hexadecimal formatting clause" + expr: '"%x".format([b"byte string"])' + value: { + string_value: '6279746520737472696e67', + } + } + test: { + name: "byte support with uppercase hexadecimal formatting clause" + expr: '"%X".format([b"byte string"])' + value: { + string_value: '6279746520737472696E67', + } + } + test: { + name: "scientific notation formatting clause" + expr: '"%.6e".format([1052.032911275])' + value: { + string_value: '1.052033e+03', + } + } + test: { + name: "default precision for fixed-point clause" + expr: '"%f".format([2.71828])' + value: { + string_value: '2.718280', + } + } + test: { + name: "default precision for scientific notation" + expr: '"%e".format([2.71828])' + value: { + string_value: '2.718280e+00', + } + } + test: { + name: "NaN support for scientific notation" + expr: '"%e".format([double("NaN")])' + value: { + string_value: 'NaN', + } + } + test: { + name: "positive infinity support for scientific notation" + expr: '"%e".format([double("Infinity")])' + value: { + string_value: 'Infinity', + } + } + test: { + name: "negative infinity support for scientific notation" + expr: '"%e".format([double("-Infinity")])' + value: { + string_value: '-Infinity', + } + } + test: { + name: "NaN support for decimal" + expr: '"%d".format([double("NaN")])' + value: { + string_value: 'NaN', + } + } + test: { + name: "positive infinity support for decimal" + expr: '"%d".format([double("Infinity")])' + value: { + string_value: 'Infinity', + } + } + test: { + name: "negative infinity support for decimal" + expr: '"%d".format([double("-Infinity")])' + value: { + string_value: '-Infinity', + } + } + test: { + name: "NaN support for fixed-point" + expr: '"%f".format([double("NaN")])' + value: { + string_value: 'NaN', + } + } + test: { + name: "positive infinity support for fixed-point" + expr: '"%f".format([double("Infinity")])' + value: { + string_value: 'Infinity', + } + } + test: { + name: "negative infinity support for fixed-point" + expr: '"%f".format([double("-Infinity")])' + value: { + string_value: '-Infinity', + } + } + test: { + name: "uint support for decimal clause" + expr: '"%d".format([uint(64)])' + value: { + string_value: '64', + } + } + test: { + name: "null support for string" + expr: '"%s".format([null])' + value: { + string_value: 'null', + } + } + test: { + name: "int support for string" + expr: '"%s".format([999999999999])' + value: { + string_value: '999999999999', + } + } + test: { + name: "bytes support for string" + expr: '"%s".format([b"xyz"])' + value: { + string_value: 'xyz', + } + } + test: { + name: "type() support for string" + expr: '"%s".format([type("test string")])' + value: { + string_value: 'string', + } + } + test: { + name: "timestamp support for string" + expr: '"%s".format([timestamp("2023-02-03T23:31:20+00:00")])' + value: { + string_value: '2023-02-03T23:31:20Z', + } + } + test: { + name: "duration support for string" + expr: '"%s".format([duration("1h45m47s")])' + value: { + string_value: '6347s', + } + } + test: { + name: "list support for string" + expr: '"%s".format([["abc", 3.14, null, [9, 8, 7, 6], timestamp("2023-02-03T23:31:20Z")]])' + value: { + string_value: '[abc, 3.14, null, [9, 8, 7, 6], 2023-02-03T23:31:20Z]', + } + } + test: { + name: "map support for string" + expr: '"%s".format([{"key1": b"xyz", "key5": null, "key2": duration("2h"), "key4": true, "key3": 2.71828}])' + value: { + string_value: '{key1: xyz, key2: 7200s, key3: 2.71828, key4: true, key5: null}', + } + } + test: { + name: "map support (all key types)" + expr: '"%s".format([{1: "value1", uint(2): "value2", true: double("NaN")}])' + value: { + string_value: '{1: value1, 2: value2, true: NaN}', + } + } + test: { + name: "boolean support for %s" + expr: '"%s, %s".format([true, false])' + value: { + string_value: 'true, false', + } + } + test: { + name: "dyntype support for string formatting clause" + expr: '"%s".format([dyn("a string")])' + value: { + string_value: 'a string', + } + } + test: { + name: "dyntype support for numbers with string formatting clause" + expr: '"%s, %s".format([dyn(32), dyn(56.8)])' + value: { + string_value: '32, 56.8', + } + } + test: { + name: "dyntype support for integer formatting clause" + expr: '"%d".format([dyn(128)])' + value: { + string_value: '128', + } + } + test: { + name: "dyntype support for integer formatting clause (unsigned)" + expr: '"%d".format([dyn(256u)])' + value: { + string_value: '256', + } + } + test: { + name: "dyntype support for hex formatting clause" + expr: '"%x".format([dyn(22)])' + value: { + string_value: '16', + } + } + test: { + name: "dyntype support for hex formatting clause (uppercase)" + expr: '"%X".format([dyn(26)])' + value: { + string_value: '1A', + } + } + test: { + name: "dyntype support for unsigned hex formatting clause" + expr: '"%x".format([dyn(500u)])' + value: { + string_value: '1f4', + } + } + test: { + name: "dyntype support for fixed-point formatting clause" + expr: '"%.3f".format([dyn(4.5)])' + value: { + string_value: '4.500', + } + } + test: { + name: "dyntype support for scientific notation" + expr: '"%e".format([dyn(2.71828)])' + value: { + string_value: '2.718280e+00', + } + } + test: { + name: "dyntype NaN/infinity support" + expr: '"%s".format([[double("NaN"), double("Infinity"), double("-Infinity")]])' + value: { + string_value: '[NaN, Infinity, -Infinity]', + } + } + test: { + name: "dyntype support for timestamp" + expr: '"%s".format([dyn(timestamp("2009-11-10T23:00:00Z"))])' + value: { + string_value: '2009-11-10T23:00:00Z', + } + } + test: { + name: "dyntype support for duration" + expr: '"%s".format([dyn(duration("8747s"))])' + value: { + string_value: '8747s', + } + } + test: { + name: "dyntype support for lists" + expr: '"%s".format([dyn([6, 4.2, "a string"])])' + value: { + string_value: '[6, 4.2, a string]', + } + } + test: { + name: "dyntype support for maps" + expr: '"%s".format([{"strKey":"x", 6:duration("422s"), true:42}])' + value: { + string_value: '{6: 422s, strKey: x, true: 42}', + } + } + test: { + name: "string substitution in a string variable" + expr: 'str_var.format(["filler"])' + type_env: { + name: "str_var", + ident: { type: { primitive: STRING } } + } + bindings: { + key: "str_var" + value: { value: { string_value: "%s" } } + } + value: { + string_value: 'filler', + } + } + test: { + name: "multiple substitutions in a string variable" + expr: 'str_var.format([1, 2, 3, "A", "B", "C", 4, 5, 6, "D", "E", "F"])' + type_env: { + name: "str_var", + ident: { type: { primitive: STRING } } + } + bindings: { + key: "str_var" + value: { value: { string_value: "%d %d %d, %s %s %s, %d %d %d, %s %s %s" } } + } + value: { + string_value: '1 2 3, A B C, 4 5 6, D E F', + } + } + test: { + name: "substitution inside escaped percent signs in a string variable" + expr: 'str_var.format(["text"])' + type_env: { + name: "str_var", + ident: { type: { primitive: STRING } } + } + bindings: { + key: "str_var" + value: { value: { string_value: "%%%s%%" } } + } + value: { + string_value: '%text%', + } + } + test: { + name: "fixed point formatting clause in a string variable" + expr: 'str_var.format([1.2345])' + type_env: { + name: "str_var", + ident: { type: { primitive: STRING } } + } + bindings: { + key: "str_var" + value: { value: { string_value: "%.3f" } } + } + value: { + string_value: '1.234', + } + } + test: { + name: "binary formatting clause in a string variable" + expr: 'str_var.format([5])' + type_env: { + name: "str_var", + ident: { type: { primitive: STRING } } + } + bindings: { + key: "str_var" + value: { value: { string_value: "%b" } } + } + value: { + string_value: '101', + } + } + test: { + name: "scientific notation formatting clause in a string variable" + expr: 'str_var.format([1052.032911275])' + type_env: { + name: "str_var", + ident: { type: { primitive: STRING } } + } + bindings: { + key: "str_var" + value: { value: { string_value: "%.6e" } } + } + value: { + string_value: '1.052033e+03', + } + } + test: { + name: "default precision for fixed-point clause in a string variable" + expr: 'str_var.format([2.71828])' + type_env: { + name: "str_var", + ident: { type: { primitive: STRING } } + } + bindings: { + key: "str_var" + value: { value: { string_value: "%f" } } + } + value: { + string_value: '2.718280', + } + } +test: { + name: "format_%f_insignificant_zeroes_removed" + expr: '"%.0f".format([123.000000])' + value: { + string_value: '123', + } + } + test: { + name: "format_%f_positive_round_to_whole_number" + expr: '"%.0f".format([3.5001])' + value: { + string_value: '4', + } + } + test: { + name: "format_%f_negative_truncate_to_whole_number" + expr: '"%.0f".format([3.4999])' + value: { + string_value: '3', + } + } + test: { + name: "format_%f_halfway_round_up_to_nearest_even" + expr: '"%.0f".format([1.5])' + value: { + string_value: '2', + } + } + test: { + name: "format_%f_halfway_truncate_to_nearest_even" + expr: '"%.0f".format([2.5])' + value: { + string_value: '2', + } + } + test: { + name: "format_%f_positive_round_up" + expr: '"%.3f".format([123.4999])' + value: { + string_value: '123.500', + } + } + test: { + name: "format_%f_positive_round_down" + expr: '"%.3f".format([123.4994])' + value: { + string_value: '123.499', + } + } + test: { + name: "format_%f_negative_round_up" + expr: '"%.3f".format([-123.4999])' + value: { + string_value: '-123.500', + } + } + test: { + name: "format_%f_negative_round_down" + expr: '"%.3f".format([-123.4994])' + value: { + string_value: '-123.499', + } + } + test: { + name: "format_%f_zero_padding" + expr: '"%.5f".format([-1.2])' + value: { + string_value: '-1.20000', + } + } +} +section: { + name: "format_errors" + test: { + name: "unrecognized formatting clause" + expr: '"%a".format([1])' + disable_check: true + eval_error: { + errors: { + message: 'could not parse formatting clause: unrecognized formatting clause "a"' + } + } + } + test: { + name: "out of bounds arg index" + expr: '"%d %d %d".format([0, 1])' + disable_check: true + eval_error: { + errors: { + message: 'index 2 out of range' + } + } + } + test: { + name: "string substitution is not allowed with binary clause" + expr: '"string is %b".format(["abc"])' + disable_check: true + eval_error: { + errors: { + message: 'error during formatting: only integers and bools can be formatted as binary, was given string' + } + } + } + test: { + name: "duration substitution not allowed with decimal clause" + expr: '"%d".format([duration("30m2s")])' + disable_check: true + eval_error: { + errors: { + message: 'error during formatting: decimal clause can only be used on integers, was given google.protobuf.Duration' + } + } + } + test: { + name: "string substitution not allowed with octal clause" + expr: '"octal: %o".format(["a string"])' + disable_check: true + eval_error: { + errors: { + message: 'error during formatting: octal clause can only be used on integers, was given string' + } + } + } + test: { + name: "double substitution not allowed with hex clause" + expr: '"double is %x".format([0.5])' + disable_check: true + eval_error: { + errors: { + message: 'error during formatting: only integers, byte buffers, and strings can be formatted as hex, was given double' + } + } + } + test: { + name: "uppercase not allowed for scientific clause" + expr: '"double is %E".format([0.5])' + disable_check: true + eval_error: { + errors: { + message: 'could not parse formatting clause: unrecognized formatting clause "E"' + } + } + } + test: { + name: "object not allowed" + expr: '"object is %s".format([cel.expr.conformance.proto3.TestAllTypes{}])' + disable_check: true + eval_error: { + errors: { + message: 'error during formatting: string clause can only be used on strings, bools, bytes, ints, doubles, maps, lists, types, durations, and timestamps, was given cel.expr.conformance.proto3.TestAllTypes' + } + } + } + test: { + name: "object inside list" + expr: '"%s".format([[1, 2, cel.expr.conformance.proto3.TestAllTypes{}]])' + disable_check: true + eval_error: { + errors: { + message: 'error during formatting: string clause can only be used on strings, bools, bytes, ints, doubles, maps, lists, types, durations, and timestamps, was given cel.expr.conformance.proto3.TestAllTypes' + } + } + } + test: { + name: "object inside map" + expr: '"%s".format([{1: "a", 2: cel.expr.conformance.proto3.TestAllTypes{}}])' + disable_check: true + eval_error: { + errors: { + message: 'error during formatting: string clause can only be used on strings, bools, bytes, ints, doubles, maps, lists, types, durations, and timestamps, was given cel.expr.conformance.proto3.TestAllTypes' + } + } + } + test: { + name: "null not allowed for %d" + expr: '"null: %d".format([null])' + disable_check: true + eval_error: { + errors: { + message: 'error during formatting: decimal clause can only be used on integers, was given null_type' + } + } + } + test: { + name: "null not allowed for %e" + expr: '"null: %e".format([null])' + disable_check: true + eval_error: { + errors: { + message: 'error during formatting: scientific clause can only be used on doubles, was given null_type' + } + } + } + test: { + name: "null not allowed for %f" + expr: '"null: %f".format([null])' + disable_check: true + eval_error: { + errors: { + message: 'error during formatting: fixed-point clause can only be used on doubles, was given null_type' + } + } + } + test: { + name: "null not allowed for %x" + expr: '"null: %x".format([null])' + disable_check: true + eval_error: { + errors: { + message: 'error during formatting: only integers, byte buffers, and strings can be formatted as hex, was given null_type' + } + } + } + test: { + name: "null not allowed for %X" + expr: '"null: %X".format([null])' + disable_check: true + eval_error: { + errors: { + message: 'error during formatting: only integers, byte buffers, and strings can be formatted as hex, was given null_type' + } + } + } + test: { + name: "null not allowed for %b" + expr: '"null: %b".format([null])' + disable_check: true + eval_error: { + errors: { + message: 'error during formatting: only integers and bools can be formatted as binary, was given null_type' + } + } + } + test: { + name: "null not allowed for %o" + expr: '"null: %o".format([null])' + disable_check: true + eval_error: { + errors: { + message: 'error during formatting: octal clause can only be used on integers, was given null_type' + } + } + } +} +section: { + name: "value_errors" + test: { + name: "charat_out_of_range" + expr: "'tacocat'.charAt(30) == ''" + eval_error: { + errors: { + message: "index out of range: 30" + } + } + } + test: { + name: "indexof_out_of_range" + expr: "'tacocat'.indexOf('a', 30) == -1" + eval_error: { + errors: { + message: "index out of range: 30" + } + } + } + test: { + name: "lastindexof_negative_index" + expr: "'tacocat'.lastIndexOf('a', -1) == -1" + eval_error: { + errors: { + message: "index out of range: -1" + } + } + } + test: { + name: "lastindexof_out_of_range" + expr: "'tacocat'.lastIndexOf('a', 30) == -1" + eval_error: { + errors: { + message: "index out of range: 30" + } + } + } + test: { + name: "substring_out_of_range" + expr: "'tacocat'.substring(40) == 'cat'" + eval_error: { + errors: { + message: "index out of range: 40" + } + } + } + test: { + name: "substring_negative_index" + expr: "'tacocat'.substring(-1) == 'cat'" + eval_error: { + errors: { + message: "index out of range: -1" + } + } + } + test: { + name: "substring_end_index_out_of_range" + expr: "'tacocat'.substring(1, 50) == 'cat'" + eval_error: { + errors: { + message: "index out of range: 50" + } + } + } + test: { + name: "substring_begin_index_out_of_range" + expr: "'tacocat'.substring(49, 50) == 'cat'" + eval_error: { + errors: { + message: "index out of range: 49" + } + } + } + test: { + name: "substring_end_index_greater_than_begin_index" + expr: "'tacocat'.substring(4, 3) == ''" + eval_error: { + errors: { + message: "invalid substring range. start: 4, end: 3" + } + } + } +} +section: { + name: "type_errors" + test: { + name: "charat_invalid_type" + expr: "42.charAt(2) == ''" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "charat_invalid_argument" + expr: "'hello'.charAt(true) == ''" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "indexof_unary_invalid_type" + expr: "24.indexOf('2') == 0" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "indexof_unary_invalid_argument" + expr: "'hello'.indexOf(true) == 1" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "indexof_binary_invalid_argument" + expr: "42.indexOf('4', 0) == 0" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "indexof_binary_invalid_argument_2" + expr: "'42'.indexOf(4, 0) == 0" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "indexof_binary_both_invalid_arguments" + expr: "'42'.indexOf('4', '0') == 0" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "indexof_ternary_invalid_arguments" + expr: "'42'.indexOf('4', 0, 1) == 0" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "split_invalid_type" + expr: "42.split('2') == ['4']" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "replace_invalid_type" + expr: "42.replace(2, 1) == '41'" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "replace_binary_invalid_argument" + expr: "'42'.replace(2, 1) == '41'" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "replace_binary_invalid_argument_2" + expr: "'42'.replace('2', 1) == '41'" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "replace_ternary_invalid_argument" + expr: "42.replace('2', '1', 1) == '41'" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "replace_ternary_invalid_argument_2" + expr: "'42'.replace(2, '1', 1) == '41'" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "replace_ternary_invalid_argument_3" + expr: "'42'.replace('2', 1, 1) == '41'" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "replace_ternary_invalid_argument_4" + expr: "'42'.replace('2', '1', '1') == '41'" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "replace_quaternary_invalid_argument" + expr: "'42'.replace('2', '1', 1, false) == '41'" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "split_invalid_type_empty_arg" + expr: "42.split('') == ['4', '2']" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "split_invalid_argument" + expr: "'42'.split(2) == ['4']" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "split_binary_invalid_type" + expr: "42.split('2', '1') == ['4']" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "split_binary_invalid_argument" + expr: "'42'.split(2, 1) == ['4']" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "split_binary_invalid_argument_2" + expr: "'42'.split('2', '1') == ['4']" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "split_ternary_invalid_argument" + expr: "'42'.split('2', 1, 1) == ['4']" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "substring_ternary_invalid_argument" + expr: "'hello'.substring(1, 2, 3) == ''" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "substring_binary_invalid_type" + expr: "30.substring(true, 3) == ''" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "substring_binary_invalid_argument" + expr: "'tacocat'.substring(true, 3) == ''" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } + test: { + name: "substring_binary_invalid_argument_2" + expr: "'tacocat'.substring(0, false) == ''" + disable_check: true + eval_error: { + errors: { + message: "no such overload" + } + } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/timestamps.textproto b/packages/cel-spec/src/testdata/textproto/timestamps.textproto new file mode 100644 index 00000000..d3d05849 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/timestamps.textproto @@ -0,0 +1,478 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "timestamps" +description: "Timestamp and duration tests." +section { + name: "timestamp_conversions" + description: "Conversions of timestamps to other types." + test { + name: "toInt_timestamp" + expr: "int(timestamp('2009-02-13T23:31:30Z'))" + value: { int64_value: 1234567890 } + } + test { + name: "toString_timestamp" + expr: "string(timestamp('2009-02-13T23:31:30Z'))" + value: { string_value: "2009-02-13T23:31:30Z" } + } + test { + name: "toString_timestamp_nanos" + expr: "string(timestamp('9999-12-31T23:59:59.999999999Z'))" + value: { string_value: "9999-12-31T23:59:59.999999999Z" } + } + test { + name: "toType_timestamp" + expr: "type(timestamp('2009-02-13T23:31:30Z'))" + value: { type_value: "google.protobuf.Timestamp" } + } + test { + name: "type_comparison" + expr: "google.protobuf.Timestamp == type(timestamp('2009-02-13T23:31:30Z'))" + value: { bool_value: true } + } +} +section { + name: "duration_conversions" + description: "Conversions of durations to other types." + test { + name: "toString_duration" + expr: "string(duration('1000000s'))" + value: { string_value: "1000000s" } + } + test { + name: "toType_duration" + expr: "type(duration('1000000s'))" + value: { type_value: "google.protobuf.Duration" } + } + test { + name: "type_comparison" + expr: "google.protobuf.Duration == type(duration('1000000s'))" + value: { bool_value: true } + } +} + +section { + name: "timestamp_selectors" + description: "Timestamp selection operators without timezones" + # 1234567890 -> Fri 2009-02-13 23:31:30 UTC + test { + name: "getDate" + expr: "timestamp('2009-02-13T23:31:30Z').getDate()" + value: { int64_value: 13 } + } + test { + name: "getDayOfMonth" + expr: "timestamp('2009-02-13T23:31:30Z').getDayOfMonth()" + value: { int64_value: 12 } + } + test { + name: "getDayOfWeek" + expr: "timestamp('2009-02-13T23:31:30Z').getDayOfWeek()" + value: { int64_value: 5 } + } + test { + name: "getDayOfYear" + expr: "timestamp('2009-02-13T23:31:30Z').getDayOfYear()" + value: { int64_value: 43 } + } + test { + name: "getFullYear" + expr: "timestamp('2009-02-13T23:31:30Z').getFullYear()" + value: { int64_value: 2009 } + } + test { + name: "getHours" + expr: "timestamp('2009-02-13T23:31:30Z').getHours()" + value: { int64_value: 23 } + } + test { + name: "getMilliseconds" + expr: "timestamp('2009-02-13T23:31:20.123456789Z').getMilliseconds()" + value: { int64_value: 123 } + } + test { + name: "getMinutes" + expr: "timestamp('2009-02-13T23:31:30Z').getMinutes()" + value: { int64_value: 31 } + } + test { + name: "getMonth" + expr: "timestamp('2009-02-13T23:31:30Z').getMonth()" + value: { int64_value: 1 } + } + test { + name: "getSeconds" + expr: "timestamp('2009-02-13T23:31:30Z').getSeconds()" + value: { int64_value: 30 } + } +} +section { + name: "timestamp_selectors_tz" + description: "Timestamp selection operators with timezones" + # 1234567890 -> Fri 2009-02-13 23:31:30 UTC + test { + name: "getDate" + expr: "timestamp('2009-02-13T23:31:30Z').getDate('Australia/Sydney')" + value: { int64_value: 14 } + } + test { + name: "getDayOfMonth_name_pos" + expr: "timestamp('2009-02-13T23:31:30Z').getDayOfMonth('US/Central')" + value: { int64_value: 12 } + } + test { + name: "getDayOfMonth_numerical_pos" + expr: "timestamp('2009-02-13T23:31:30Z').getDayOfMonth('+11:00')" + value: { int64_value: 13 } + } + test { + name: "getDayOfMonth_numerical_neg" + expr: "timestamp('2009-02-13T02:00:00Z').getDayOfMonth('-02:30')" + value: { int64_value: 11 } + } + test { + name: "getDayOfMonth_name_neg" + expr: "timestamp('2009-02-13T02:00:00Z').getDayOfMonth('America/St_Johns')" + value: { int64_value: 11 } + } + test { + name: "getDayOfWeek" + expr: "timestamp('2009-02-13T23:31:30Z').getDayOfWeek('UTC')" + value: { int64_value: 5 } + } + test { + name: "getDayOfYear" + expr: "timestamp('2009-02-13T23:31:30Z').getDayOfYear('US/Central')" + value: { int64_value: 43 } + } + test { + name: "getFullYear" + expr: "timestamp('2009-02-13T23:31:30Z').getFullYear('-09:30')" + value: { int64_value: 2009 } + } + test { + name: "getHours" + expr: "timestamp('2009-02-13T23:31:30Z').getHours('02:00')" + value: { int64_value: 1 } + } + test { + name: "getMinutes" + expr: "timestamp('2009-02-13T23:31:30Z').getMinutes('Asia/Kathmandu')" + value: { int64_value: 16 } + } + test { + name: "getMonth" + expr: "timestamp('2009-02-13T23:31:30Z').getMonth('UTC')" + value: { int64_value: 1 } + } + test { + name: "getSeconds" + expr: "timestamp('2009-02-13T23:31:30Z').getSeconds('-00:00')" + value: { int64_value: 30 } + } +} +section { + name: "timestamp_equality" + description: "Equality operations on timestamps." + test { + name: "eq_same" + expr: "timestamp('2009-02-13T23:31:30Z') == timestamp('2009-02-13T23:31:30Z')" + value: { bool_value: true } + } + test { + name: "eq_diff" + expr: "timestamp('2009-02-13T23:31:29Z') == timestamp('2009-02-13T23:31:30Z')" + value: { bool_value: false } + } + test { + name: "neq_same" + expr: "timestamp('1945-05-07T02:41:00Z') != timestamp('1945-05-07T02:41:00Z')" + value: { bool_value: false } + } + test { + name: "neq_diff" + expr: "timestamp('2000-01-01T00:00:00Z') != timestamp('2001-01-01T00:00:00Z')" + value: { bool_value: true } + } +} +section { + name: "duration_equality" + description: "Equality tests for durations." + test { + name: "eq_same" + expr: "duration('123s') == duration('123s')" + value: { bool_value: true } + } + test { + name: "eq_diff" + expr: "duration('60s') == duration('3600s')" + value: { bool_value: false } + } + test { + name: "neq_same" + expr: "duration('604800s') != duration('604800s')" + value: { bool_value: false } + } + test { + name: "neq_diff" + expr: "duration('86400s') != duration('86164s')" + value: { bool_value: true } + } +} +section { + name: "timestamp_arithmetic" + description: "Arithmetic operations on timestamps and/or durations." + test { + name: "add_duration_to_time" + expr: "timestamp('2009-02-13T23:00:00Z') + duration('240s') == timestamp('2009-02-13T23:04:00Z')" + value: { bool_value: true } + } + test { + name: "add_time_to_duration" + expr: "duration('120s') + timestamp('2009-02-13T23:01:00Z') == timestamp('2009-02-13T23:03:00Z')" + value: { bool_value: true } + } + test { + name: "add_duration_to_duration" + expr: "duration('600s') + duration('50s') == duration('650s')" + value: { bool_value: true } + } + test { + name: "add_time_to_duration_nanos_negative" + expr: "timestamp('0001-01-01T00:00:01.000000001Z') + duration('-999999999ns') == timestamp('0001-01-01T00:00:00.000000002Z')" + value: { bool_value: true } + } + test { + name: "add_time_to_duration_nanos_positive" + expr: "timestamp('0001-01-01T00:00:01.999999999Z') + duration('999999999ns') == timestamp('0001-01-01T00:00:02.999999998Z')" + value: { bool_value: true } + } + test { + name: "subtract_duration_from_time" + expr: "timestamp('2009-02-13T23:10:00Z') - duration('600s') == timestamp('2009-02-13T23:00:00Z')" + value: { bool_value: true } + } + test { + name: "subtract_time_from_time" + expr: "timestamp('2009-02-13T23:31:00Z') - timestamp('2009-02-13T23:29:00Z') == duration('120s')" + value: { bool_value: true } + } + test { + name: "subtract_duration_from_duration" + expr: "duration('900s') - duration('42s') == duration('858s')" + value: { bool_value: true } + } +} +section { + name: "comparisons" + description: "Comparisons on timestamps and/or durations." + test { + name: "leq_timestamp_true" + expr: "timestamp('2009-02-13T23:00:00Z') <= timestamp('2009-02-13T23:00:00Z')" + value: { bool_value: true } + } + test { + name: "leq_timestamp_false" + expr: "timestamp('2009-02-13T23:00:00Z') <= timestamp('2009-02-13T22:59:59Z')" + value: { bool_value: false } + } + test { + name: "leq_duration_true" + expr: "duration('200s') <= duration('200s')" + value: { bool_value: true } + } + test { + name: "leq_duration_false" + expr: "duration('300s') <= duration('200s')" + value: { bool_value: false } + } + test { + name: "less_timestamp_true" + expr: "timestamp('2009-02-13T23:00:00Z') < timestamp('2009-03-13T23:00:00Z')" + value: { bool_value: true } + } + test { + name: "less_duration_true" + expr: "duration('200s') < duration('300s')" + value: { bool_value: true } + } + test { + name: "geq_timestamp_true" + expr: "timestamp('2009-02-13T23:00:00Z') >= timestamp('2009-02-13T23:00:00Z')" + value: { bool_value: true } + } + test { + name: "geq_timestamp_false" + expr: "timestamp('2009-02-13T22:58:00Z') >= timestamp('2009-02-13T23:00:00Z')" + value: { bool_value: false } + } + test { + name: "geq_duration_true" + expr: "duration('200s') >= duration('200s')" + value: { bool_value: true } + } + test { + name: "geq_duration_false" + expr: "duration('120s') >= duration('200s')" + value: { bool_value: false } + } + test { + name: "greater_timestamp_true" + expr: "timestamp('2009-02-13T23:59:00Z') > timestamp('2009-02-13T23:00:00Z')" + value: { bool_value: true } + } + test { + name: "greater_duration_true" + expr: "duration('300s') > duration('200s')" + value: { bool_value: true } + } +} +section { + name: "duration_converters" + description: "Conversion functions on durations. Unlike timestamps, we don't, e.g. select the 'minutes' field - we convert the duration to integer minutes." + test { + name: "get_hours" + expr: "duration('10000s').getHours()" + value: { int64_value: 2 } + } + test { + name: "get_milliseconds" + description: "Obtain the milliseconds component of the duration. Note, this is not the same as converting the duration to milliseconds. This behavior will be deprecated." + expr: "x.getMilliseconds()" + type_env { + name: "x" + ident: { type: { message_type: "google.protobuf.Duration" } } + } + bindings { + key: "x" + value { + value { + object_value { + [type.googleapis.com/google.protobuf.Duration] { + seconds: 123 + nanos: 321456789 + } + } + } + } + } + value: { int64_value: 321 } + } + test { + name: "get_minutes" + expr: "duration('3730s').getMinutes()" + value: { int64_value: 62 } + } + test { + name: "get_seconds" + expr: "duration('3730s').getSeconds()" + value: { int64_value: 3730 } + } +} +section { + name: "timestamp_range" + description: "Tests for out-of-range operations on timestamps." + test { + name: "from_string_under" + expr: "timestamp('0000-01-01T00:00:00Z')" + eval_error { + errors { message: "range" } + } + } + test { + name: "from_string_over" + expr: "timestamp('10000-01-01T00:00:00Z')" + eval_error { + errors { message: "range" } + } + } + test { + name: "add_duration_under" + expr: "timestamp('0001-01-01T00:00:00Z') + duration('-1s')" + eval_error { + errors { message: "range" } + } + } + test { + name: "add_duration_over" + expr: "timestamp('9999-12-31T23:59:59Z') + duration('1s')" + eval_error { + errors { message: "range" } + } + } + test { + name: "add_duration_nanos_over" + expr: "timestamp('9999-12-31T23:59:59.999999999Z') + duration('1ns')" + eval_error { + errors { message: "range" } + } + } + test { + name: "add_duration_nanos_under" + expr: "timestamp('0001-01-01T00:00:00Z') + duration('-1ns')" + eval_error { + errors { message: "range" } + } + } + test { + name: "sub_time_duration_over" + expr: "timestamp('9999-12-31T23:59:59Z') - timestamp('0001-01-01T00:00:00Z')" + eval_error { + errors { message: "range" } + } + } + test { + name: "sub_time_duration_under" + expr: "timestamp('0001-01-01T00:00:00Z') - timestamp('9999-12-31T23:59:59Z')" + eval_error { + errors { message: "range" } + } + } +} +section { + name: "duration_range" + description: "Tests for out-of-range operations on durations." + test { + name: "from_string_under" + expr: "duration('-320000000000s')" + eval_error { + errors { message: "range" } + } + } + test { + name: "from_string_over" + expr: "duration('320000000000s')" + eval_error { + errors { message: "range" } + } + } + test { + name: "add_under" + expr: "duration('-200000000000s') + duration('-200000000000s')" + eval_error { + errors { message: "range" } + } + } + test { + name: "add_over" + expr: "duration('200000000000s') + duration('200000000000s')" + eval_error { + errors { message: "range" } + } + } + test { + name: "sub_under" + expr: "duration('-200000000000s') - duration('200000000000s')" + eval_error { + errors { message: "range" } + } + } + test { + name: "sub_over" + expr: "duration('200000000000s') - duration('-200000000000s')" + eval_error { + errors { message: "range" } + } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/type_deduction.textproto b/packages/cel-spec/src/testdata/textproto/type_deduction.textproto new file mode 100644 index 00000000..1a0e2611 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/type_deduction.textproto @@ -0,0 +1,953 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "type_deductions" +description: "Tests for type checker deduced types" + +section { + name: "constant_literals" + test { + name: "bool" + expr: "true" + typed_result { + result { + bool_value: true + } + deduced_type { + primitive: BOOL + } + } + } + test { + name: "int" + expr: "42" + typed_result { + result { + int64_value: 42 + } + deduced_type { + primitive: INT64 + } + } + } + test { + name: "uint" + expr: "42u" + typed_result { + result { + uint64_value: 42 + } + deduced_type { + primitive: UINT64 + } + } + } + test { + name: "double" + expr: "0.1" + typed_result { + result { + double_value: 0.1 + } + deduced_type { + primitive: DOUBLE + } + } + } + test { + name: "string" + expr: "\"test\"" + typed_result { + result { + string_value: "test" + } + deduced_type { + primitive: STRING + } + } + } + test { + name: "bytes" + expr: "b\"test\"" + typed_result { + result { + bytes_value: "test" + } + deduced_type { + primitive: BYTES + } + } + } + test { + name: "null" + expr: "null" + typed_result { + result { + null_value: NULL_VALUE + } + deduced_type { + null: NULL_VALUE + } + } + } +} + +section { + name: "complex_initializers" + test { + name: "list" + expr: "[1]" + typed_result { + result { + list_value { + values { + int64_value: 1 + } + } + } + deduced_type { + list_type { elem_type { primitive: INT64 } } + } + } + } + test { + name: "map" + expr: "{'abc': 123}" + typed_result { + result { + map_value { + entries { + key { string_value: "abc" } + value { int64_value: 123 } + } + } + } + deduced_type { + map_type { + key_type { primitive: STRING } + value_type { primitive: INT64 } + } + } + } + } + test { + name: "struct" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int64: 1}" + typed_result { + result { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { + single_int64: 1 + } + } + } + deduced_type { + message_type: "cel.expr.conformance.proto3.TestAllTypes" + } + } + } +} + +section { + name: "field_access" + test { + name: "int_field" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int64: 1}.single_int64" + typed_result { + result { + int64_value: 1 + } + deduced_type { + primitive: INT64 + } + } + } + test { + name: "repeated_int_field" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.repeated_int64" + typed_result { + result { + list_value {} + } + deduced_type { + list_type { elem_type { primitive: INT64 } } + } + } + } + test { + name: "map_bool_int" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.map_bool_int64" + typed_result { + result { + map_value {} + } + deduced_type { + map_type { + key_type { primitive: BOOL } + value_type { primitive: INT64 } + } + } + } + } + test { + name: "enum_field" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.standalone_enum" + typed_result { + result { + int64_value: 0 + } + deduced_type { primitive: INT64 } + } + } + test { + name: "repeated_enum_field" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.repeated_nested_enum" + typed_result { + result { + list_value {} + } + deduced_type { + list_type { elem_type { primitive: INT64 } } + } + } + } + test { + name: "enum_map_field" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{}.map_int32_enum" + typed_result { + result { + map_value {} + } + deduced_type { + map_type { + key_type { primitive: INT64 } + value_type { primitive: INT64 } + } + } + } + } +} + +section { + name: "indexing" + test { + name: "list" + expr: "['foo'][0]" + typed_result { + result { + string_value: "foo" + } + deduced_type { + primitive: STRING + } + } + } + test { + name: "map" + expr: "{'abc': 123}['abc']" + typed_result { + result { + int64_value: 123 + } + deduced_type { + primitive: INT64 + } + } + } +} + +section { + name: "functions" + test { + name: "nested_calls" + expr: "('foo' + 'bar').startsWith('foo')" + typed_result { + result { + bool_value: true + } + deduced_type { + primitive: BOOL + } + } + } + test { + name: "function_result_type" + expr: "fn('abc', 123)" + check_only: true + type_env { + name: "fn" + function { + overloads { + overload_id: "fn_string_int" + result_type { primitive: STRING } + params { primitive: STRING } + params { primitive: INT64 } + } + } + } + typed_result { + deduced_type { + primitive: STRING + } + } + } +} + +# These are somewhat complex expressions for edge cases in type inference. The +# result values are not interesting, but the inferred types are. +section { + name: "flexible_type_parameter_assignment" + test { + name: "list_parameter" + expr: "[[], [[]], [[[]]], [[[[]]]]]" + check_only: true + typed_result { + deduced_type { + list_type { + elem_type { + list_type { + elem_type { + list_type { + elem_type { + list_type { + elem_type { + list_type { + elem_type { dyn {} } + } + } + } + } + } + } + } + } + } + } + } + } + test { + name: "list_parameter_order_independent" + expr: "[[[[[]]]], [], [[[]]]]" + check_only: true + typed_result { + deduced_type { + list_type { + elem_type { + list_type { + elem_type { + list_type { + elem_type { + list_type { + elem_type { + list_type { + elem_type { dyn {} } + } + } + } + } + } + } + } + } + } + } + } + } + test { + name: "comprehension_type_var_aliasing" + expr: "msg.repeated_nested_message.map(x, x).map(y, y.bb)" + check_only: true + type_env { + name: "msg" + ident { + type { + message_type: "cel.expr.conformance.proto3.TestAllTypes" + } + } + } + typed_result { + deduced_type { + list_type { + elem_type { + primitive: INT64 + } + } + } + } + } + test { + name: "overload_type_var_aliasing" + expr: "([] + msg.repeated_nested_message + [])[0].bb" + check_only: true + type_env { + name: "msg" + ident { + type { + message_type: "cel.expr.conformance.proto3.TestAllTypes" + } + } + } + typed_result { + deduced_type { + primitive: INT64 + } + } + } + test { + name: "unconstrained_type_var_as_dyn" + expr: "([].map(x,x))[0].foo" + check_only: true + typed_result { + deduced_type { + dyn {} + } + } + } + test { + name: "list_parameters_do_not_unify" + expr: "[msg.single_int64_wrapper, msg.single_string_wrapper]" + type_env { + name: "msg" + ident { + type { + message_type: "cel.expr.conformance.proto3.TestAllTypes" + } + } + } + check_only: true + typed_result { + deduced_type { + list_type { + elem_type { + dyn {} + } + } + } + } + } + test { + name: "optional_none" + expr: "[optional.none(), optional.of(1)]" + check_only: true + typed_result { + deduced_type { + list_type { + elem_type { + abstract_type { + name: "optional_type" + parameter_types { primitive: INT64 } + } + } + } + } + } + } + test { + name: "optional_none_2" + expr: "[optional.of(1), optional.none()]" + check_only: true + typed_result { + deduced_type { + list_type { + elem_type { + abstract_type { + name: "optional_type" + parameter_types { primitive: INT64 } + } + } + } + } + } + } + test { + name: "optional_dyn_promotion" + expr: "[optional.of(1), optional.of(dyn(1))]" + check_only: true + typed_result { + deduced_type { + list_type { + elem_type { + abstract_type { + name: "optional_type" + parameter_types { dyn {} } + } + } + } + } + } + } + test { + name: "optional_dyn_promotion_2" + expr: "[optional.of(dyn(1)), optional.of(1)]" + check_only: true + typed_result { + deduced_type { + list_type { + elem_type { + abstract_type { + name: "optional_type" + parameter_types { dyn {} } + } + } + } + } + } + } + test { + name: "optional_in_ternary" + expr: "true ? optional.of(dyn(1)) : optional.of(1)" + check_only: true + typed_result { + deduced_type { + abstract_type { + name: "optional_type" + parameter_types { dyn {} } + } + } + } + } +} + +# Wrapper types have some special handling. They generally behave like a union +# type e.g. `null | int64` with auto-unboxing, but there are some quirks. +section { + name: "wrappers" + test { + name: "wrapper_promotion" + type_env { + name: "msg" + ident { + type { + message_type: "cel.expr.conformance.proto3.TestAllTypes" + } + } + } + expr: "[msg.single_int64_wrapper, msg.single_int64]" + check_only: true + typed_result { + deduced_type { + list_type { + elem_type { + wrapper: INT64 + } + } + } + } + } + test { + name: "wrapper_promotion_2" + type_env { + name: "msg" + ident { + type { + message_type: "cel.expr.conformance.proto3.TestAllTypes" + } + } + } + expr: "[msg.single_int64, msg.single_int64_wrapper]" + check_only: true + typed_result { + deduced_type { + list_type { + elem_type { + wrapper: INT64 + } + } + } + } + } + test { + name: "wrapper_dyn_promotion" + type_env { + name: "msg" + ident { + type { + message_type: "cel.expr.conformance.proto3.TestAllTypes" + } + } + } + expr: "[msg.single_int64_wrapper, msg.single_int64, dyn(1)]" + check_only: true + typed_result { + deduced_type { + list_type { + elem_type { + dyn {} + } + } + } + } + } + test { + name: "wrapper_dyn_promotion_2" + type_env { + name: "msg" + ident { + type { + message_type: "cel.expr.conformance.proto3.TestAllTypes" + } + } + } + expr: "[dyn(1), msg.single_int64_wrapper, msg.single_int64]" + check_only: true + typed_result { + deduced_type { + list_type { + elem_type { + dyn {} + } + } + } + } + } + test { + name: "wrapper_primitive_assignable" + type_env { + name: "msg" + ident { + type { + message_type: "cel.expr.conformance.proto3.TestAllTypes" + } + } + } + expr: "msg.single_int64_wrapper + 1" + check_only: true + typed_result { + deduced_type { + primitive: INT64 + } + } + } + test { + name: "wrapper_null_assignable" + type_env { + name: "msg" + ident { + type { + message_type: "cel.expr.conformance.proto3.TestAllTypes" + } + } + } + expr: "msg.single_int64_wrapper == null" + check_only: true + typed_result { + deduced_type { + primitive: BOOL + } + } + } + test { + name: "wrapper_ternary_parameter_assignment" + type_env { + name: "msg" + ident { + type { + message_type: "cel.expr.conformance.proto3.TestAllTypes" + } + } + } + expr: "false ? msg.single_int64_wrapper : null" + check_only: true + typed_result { + deduced_type { + wrapper: INT64 + } + } + } + test { + name: "wrapper_ternary_parameter_assignment_2" + type_env { + name: "msg" + ident { + type { + message_type: "cel.expr.conformance.proto3.TestAllTypes" + } + } + } + expr: "true ? msg.single_int64_wrapper : 42" + check_only: true + typed_result { + deduced_type { + wrapper: INT64 + } + } + } +} + +section { + name: "type_parameters" + test { + name: "multiple_parameters_generality" + check_only: true + expr: "[tuple(1, 2u, 3.0), tuple(dyn(1), dyn(2u), dyn(3.0))][0]" + type_env { + name: "tuple" + function { + overloads { + overload_id: "tuple_T_U_V" + params { type_param: "T" } + params { type_param: "U" } + params { type_param: "V" } + result_type { + abstract_type { + name: "tuple" + parameter_types { type_param: "T" } + parameter_types { type_param: "U" } + parameter_types { type_param: "V" } + } + } + } + } + } + typed_result { + deduced_type { + abstract_type { + name: "tuple" + parameter_types { dyn {} } + parameter_types { dyn {} } + parameter_types { dyn {} } + } + } + } + } + test { + name: "multiple_parameters_generality_2" + check_only: true + expr: "sort(tuple(dyn(1), 2u, 3.0))" + type_env { + name: "tuple" + function { + overloads { + overload_id: "tuple_T_U_V" + params { type_param: "T" } + params { type_param: "U" } + params { type_param: "V" } + result_type { + abstract_type { + name: "tuple" + parameter_types { type_param: "T" } + parameter_types { type_param: "U" } + parameter_types { type_param: "V" } + } + } + } + } + } + type_env { + name: "sort" + function { + overloads { + overload_id: "sort_tuple_T_T_T" + params { + abstract_type { + name: "tuple" + parameter_types { type_param: "T" } + parameter_types { type_param: "T" } + parameter_types { type_param: "T" } + } + } + result_type { + abstract_type { + name: "tuple" + parameter_types { type_param: "T" } + parameter_types { type_param: "T" } + parameter_types { type_param: "T" } + } + } + } + } + } + typed_result { + deduced_type { + abstract_type { + name: "tuple" + parameter_types { dyn {} } + parameter_types { dyn {} } + parameter_types { dyn {} } + } + } + } + } + test { + name: "multiple_parameters_parameterized_ovl" + check_only: true + expr: "tuple(1, 2u, 3.0) == tuple(1, dyn(2u), dyn(3.0))" + type_env { + name: "tuple" + function { + overloads { + overload_id: "tuple_T_U_V" + params { type_param: "T" } + params { type_param: "U" } + params { type_param: "V" } + result_type { + abstract_type { + name: "tuple" + parameter_types { type_param: "T" } + parameter_types { type_param: "U" } + parameter_types { type_param: "V" } + } + } + } + } + } + typed_result { + deduced_type { + primitive: BOOL + } + } + } + test { + name: "multiple_parameters_parameterized_ovl_2" + check_only: true + expr: "tuple(dyn(1), dyn(2u), 3.0) == tuple(1, 2u, 3.0)" + type_env { + name: "tuple" + function { + overloads { + overload_id: "tuple_T_U_V" + params { type_param: "T" } + params { type_param: "U" } + params { type_param: "V" } + result_type { + abstract_type { + name: "tuple" + parameter_types { type_param: "T" } + parameter_types { type_param: "U" } + parameter_types { type_param: "V" } + } + } + } + } + } + typed_result { + deduced_type { + primitive: BOOL + } + } + } +} + +# Messages, some well-known types, and abstract can be assigned from null in the +# CEL type checkers for historical reasons. For backward compatibility, we +# maintain this behavior but it's a bit inconsistent with the intended meaning +# of null (a singleton representing a JSON null literal) in CEL. +section { + name: "legacy_nullable_types" + test { + name: "null_assignable_to_message_parameter_candidate" + type_env { + name: "msg" + ident { + type { + message_type: "cel.expr.conformance.proto3.TestAllTypes" + } + } + } + bindings { + key: "msg" + value { + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] {} + } + } + } + } + expr: "[msg, null][0]" + typed_result { + deduced_type { + message_type: "cel.expr.conformance.proto3.TestAllTypes" + } + result { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] {} + } + } + } + } + test { + name: "null_assignable_to_duration_parameter_candidate" + type_env { + name: "msg" + ident { + type { + message_type: "cel.expr.conformance.proto3.TestAllTypes" + } + } + } + bindings { + key: "msg" + value { + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] {} + } + } + } + } + expr: "[msg.single_duration, null][0]" + typed_result { + deduced_type { + well_known: DURATION + } + result { + object_value { + [type.googleapis.com/google.protobuf.Duration] {} + } + } + } + } + test { + name: "null_assignable_to_timestamp_parameter_candidate" + type_env { + name: "msg" + ident { + type { + message_type: "cel.expr.conformance.proto3.TestAllTypes" + } + } + } + bindings { + key: "msg" + value { + value { + object_value { + [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] {} + } + } + } + } + expr: "[msg.single_timestamp, null][0]" + typed_result { + deduced_type { + well_known: TIMESTAMP + } + result { + object_value { + [type.googleapis.com/google.protobuf.Timestamp] {} + } + } + } + } + test { + name: "null_assignable_to_abstract_parameter_candidate" + expr: "[optional.of(1), null][0]" + check_only: true + typed_result { + deduced_type { + abstract_type { + name: "optional_type" + parameter_types { primitive: INT64 } + } + } + } + } +} diff --git a/packages/cel-spec/src/testdata/textproto/unknowns.textproto b/packages/cel-spec/src/testdata/textproto/unknowns.textproto new file mode 100644 index 00000000..1464f833 --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/unknowns.textproto @@ -0,0 +1,5 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: google.api.expr.test.v1.SimpleTestFile + +name: "unknowns" +description: "Tests for evaluation with unknown inputs." diff --git a/packages/cel-spec/src/testdata/textproto/wrappers.textproto b/packages/cel-spec/src/testdata/textproto/wrappers.textproto new file mode 100644 index 00000000..4ec9e82c --- /dev/null +++ b/packages/cel-spec/src/testdata/textproto/wrappers.textproto @@ -0,0 +1,374 @@ +# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto +# proto-message: cel.expr.conformance.test.SimpleTestFile + +name: "wrappers" +description: "Conformance tests related to wrapper types." + +# google.protobuf.BoolValue +section { + name: "bool" + test { + name: "to_any" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: google.protobuf.BoolValue{value: true}}.single_any" + value { + bool_value: true + } + } + test { + name: "to_json" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: google.protobuf.BoolValue{value: true}}.single_value" + value { + bool_value: true + } + } + test { + name: "to_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_bool_wrapper: null} == TestAllTypes{}" + value { + bool_value: true + } + } +} + +# google.protobuf.Int32Value +section { + name: "int32" + test { + name: "to_any" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: google.protobuf.Int32Value{value: 1}}.single_any" + value { + int64_value: 1 + } + } + test { + name: "to_json" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: google.protobuf.Int32Value{value: 1}}.single_value" + value { + double_value: 1 + } + } + test { + name: "to_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int32_wrapper: null} == TestAllTypes{}" + value { + bool_value: true + } + } +} + +# google.protobuf.Int64Value +section { + name: "int64" + test { + name: "to_any" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: google.protobuf.Int64Value{value: 1}}.single_any" + value { + int64_value: 1 + } + } + test { + name: "to_json_number" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: google.protobuf.Int64Value{value: 1}}.single_value" + value { + double_value: 1 + } + } + test { + name: "to_json_string" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: google.protobuf.Int64Value{value: 9223372036854775807}}.single_value" + value { + string_value: "9223372036854775807" + } + } + test { + name: "to_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_int64_wrapper: null} == TestAllTypes{}" + value { + bool_value: true + } + } +} + +# google.protobuf.UInt32Value +section { + name: "uint32" + test { + name: "to_any" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: google.protobuf.UInt32Value{value: 1u}}.single_any" + value { + uint64_value: 1 + } + } + test { + name: "to_json" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: google.protobuf.UInt32Value{value: 1u}}.single_value" + value { + double_value: 1 + } + } + test { + name: "to_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_uint32_wrapper: null} == TestAllTypes{}" + value { + bool_value: true + } + } +} + +# google.protobuf.UInt64Value +section { + name: "uint64" + test { + name: "to_any" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: google.protobuf.UInt64Value{value: 1u}}.single_any" + value { + uint64_value: 1 + } + } + test { + name: "to_json_number" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: google.protobuf.UInt64Value{value: 1u}}.single_value" + value { + double_value: 1 + } + } + test { + name: "to_json_string" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: google.protobuf.UInt64Value{value: 18446744073709551615u}}.single_value" + value { + string_value: "18446744073709551615" + } + } + test { + name: "to_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_uint64_wrapper: null} == TestAllTypes{}" + value { + bool_value: true + } + } +} + +# google.protobuf.FloatValue +section { + name: "float" + test { + name: "to_any" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: google.protobuf.FloatValue{value: 1.0}}.single_any" + value { + double_value: 1 + } + } + test { + name: "to_json" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: google.protobuf.FloatValue{value: 1.0}}.single_value" + value { + double_value: 1 + } + } + test { + name: "to_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_float_wrapper: null} == TestAllTypes{}" + value { + bool_value: true + } + } +} + +# google.protobuf.DoubleValue +section { + name: "double" + test { + name: "to_any" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: google.protobuf.DoubleValue{value: 1.0}}.single_any" + value { + double_value: 1 + } + } + test { + name: "to_json" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: google.protobuf.DoubleValue{value: 1.0}}.single_value" + value { + double_value: 1 + } + } + test { + name: "to_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_double_wrapper: null} == TestAllTypes{}" + value { + bool_value: true + } + } +} + +# google.protobuf.BytesValue +section { + name: "bytes" + test { + name: "to_any" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: google.protobuf.BytesValue{value: b'foo'}}.single_any" + value { + bytes_value: "foo" + } + } + test { + name: "to_json" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: google.protobuf.BytesValue{value: b'foo'}}.single_value" + value { + string_value: "Zm9v" + } + } + test { + name: "to_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_bytes_wrapper: null} == TestAllTypes{}" + value { + bool_value: true + } + } +} + +# google.protobuf.StringValue +section { + name: "string" + test { + name: "to_any" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: google.protobuf.StringValue{value: 'foo'}}.single_any" + value { + string_value: "foo" + } + } + test { + name: "to_json" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: google.protobuf.StringValue{value: 'foo'}}.single_value" + value { + string_value: "foo" + } + } + test { + name: "to_null" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_string_wrapper: null} == TestAllTypes{}" + value { + bool_value: true + } + } +} + +# google.protobuf.Value +section { + name: "value" + test { + name: "default_to_json" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: TestAllTypes{}.single_value}.single_any" + value { + null_value: NULL_VALUE + } + } +} + +# google.protobuf.ListValue +section { + name: "list_value" + description: "" + test { + name: "literal_to_any" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: []}.single_any" + value { + list_value {} + } + } +} + +# google.protobuf.Struct +section { + name: "struct" + test { + name: "literal_to_any" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_any: {}}.single_any" + value { + map_value {} + } + } +} + +# google.protobuf.FieldMask +section { + name: "field_mask" + test { + name: "to_json" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: google.protobuf.FieldMask{paths: ['foo', 'bar']}}.single_value" + value { + string_value: "foo,bar" + } + } +} + +# google.protobuf.Duration +section { + name: "duration" + test { + name: "to_json" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: duration('1000000s')}.single_value" + value { + string_value: "1000000s" + } + } +} + +# google.protobuf.Timestamp +section { + name: "timestamp" + test { + name: "to_json" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: timestamp('9999-12-31T23:59:59.999999999Z')}.single_value" + value { + string_value: "9999-12-31T23:59:59.999999999Z" + } + } +} + +# google.protobuf.Empty +section { + name: "empty" + test { + name: "to_json" + container: "cel.expr.conformance.proto3" + expr: "TestAllTypes{single_value: google.protobuf.Empty{}}.single_value" + value { + map_value {} + } + } +} diff --git a/packages/cel-spec/turbo.json b/packages/cel-spec/turbo.json index a60951e3..e41fb2f4 100644 --- a/packages/cel-spec/turbo.json +++ b/packages/cel-spec/turbo.json @@ -10,8 +10,8 @@ }, "fetch-testdata": { "inputs": ["scripts/fetch-testdata.js", "package.json"], - "outputs": ["src/testdata/conformance.ts", "src/testdata/json/*.json"], - "dependsOn": ["fetch-proto"], + "outputs": ["src/testdata/textproto/*.textproto"], + "dependsOn": [], "outputLogs": "new-only" }, "fetch-parsing": { @@ -39,7 +39,7 @@ "scripts/*.go", "scripts/go.*", "package.json", - "src/testdata/json/*.json" + "src/testdata/textproto/*.textproto" ], "outputs": ["src/testdata/conformance.ts"], "env": ["GO*"],