Skip to content

Commit

Permalink
SNOW-1011766: Fixed typo in escape_like_pattern, wrote unit tests for…
Browse files Browse the repository at this point in the history
… escape_like_pattern
  • Loading branch information
sfc-gh-davwang committed Feb 1, 2024
1 parent d5241ab commit cb39f19
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/snowflake/cli/api/project/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,5 @@ def validate_version(version: str):


def escape_like_pattern(pattern: str) -> str:
pattern = pattern.replace("%", r"\\}%").replace("_", r"\\_")
pattern = pattern.replace("%", r"\\%").replace("_", r"\\_")
return pattern
15 changes: 15 additions & 0 deletions tests/project/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
is_valid_unquoted_identifier,
to_identifier,
to_string_literal,
escape_like_pattern,
)

VALID_UNQUOTED_IDENTIFIERS = (
Expand Down Expand Up @@ -162,3 +163,17 @@ def test_is_valid_string_literal(literal, valid):
)
def test_to_string_literal(raw_string, literal):
assert to_string_literal(raw_string) == literal


@pytest.mark.parametrize(
"raw_string, escaped",
[
(r"underscore_table", r"underscore\\_table"),
(r"percent%%table", r"percent\\%\\%table"),
(r"__many__under__scores__", r"\\_\\_many\\_\\_under\\_\\_scores\\_\\_"),
(r"mixed_underscore%percent", r"mixed\\_underscore\\%percent"),
(r"regular$table", r"regular$table"),
],
)
def test_escape_like_pattern(raw_string, escaped):
assert escape_like_pattern(raw_string) == escaped

0 comments on commit cb39f19

Please sign in to comment.