format: event arg values use backticks (#1926)

This commit is contained in:
Masen Furer 2023-10-17 10:42:35 -07:00 committed by GitHub
parent 1efc61e1c4
commit d1d5812602
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 14 deletions

View File

@ -420,7 +420,7 @@ def format_event(event_spec: EventSpec) -> str:
":".join(
(
name._var_name,
json.dumps(val._var_name)
wrap(json.dumps(val._var_name).strip('"'), "`")
if val._var_is_string
else val._var_full_name,
)

View File

@ -68,7 +68,7 @@ def test_call_event_handler():
event_spec = handler("first", "second") # type: ignore
assert (
format.format_event(event_spec)
== 'Event("test_fn_with_args", {arg1:"first",arg2:"second"})'
== 'Event("test_fn_with_args", {arg1:`first`,arg2:`second`})'
)
first, second = 123, "456"
@ -76,7 +76,7 @@ def test_call_event_handler():
event_spec = handler(first, second) # type: ignore
assert (
format.format_event(event_spec)
== 'Event("test_fn_with_args", {arg1:123,arg2:"456"})'
== 'Event("test_fn_with_args", {arg1:123,arg2:`456`})'
)
assert event_spec.handler == handler
@ -122,9 +122,9 @@ def test_fix_events(arg1, arg2):
@pytest.mark.parametrize(
"input,output",
[
(("/path", None), 'Event("_redirect", {path:"/path",external:false})'),
(("/path", True), 'Event("_redirect", {path:"/path",external:true})'),
(("/path", False), 'Event("_redirect", {path:"/path",external:false})'),
(("/path", None), 'Event("_redirect", {path:`/path`,external:false})'),
(("/path", True), 'Event("_redirect", {path:`/path`,external:true})'),
(("/path", False), 'Event("_redirect", {path:`/path`,external:false})'),
(
(Var.create_safe("path"), None),
'Event("_redirect", {path:path,external:false})',
@ -160,7 +160,7 @@ def test_event_console_log():
assert spec.handler.fn.__qualname__ == "_console"
assert spec.args[0][0].equals(Var.create_safe("message"))
assert spec.args[0][1].equals(Var.create_safe("message"))
assert format.format_event(spec) == 'Event("_console", {message:"message"})'
assert format.format_event(spec) == 'Event("_console", {message:`message`})'
spec = event.console_log(Var.create_safe("message"))
assert format.format_event(spec) == 'Event("_console", {message:message})'
@ -172,7 +172,7 @@ def test_event_window_alert():
assert spec.handler.fn.__qualname__ == "_alert"
assert spec.args[0][0].equals(Var.create_safe("message"))
assert spec.args[0][1].equals(Var.create_safe("message"))
assert format.format_event(spec) == 'Event("_alert", {message:"message"})'
assert format.format_event(spec) == 'Event("_alert", {message:`message`})'
spec = event.window_alert(Var.create_safe("message"))
assert format.format_event(spec) == 'Event("_alert", {message:message})'
@ -198,7 +198,7 @@ def test_set_value():
assert spec.args[0][1].equals(Var.create_safe("ref_input1"))
assert spec.args[1][0].equals(Var.create_safe("value"))
assert spec.args[1][1].equals(Var.create_safe(""))
assert format.format_event(spec) == 'Event("_set_value", {ref:ref_input1,value:""})'
assert format.format_event(spec) == 'Event("_set_value", {ref:ref_input1,value:``})'
spec = event.set_value("input1", Var.create_safe("message"))
assert (
format.format_event(spec)
@ -217,7 +217,7 @@ def test_set_cookie():
assert spec.args[1][1].equals(Var.create_safe("testvalue"))
assert (
format.format_event(spec)
== 'Event("_set_cookie", {key:"testkey",value:"testvalue"})'
== 'Event("_set_cookie", {key:`testkey`,value:`testvalue`})'
)
@ -232,7 +232,7 @@ def test_remove_cookie():
assert spec.args[1][1].equals(Var.create_safe({}))
assert (
format.format_event(spec)
== 'Event("_remove_cookie", {key:"testkey",options:{}})'
== 'Event("_remove_cookie", {key:`testkey`,options:{}})'
)
@ -253,7 +253,7 @@ def test_remove_cookie_with_options():
assert spec.args[1][1].equals(Var.create_safe(options))
assert (
format.format_event(spec)
== f'Event("_remove_cookie", {{key:"testkey",options:{json.dumps(options)}}})'
== f'Event("_remove_cookie", {{key:`testkey`,options:{json.dumps(options)}}})'
)
@ -268,7 +268,7 @@ def test_set_local_storage():
assert spec.args[1][1].equals(Var.create_safe("testvalue"))
assert (
format.format_event(spec)
== 'Event("_set_local_storage", {key:"testkey",value:"testvalue"})'
== 'Event("_set_local_storage", {key:`testkey`,value:`testvalue`})'
)
@ -289,5 +289,5 @@ def test_remove_local_storage():
assert spec.args[0][0].equals(Var.create_safe("key"))
assert spec.args[0][1].equals(Var.create_safe("testkey"))
assert (
format.format_event(spec) == 'Event("_remove_local_storage", {key:"testkey"})'
format.format_event(spec) == 'Event("_remove_local_storage", {key:`testkey`})'
)