Esempio n. 1
0
def test_recursive_wildcards():
    """Ensure unescaping of wildcards does not lead to them being matched later."""
    text = r"This has an escaped wildcard \%m"
    expected = "This has an escaped wildcard %m"
    intermediate = wildcards.expand(text, "%m", lambda: "anything")
    result = wildcards.expand(intermediate, "%", lambda: "anything")
    assert result == expected
Esempio n. 2
0
def test_expand_wildcard(wildcard, escaped, text):
    text = text.format(wildcard=rf"\{wildcard}" if escaped else wildcard)
    paths = "this", "is", "text"
    result = wildcards.expand(text, wildcard, lambda: paths)

    if escaped:
        expected = text.replace("\\", "")
    else:
        expected = text.replace(wildcard, " ".join(paths))

    assert result == expected
Esempio n. 3
0
def _run_single(text: str, mode: api.modes.Mode, count: str) -> None:
    """Run either external or internal command.

    Args:
        text: Complete text given to command line or keybinding.
        count: Count given if any.
        mode: Mode to run the command in.
    """
    if text.startswith("!"):
        external_runner.run(
            wildcards.expand(text.lstrip("!"), "~", os.path.expanduser, "~"))
    else:
        command(count + text, mode)
Esempio n. 4
0
def test_expand_with_backslash(wildcard, char):
    paths = (rf"\{char}", )
    expected = " ".join(shlex.quote(path) for path in paths)

    result = wildcards.expand(wildcard, wildcard, lambda: paths)
    assert result == expected