Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace all non-word characters with wordify #166

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions shtab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def complete2pattern(opt_complete, shell: str, choice_type2fn) -> str:


def wordify(string: str) -> str:
"""Replace non-word chars [-. :] with underscores [_]"""
return re.sub(r"[-.\s:]", "_", string)
"""Replace non-word chars [\\W] with underscores [_]"""
return re.sub("\\W", "_", string)


def get_public_subcommands(sub):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_shtab.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,25 @@ def test_subparser_colons(shell, caplog):
assert not caplog.record_tuples


@fix_shell
def test_subparser_slashes(shell, caplog):
parser = ArgumentParser(prog="test")
subparsers = parser.add_subparsers()
subparsers.add_parser("sub/cmd", help="help message")
with caplog.at_level(logging.INFO):
completion = shtab.complete(parser, shell=shell)
print(completion)

if shell == "bash":
shell = Bash(completion)
shell.compgen('-W "${_shtab_test_subparsers[*]}"', "s", "sub/cmd")
shell.compgen('-W "${_shtab_test_pos_0_choices[*]}"', "s", "sub/cmd")
shell.test('-z "${_shtab_test_COMPGEN-}"')
elif shell == "zsh":
assert "_shtab_test_sub/cmd" not in completion
assert "_shtab_test_sub_cmd" in completion


@fix_shell
def test_add_argument_to_optional(shell, caplog):
parser = ArgumentParser(prog="test")
Expand Down