mirror of
https://github.com/home-assistant/core.git
synced 2025-08-07 22:55:10 +02:00
Add search
and match
as Jinja tests (#49229)
This commit is contained in:
@@ -1459,6 +1459,8 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment):
|
|||||||
self.globals["urlencode"] = urlencode
|
self.globals["urlencode"] = urlencode
|
||||||
self.globals["max"] = max
|
self.globals["max"] = max
|
||||||
self.globals["min"] = min
|
self.globals["min"] = min
|
||||||
|
self.tests["match"] = regex_match
|
||||||
|
self.tests["search"] = regex_search
|
||||||
|
|
||||||
if hass is None:
|
if hass is None:
|
||||||
return
|
return
|
||||||
|
@@ -1003,6 +1003,17 @@ def test_regex_match(hass):
|
|||||||
assert tpl.async_render() is True
|
assert tpl.async_render() is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_match_test(hass):
|
||||||
|
"""Test match test."""
|
||||||
|
tpl = template.Template(
|
||||||
|
r"""
|
||||||
|
{{ '123-456-7890' is match('(\\d{3})-(\\d{3})-(\\d{4})') }}
|
||||||
|
""",
|
||||||
|
hass,
|
||||||
|
)
|
||||||
|
assert tpl.async_render() is True
|
||||||
|
|
||||||
|
|
||||||
def test_regex_search(hass):
|
def test_regex_search(hass):
|
||||||
"""Test regex_search method."""
|
"""Test regex_search method."""
|
||||||
tpl = template.Template(
|
tpl = template.Template(
|
||||||
@@ -1038,6 +1049,17 @@ def test_regex_search(hass):
|
|||||||
assert tpl.async_render() is True
|
assert tpl.async_render() is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_search_test(hass):
|
||||||
|
"""Test search test."""
|
||||||
|
tpl = template.Template(
|
||||||
|
r"""
|
||||||
|
{{ '123-456-7890' is search('(\\d{3})-(\\d{3})-(\\d{4})') }}
|
||||||
|
""",
|
||||||
|
hass,
|
||||||
|
)
|
||||||
|
assert tpl.async_render() is True
|
||||||
|
|
||||||
|
|
||||||
def test_regex_replace(hass):
|
def test_regex_replace(hass):
|
||||||
"""Test regex_replace method."""
|
"""Test regex_replace method."""
|
||||||
tpl = template.Template(
|
tpl = template.Template(
|
||||||
|
Reference in New Issue
Block a user