Skip to content

Instantly share code, notes, and snippets.

@acdimalev
Created June 26, 2019 04:34
Show Gist options
  • Save acdimalev/ffb7d6970605970a422c1ea981424b9e to your computer and use it in GitHub Desktop.
Save acdimalev/ffb7d6970605970a422c1ea981424b9e to your computer and use it in GitHub Desktop.
quoted = lambda s: '"' + str.replace(s, '"', '\\"') + '"'
unquoted = lambda s: str.replace(s[1:-1], '\\"', '"')
slash = lambda s: str.replace(s, '\\', '\\\\')
unslash = lambda s: str.replace(s, '\\\\', '\\')
shell_escape = lambda s: quoted(slash(s))
shell_unescape = lambda s: unslash(unquoted(s))
from env import *
from hypothesis import given
import hypothesis.strategies as st
@given(st.text())
def test_quoted_serialization(s):
assert s == unquoted(quoted(s))
@given(st.text())
def test_slash_serialization(s):
assert s == unslash(slash(s))
@given(st.text())
def test_shell_escape_serialization(s):
assert s == shell_unescape(shell_escape(s))
if __name__ == '__main__':
test_quoted_serialization()
test_slash_serialization()
test_shell_escape_serialization()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment