Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions proto/cel/expr/conformance/test/env/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
load("@com_google_protobuf//bazel:java_proto_library.bzl", "java_proto_library")
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library")

package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:public"],
licenses = ["notice"], # Apache 2.0
)

proto_library(
name = "suite_proto",
srcs = ["suite.proto"],
strip_import_prefix = "/proto",
deps = [
"//proto/cel/expr/conformance/test:suite_proto",
"@cel_spec//proto/cel/expr:eval_proto",
"@cel_spec//proto/cel/expr:value_proto",
"@cel_spec//proto/cel/expr/conformance:env_config_proto",
],
)

cc_proto_library(
name = "suite_cc_proto",
deps = [":suite_proto"],
)

java_proto_library(
name = "suite_java_proto",
deps = [":suite_proto"],
)

py_proto_library(
name = "suite_py_pb2",
deps = [":suite_proto"],
)
98 changes: 98 additions & 0 deletions proto/cel/expr/conformance/test/env/suite.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package cel.expr.conformance.test.env;

import "cel/expr/conformance/env_config.proto";
import "cel/expr/value.proto";
import "cel/expr/conformance/test/suite.proto";

option cc_enable_arenas = true;
option go_package = "cel.dev/expr/conformance/test/env";
option java_multiple_files = true;
option java_outer_classname = "SuiteProto";
option java_package = "dev.cel.expr.conformance.test.env";

// A test suite is a collection of tests designed to evaluate the correctness of
// a CEL environment.
message TestSuite {
// The name of the test suite.
string name = 1;

// Description of the test suite.
string description = 2;

// Test sections of the test suite.
// Each section represents a behavior to be tested.
repeated TestSection sections = 3;
}

// A collection of related test cases.
message TestSection {
// Name of the test section.
string name = 1;

// Description of the test section.
string description = 2;

// Test cases of the test section.
// Each test case represents a test scenario.
repeated TestCase tests = 3;
}

// A test case which validates the behavior of a CEL environment.
message TestCase {
// Name of the test case.
string name = 1;

// A description of the test.
string description = 2;

oneof env_config {
// The environment to be used for compilation and evaluation of the CEL
// expression for the current test case, specified as a YAML string.
string env_yaml = 3;

// The environment to be used for compilation and evaluation of the CEL
// expression for the current test case.
cel.expr.conformance.Environment env = 4;
}

// The text of the CEL expression.
string expr = 5;

// A map representing a variable binding where the key is the name of the
// input variable.
map<string, cel.expr.conformance.test.InputValue> input = 6;

// Expected result of the test case.
TestOutput output = 7;
}

// Expected result of the test case.
message TestOutput {
// The expected exported environment YAML of the test case.
string exported_env_yaml = 1;

// A normal value, which must match the evaluation result exactly via value
// equality semantics. This coincides with proto equality, except for:
// * maps are order-agnostic
// * a floating point NaN should match any NaN
cel.expr.Value result_value = 2;

// Expected error substrings. Success if all expected errors match.
repeated string errors = 4;
}
26 changes: 26 additions & 0 deletions tests/env/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package(
default_applicable_licenses = ["//:license"],
default_visibility = ["//visibility:public"],
licenses = ["notice"], # Apache 2.0
)

exports_files(glob(["testdata/*.textproto"]))

filegroup(
name = "env_testdata",
srcs = glob(["testdata/*.textproto"]),
)
117 changes: 117 additions & 0 deletions tests/env/testdata/type_signatures.textproto
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# proto-file: ../../../proto/cel/expr/conformance/test/env/suite.proto
# proto-message: cel.expr.conformance.test.env.TestSuite

name: "type_signatures"
description: "Conformance tests for canonical CEL type signatures and aliases."

sections {
name: "primitives"
description: "Canonical primitive types and aliases."

tests {
name: "bool"
description: "Canonical bool type."
env_yaml:
"variables:\n"
" - name: x\n"
" type: bool\n"
expr: "!x"
input {
key: "x"
value {
value {
bool_value: true
}
}
}
output {
exported_env_yaml:
"variables:\n"
" - name: x\n"
" type: bool\n"
result_value {
bool_value: false
}
}
}
}

sections {
name: "timestamp"
description: "Canonical timestamp type and protobuf alias."

tests {
name: "timestamp"
description: "Canonical timestamp type."
env_yaml:
"variables:\n"
" - name: x\n"
" type: timestamp\n"
expr: "x + duration('1h')"
input {
key: "x"
value {
expr: "timestamp('2026-01-01T00:00:00Z')"
}
}
output {
exported_env_yaml:
"variables:\n"
" - name: x\n"
" type: timestamp\n"
result_value {
object_value {
[type.googleapis.com/google.protobuf.Timestamp] {
seconds: 1767229200
}
}
}
}
}

tests {
name: "timestamp_alias"
description: "Alias google.protobuf.Timestamp normalizes to timestamp."
env_yaml:
"variables:\n"
" - name: x\n"
" type: google.protobuf.Timestamp\n"
expr: "x + duration('1h')"
input {
key: "x"
value {
expr: "timestamp('2026-01-01T00:00:00Z')"
}
}
output {
exported_env_yaml:
"variables:\n"
" - name: x\n"
" type: timestamp\n"
result_value {
object_value {
[type.googleapis.com/google.protobuf.Timestamp] {
seconds: 1767229200
}
}
}
}
}
}

sections {
name: "errors"
description: "Invalid type signatures."

tests {
name: "unterminated_map"
description: "Malformed map type signature missing value type and closing bracket."
env_yaml:
"variables:\n"
" - name: x\n"
" type: \"map<int,\"\n"
output {
errors: "Invalid type signature"
}
}
}
Loading