-
Notifications
You must be signed in to change notification settings - Fork 1.3k
test(conformance): add a cross-language conformance suite for the expression parser #2497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
diegolopezrm
wants to merge
7
commits into
a2ui-project:main
Choose a base branch
from
diegolopezrm:feat-expression-parser-conformance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c9777f3
fix(dart, web_core): reject invalid number literals with a protocol e…
diegolopezrm 1d6510e
test(conformance): add a shared suite for the client-side expression …
diegolopezrm 45dc82f
test(dart): run the expression parser conformance suite
diegolopezrm 00245b0
test(web_core): run the expression parser conformance suite
diegolopezrm e83a331
fix(dart, web_core): fix the number literal grammar in the parsers
diegolopezrm 9d8befd
test(conformance): validate the suite against all four implementations
diegolopezrm a760f86
Merge remote-tracking branch 'upstream/main' into feat-expression-par…
diegolopezrm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| # Copyright 2024 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. | ||
|
|
||
| # Conformance cases for the client-side expression parser that backs | ||
| # `formatString` in the basic catalog, as described in | ||
| # specification/v0_9/docs/basic_catalog_implementation_guide.md. | ||
| # | ||
| # `input` is the template string handed to the parser. `expect` is the sequence | ||
| # of parsed parts: literal strings, data bindings ({path: ...}) and function | ||
| # calls ({call: ..., args: ..., returnType: ...}). Harnesses compare the parsed | ||
| # parts with adjacent literals joined, so a case fixes what a template means, | ||
| # not how an implementation happens to split its literal runs. | ||
|
|
||
| - name: test_expr_plain_text_is_one_literal | ||
| description: A template with no interpolation yields the input unchanged. | ||
| action: parse_expression_template | ||
| input: "hello world" | ||
| expect: ["hello world"] | ||
|
|
||
| - name: test_expr_empty_template | ||
| description: An empty template yields a single empty literal. | ||
| action: parse_expression_template | ||
| input: "" | ||
| expect: [""] | ||
|
|
||
| - name: test_expr_relative_path | ||
| description: A bare identifier is a relative data binding. | ||
| action: parse_expression_template | ||
| input: "${user}" | ||
| expect: [{path: "user"}] | ||
|
|
||
| - name: test_expr_absolute_path | ||
| description: An identifier starting with a slash is an absolute data binding. | ||
| action: parse_expression_template | ||
| input: "value is ${/user/name}" | ||
| expect: ["value is ", {path: "/user/name"}] | ||
|
|
||
| - name: test_expr_path_with_punctuation | ||
| description: Dots, dashes and underscores are part of a path. | ||
| action: parse_expression_template | ||
| input: "${my-path.with_underscores}" | ||
| expect: [{path: "my-path.with_underscores"}] | ||
|
|
||
| - name: test_expr_literal_between_bindings | ||
| description: Literal text surrounding interpolations is preserved. | ||
| action: parse_expression_template | ||
| input: "a ${x} b ${y} c" | ||
| expect: ["a ", {path: "x"}, " b ", {path: "y"}, " c"] | ||
|
|
||
| - name: test_expr_adjacent_bindings | ||
| description: Interpolations with nothing between them stay separate parts. | ||
| action: parse_expression_template | ||
| input: "${x}${y}" | ||
| expect: [{path: "x"}, {path: "y"}] | ||
|
|
||
| - name: test_expr_single_quoted_string | ||
| description: Single-quoted literals parse to their contents. | ||
| action: parse_expression_template | ||
| input: "${'hello world'}" | ||
| expect: ["hello world"] | ||
|
|
||
| - name: test_expr_double_quoted_string | ||
| description: Double-quoted literals parse to their contents. | ||
| action: parse_expression_template | ||
| input: '${"hello world"}' | ||
| expect: ["hello world"] | ||
|
|
||
| - name: test_expr_string_escapes | ||
| description: Backslash escapes inside string literals are unescaped. | ||
| action: parse_expression_template | ||
| input: "${'line\\nbreak'}" | ||
| expect: ["line\nbreak"] | ||
|
|
||
| - name: test_expr_string_escaped_quote | ||
| description: An escaped quote does not terminate the literal. | ||
| action: parse_expression_template | ||
| input: "${'it\\'s'}" | ||
| expect: ["it's"] | ||
|
|
||
| - name: test_expr_integer_literal | ||
| description: Integer literals parse to numbers. | ||
| action: parse_expression_template | ||
| input: "${42}" | ||
| expect: [42] | ||
|
|
||
| - name: test_expr_decimal_literal | ||
| description: Decimal literals parse to numbers. | ||
| action: parse_expression_template | ||
| input: "${1.5}" | ||
| expect: [1.5] | ||
|
|
||
| - name: test_expr_leading_zeros | ||
| description: Leading zeros do not change the value. | ||
| action: parse_expression_template | ||
| input: "${007}" | ||
| expect: [7] | ||
|
|
||
| - name: test_expr_boolean_literals | ||
| description: The true and false keywords parse to booleans. | ||
| action: parse_expression_template | ||
| input: "${true} ${false}" | ||
| expect: [true, " ", false] | ||
|
|
||
| - name: test_expr_keyword_prefix_is_a_path | ||
| description: An identifier that merely starts with a keyword is a path. | ||
| action: parse_expression_template | ||
| input: "${trueish}" | ||
| expect: [{path: "trueish"}] | ||
|
|
||
| - name: test_expr_function_call_no_args | ||
| description: A function call with no arguments parses to an empty args map. | ||
| action: parse_expression_template | ||
| input: "${now()}" | ||
| expect: [{call: "now", args: {}, returnType: "any"}] | ||
|
|
||
| - name: test_expr_function_call_named_args | ||
| description: Function arguments are named and comma separated. | ||
| action: parse_expression_template | ||
| input: "sum is ${add(a: 10, b: 20)}" | ||
| expect: ["sum is ", {call: "add", args: {a: 10, b: 20}, returnType: "any"}] | ||
|
|
||
| - name: test_expr_function_call_mixed_arg_types | ||
| description: Arguments may be literals, paths or nested calls. | ||
| action: parse_expression_template | ||
| input: "${format(value: /amount, suffix: ' USD', fallback: zero())}" | ||
| expect: | ||
| - call: "format" | ||
| args: | ||
| value: {path: "/amount"} | ||
| suffix: " USD" | ||
| fallback: {call: "zero", args: {}, returnType: "any"} | ||
| returnType: "any" | ||
|
|
||
| - name: test_expr_nested_function_calls | ||
| description: Function arguments may themselves be function calls. | ||
| action: parse_expression_template | ||
| input: "${outer(a: inner(b: 1))}" | ||
| expect: | ||
| - call: "outer" | ||
| args: | ||
| a: {call: "inner", args: {b: 1}, returnType: "any"} | ||
| returnType: "any" | ||
|
|
||
| - name: test_expr_nested_interpolation | ||
| description: An interpolation inside an interpolation resolves to the inner expression. | ||
| action: parse_expression_template | ||
| input: "${${'hello'}}" | ||
| expect: ["hello"] | ||
|
|
||
| - name: test_expr_whitespace_around_expression | ||
| description: Whitespace inside the interpolation braces is ignored. | ||
| action: parse_expression_template | ||
| input: "${ /user/name }" | ||
| expect: [{path: "/user/name"}] | ||
|
|
||
| - name: test_expr_escaped_marker_is_literal | ||
| description: An escaped marker resolves to a literal "${" and is not interpolated. | ||
| action: parse_expression_template | ||
| input: "\\${not_interpolated}" | ||
| expect: ["${not_interpolated}"] | ||
|
|
||
| - name: test_expr_escaped_marker_between_text | ||
| description: An escaped marker inside surrounding text stays literal. | ||
| action: parse_expression_template | ||
| input: "before \\${x} after" | ||
| expect: ["before ${x} after"] | ||
|
|
||
| - name: test_expr_escaped_and_real_marker | ||
| description: An escaped marker and a real interpolation can appear in one template. | ||
| action: parse_expression_template | ||
| input: "\\${literal} ${real}" | ||
| expect: ["${literal} ", {path: "real"}] | ||
|
|
||
| - name: test_expr_error_unclosed_interpolation | ||
| description: A template whose interpolation is never closed is rejected. | ||
| action: parse_expression_template | ||
| input: "hello ${world" | ||
| expect_error: | ||
| category: "ParseError" | ||
| message: "Unclosed interpolation" | ||
|
|
||
| - name: test_expr_error_missing_closing_paren | ||
| description: A function call whose parentheses are unbalanced is rejected. | ||
| action: parse_expression_template | ||
| input: "${add(a: 1, b: 2}" | ||
| expect_error: | ||
| category: "ParseError" | ||
| message: "after function arguments" | ||
|
|
||
| - name: test_expr_error_missing_arg_colon | ||
| description: A function argument without a colon is rejected. | ||
| action: parse_expression_template | ||
| input: "${add(a 1)}" | ||
| expect_error: | ||
| category: "ParseError" | ||
| message: "after argument name" | ||
|
|
||
| - name: test_expr_error_trailing_characters | ||
| description: Characters after a complete expression are rejected. | ||
| action: parse_expression_template | ||
| input: "${true false}" | ||
| expect_error: | ||
| category: "ParseError" | ||
| message: "Unexpected characters" | ||
|
|
||
| - name: test_expr_error_invalid_number_two_points | ||
| description: A number literal with two decimal points is rejected as a protocol error. | ||
| action: parse_expression_template | ||
| input: "${1.2.3}" | ||
| expect_error: | ||
| category: "ParseError" | ||
| message: "Invalid number literal" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,3 +30,4 @@ dependencies: | |
|
|
||
| dev_dependencies: | ||
| test: ^1.26.2 | ||
| yaml: ^3.1.2 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
num.tryParse(text)can lead to platform-specific discrepancies between Dart VM and Dart Web (where it compiles to JavaScript'sparseFloat/Numberand might accept trailing or leading decimals like1.or.5that Dart VM rejects).To guarantee strict 1:1 behavioral parity across all platforms and client implementations, we should validate the parsed number literal against a standardized decimal/integer regular expression before parsing it.
References
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same change applied here; see the reply on the TypeScript side for the measurements, including a dart2js run that shows the VM and web behave the same on these inputs.