Dash encoding functions, tests and docs, refs #1439

This commit is contained in:
Simon Willison 2022-03-05 11:31:49 -08:00
commit d1cb73180b
3 changed files with 51 additions and 0 deletions

View file

@ -646,3 +646,19 @@ async def test_derive_named_parameters(sql, expected):
db = ds.get_database("_memory")
params = await utils.derive_named_parameters(db, sql)
assert params == expected
@pytest.mark.parametrize(
"original,expected",
(
("abc", "abc"),
("/foo/bar", "-/foo-/bar"),
("/-/bar", "-/---/bar"),
("-/db-/table---.csv-.csv", "---/db---/table-------.csv---.csv"),
),
)
def test_dash_encoding(original, expected):
actual = utils.dash_encode(original)
assert actual == expected
# And test round-trip
assert original == utils.dash_decode(actual)