Skip to content

Commit

Permalink
feat: support multiple expressions in string interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
arjendev committed Dec 1, 2023
1 parent bd99c36 commit cccccd2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self) -> None:
| LITERAL_NULL
| literal_array
literal_array: "[" literal_evaluation ("," literal_evaluation)* "]"
literal_interpolation: LITERAL_LETTER* "@{" expression_evaluation "}" LITERAL_LETTER*
literal_interpolation: (LITERAL_LETTER* "@{" expression_evaluation "}" LITERAL_LETTER*)*
// literal terminals:
Expand Down
48 changes: 48 additions & 0 deletions tests/unit/functions/test_expression_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,43 @@
),
id="string_interpolation",
),
p(
"/repos/@{pipeline().globalParameters.OpsPrincipalClientId}/@{pipeline().parameters.SubPath}",
Tree(
Token("RULE", "literal_interpolation"),
[
Token("LITERAL_LETTER", "/repos/"),
Tree(
Token("RULE", "expression_evaluation"),
[
Tree(
Token("RULE", "expression_pipeline_reference"),
[
Token("EXPRESSION_PIPELINE_PROPERTY", "globalParameters"),
Token("EXPRESSION_PARAMETER_NAME", "OpsPrincipalClientId"),
],
),
Tree(Token("RULE", "expression_array_indices"), [None]),
],
),
Token("LITERAL_LETTER", "/"),
Tree(
Token("RULE", "expression_evaluation"),
[
Tree(
Token("RULE", "expression_pipeline_reference"),
[
Token("EXPRESSION_PIPELINE_PROPERTY", "parameters"),
Token("EXPRESSION_PARAMETER_NAME", "SubPath"),
],
),
Tree(Token("RULE", "expression_array_indices"), [None]),
],
),
],
),
id="string_interpolation_multiple_expressions",
),
],
)
def test_parse(expression: str, expected: Tree[Token]) -> None:
Expand Down Expand Up @@ -655,6 +692,17 @@ def test_parse(expression: str, expected: Tree[Token]) -> None:
"/Repos/dummyId/",
id="string_interpolation_with_literals",
),
p(
"/Repos/@{pipeline().globalParameters.OpsPrincipalClientId}/@{pipeline().parameters.SubPath}",
PipelineRunState(
parameters=[
RunParameter(RunParameterType.Global, "OpsPrincipalClientId", "dummyId"),
RunParameter(RunParameterType.Pipeline, "SubPath", "dummyPath"),
]
),
"/Repos/dummyId/dummyPath",
id="string_interpolation_with_multiple_expressions",
),
],
)
@freeze_time("2021-11-24 12:11:49.753132")
Expand Down

0 comments on commit cccccd2

Please sign in to comment.