Fix format dict props (#641)

This commit is contained in:
Nikhil Rao 2023-03-06 17:38:21 -08:00 committed by GitHub
parent d74efb9bff
commit 3491955995
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -108,6 +108,7 @@ class Tag(Base):
# This substitution is necessary to unwrap var values.
prop = re.sub('"{', "", prop)
prop = re.sub('}"', "", prop)
prop = re.sub('\\\\"', '"', prop)
# Wrap the variable in braces.
assert isinstance(prop, str), "The prop must be a string."

View File

@ -39,9 +39,18 @@ def mock_event(arg):
),
'{(e) => Event([E("mock_event", {arg:e.target.value})])}',
),
({"a": "red", "b": "blue"}, '{{"a": "red", "b": "blue"}}'),
(BaseVar(name="var", type_="int"), "{var}"),
(BaseVar(name='state.colors["a"]', type_="str"), '{state.colors["a"]}'),
({"a": BaseVar(name="val", type_="str")}, '{{"a": val}}'),
({"a": BaseVar(name='"val"', type_="str")}, '{{"a": "val"}}'),
(
{"a": BaseVar(name='state.colors["val"]', type_="str")},
'{{"a": state.colors["val"]}}',
),
],
)
def test_format_value(prop: Var, formatted: str):
def test_format_prop(prop: Var, formatted: str):
"""Test that the formatted value of an prop is correct.
Args: