Created
June 26, 2019 04:34
-
-
Save acdimalev/ffb7d6970605970a422c1ea981424b9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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