From 30743c9cf9b66fccfca83e8a580ce81810f76798 Mon Sep 17 00:00:00 2001 From: Sokwhan Huh Date: Fri, 2 Aug 2024 19:33:54 +0000 Subject: [PATCH 1/6] Remove trailing whitespaces --- doc/langdef.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/langdef.md b/doc/langdef.md index 0ab6481..37f2f5f 100644 --- a/doc/langdef.md +++ b/doc/langdef.md @@ -708,13 +708,13 @@ macros are: function given by the expression `t`, which can use the variable `x`. For instance, `[1, 2, 3].map(n, n * n)` evaluates to `[1, 4, 9]`. Any evaluation error for any element causes the macro to raise an error. - * transforms a map `e` by taking each key in the map `x` to the function + * transforms a map `e` by taking each key in the map `x` to the function given by the expression `t`, which can use the variable `x`. For - instance, `{'one': 1, 'two': 2}.map(k, k)` evaluates to `['one', 'two']`. + instance, `{'one': 1, 'two': 2}.map(k, k)` evaluates to `['one', 'two']`. Any evaluation error for any element causes the macro to raise an error. * `e.map(x, p, t)`: Same as the two-arg map but with a conditional `p` filter before the value is transformed. -* `e.filter(x, p)`: +* `e.filter(x, p)`: * for a list `e`, returns the sublist of all elements `x` which evaluate to `true` in the predicate expression `p` (which can use variable `x`). For instance, `[1, 2, 3].filter(i, i % 2 > 0)` evaluates to `[1, 3]`. From 099aa6c22f2967051fb8c9ef92bbe2cbaca00143 Mon Sep 17 00:00:00 2001 From: Sokwhan Huh Date: Fri, 2 Aug 2024 19:36:41 +0000 Subject: [PATCH 2/6] Add string to bool conversion overload to the standard definitions --- doc/langdef.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/langdef.md b/doc/langdef.md index 37f2f5f..785234e 100644 --- a/doc/langdef.md +++ b/doc/langdef.md @@ -1835,7 +1835,7 @@ See [cel-go/issues/9](https://github.com/google/cel-go/issues/9). - + bool @@ -1853,6 +1853,14 @@ See [cel-go/issues/9](https://github.com/google/cel-go/issues/9). identity + + + (string) -> bool + + + type conversion + + bytes From 25c43a789af67523f93702140cd6640bce6c1a91 Mon Sep 17 00:00:00 2001 From: Sokwhan Huh Date: Fri, 2 Aug 2024 19:40:25 +0000 Subject: [PATCH 3/6] Remove trailing whitespace from proot3.textproto --- tests/simple/testdata/proto3.textproto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/simple/testdata/proto3.textproto b/tests/simple/testdata/proto3.textproto index 3d98d8c..2d1fcbf 100644 --- a/tests/simple/testdata/proto3.textproto +++ b/tests/simple/testdata/proto3.textproto @@ -724,7 +724,7 @@ section { eval_error: { errors: { message: "unsupported field type" } } - } + } test { name: "list_value" container: "google.api.expr.test.v1.proto3" From 4738187632c6200190a6af49ac474f47c3e02136 Mon Sep 17 00:00:00 2001 From: Sokwhan Huh Date: Fri, 2 Aug 2024 21:07:45 +0000 Subject: [PATCH 4/6] Add conformance tests for string to boolean conversions --- tests/simple/testdata/conversions.textproto | 54 +++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/simple/testdata/conversions.textproto b/tests/simple/testdata/conversions.textproto index 75ffddd..00ee018 100644 --- a/tests/simple/testdata/conversions.textproto +++ b/tests/simple/testdata/conversions.textproto @@ -505,6 +505,60 @@ section { 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 } + } +} section { name: "identity" description: "Identity functions" From 25e2451ccb92c311ca8467e196f55a3930915057 Mon Sep 17 00:00:00 2001 From: Sokwhan Huh Date: Fri, 2 Aug 2024 21:18:25 +0000 Subject: [PATCH 5/6] Add conformance test cases for bad conversions --- tests/simple/testdata/conversions.textproto | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/simple/testdata/conversions.textproto b/tests/simple/testdata/conversions.textproto index 00ee018..bbf6c41 100644 --- a/tests/simple/testdata/conversions.textproto +++ b/tests/simple/testdata/conversions.textproto @@ -558,6 +558,20 @@ section { 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" From 1ff4d422eba40c99eb5ecaec9985d6da32fe5065 Mon Sep 17 00:00:00 2001 From: Sokwhan Huh Date: Fri, 2 Aug 2024 22:04:14 +0000 Subject: [PATCH 6/6] Change bytes identity test to accept a byte literal --- tests/simple/testdata/conversions.textproto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/simple/testdata/conversions.textproto b/tests/simple/testdata/conversions.textproto index bbf6c41..ed8f408 100644 --- a/tests/simple/testdata/conversions.textproto +++ b/tests/simple/testdata/conversions.textproto @@ -603,7 +603,7 @@ section { } test { name: "bytes" - expr: "bytes(bytes('abc'))" + expr: "bytes(b'abc')" value: { bytes_value: "abc" } } test {