From 509c0821c0b2d8e0302f08fbeaf926aa861633e0 Mon Sep 17 00:00:00 2001 From: Tristan Swadell Date: Wed, 22 Jul 2026 16:55:09 -0700 Subject: [PATCH] Create CEL API Reference and link it from README and sitemap. Add a unified API Reference document for CEL macros, operators, and functions under third_party/cel/spec/docs/api-reference.md. This document includes a support matrix for Go, C++, Java, Python, and C (runtime-only) stacks, with granular introduction release versions for each individual function. Key changes: - Added 'Stack Versions' section listing documented release versions of CEL. - Added 'Network Library' section documenting the Go-only IP/CIDR functions. - Granularized compatibility tables to document the exact introduction release version of each individual function instead of the library addition. - Split bundled function rows (Bitwise, Rounding, Classification, first/last, Lower/Upper) into individual rows with independent versioning. - Corrected C++ and Java compatibility for `json.encode` (marked as unsupported). - Updated Python compatibility checkmarks and enablement notes for Lists, Sets, Two-Variable Comprehensions, and Regex (supported via config). - Added Python unit tests verifying standard extensions (Lists, Sets, Two-Var Comprehensions, Regex) can be enabled via config. - Revised the LLM prompt for API doc generation to mirror the final doc layout. PiperOrigin-RevId: 952408595 --- cel_expr_python/cel_env_test.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cel_expr_python/cel_env_test.py b/cel_expr_python/cel_env_test.py index eacfc9f..af1de62 100644 --- a/cel_expr_python/cel_env_test.py +++ b/cel_expr_python/cel_env_test.py @@ -490,6 +490,34 @@ def test_config_extensions(self): res = env.compile("hello('World')").eval() self.assertEqual(res.value(), "Hello, World!") + def test_standard_extensions_via_config(self): + config: cel.EnvConfig = cel.NewEnvConfigFromYaml(""" + extensions: + - name: lists + - name: sets + - name: two-var-comprehensions + - name: optional + - name: regex + """) + env: cel.Env = cel.NewEnv(config=config) + + # Test lists extension (e.g., reverse) + res = env.compile("[1, 2].reverse()").eval() + self.assertEqual(res.plain_value(), [2, 1]) + + # Test sets extension (e.g., intersects) + res = env.compile("sets.intersects([1, 2], [2, 3])").eval() + self.assertEqual(res.value(), True) + + # Test two-var-comprehensions (e.g., all) + res = env.compile("[1, 2].all(i, v, v > 0)").eval() + self.assertEqual(res.value(), True) + + # Test regex extension (e.g., replace) + expr = r"regex.replace('123-456', r'(\d+)-(\d+)', r'\2-\1')" + res = env.compile(expr).eval() + self.assertEqual(res.value(), "456-123") + def test_config_extension_override_same_version(self): config: cel.EnvConfig = cel.NewEnvConfigFromYaml(""" extensions: