|
12 | 12 | from click.core import Option |
13 | 13 | from click.shell_completion import add_completion_class |
14 | 14 | from click.shell_completion import CompletionItem |
| 15 | +from click.shell_completion import FishComplete |
15 | 16 | from click.shell_completion import shell_complete |
16 | 17 | from click.shell_completion import ShellComplete |
17 | 18 | from click.types import Choice |
@@ -359,9 +360,9 @@ def test_full_source(runner, shell): |
359 | 360 | ("bash", {"COMP_WORDS": "a b", "COMP_CWORD": "1"}, "plain,b\n"), |
360 | 361 | ("zsh", {"COMP_WORDS": "", "COMP_CWORD": "0"}, "plain\na\n_\nplain\nb\nbee\n"), |
361 | 362 | ("zsh", {"COMP_WORDS": "a b", "COMP_CWORD": "1"}, "plain\nb\nbee\n"), |
362 | | - ("fish", {"COMP_WORDS": "", "COMP_CWORD": ""}, "plain\na\n_\nplain\nb\nbee\n"), |
363 | | - ("fish", {"COMP_WORDS": "a b", "COMP_CWORD": "b"}, "plain\nb\nbee\n"), |
364 | | - ("fish", {"COMP_WORDS": 'a "b', "COMP_CWORD": '"b'}, "plain\nb\nbee\n"), |
| 363 | + ("fish", {"COMP_WORDS": "", "COMP_CWORD": ""}, "plain,a\nplain,b\tbee\n"), |
| 364 | + ("fish", {"COMP_WORDS": "a b", "COMP_CWORD": "b"}, "plain,b\tbee\n"), |
| 365 | + ("fish", {"COMP_WORDS": 'a "b', "COMP_CWORD": '"b'}, "plain,b\tbee\n"), |
365 | 366 | ], |
366 | 367 | ) |
367 | 368 | @pytest.mark.usefixtures("_patch_for_completion") |
@@ -578,48 +579,9 @@ def cli(ctx, config_file): |
578 | 579 | assert not current_warnings, "There should be no warnings after either" |
579 | 580 |
|
580 | 581 |
|
581 | | -@pytest.mark.usefixtures("_patch_for_completion") |
582 | | -def test_fish_multiline_help_complete(runner): |
583 | | - """Test Fish completion with multi-line help text doesn't cause errors.""" |
584 | | - cli = Command( |
585 | | - "cli", |
586 | | - params=[ |
587 | | - Option( |
588 | | - ["--at", "--attachment-type"], |
589 | | - type=(str, str), |
590 | | - multiple=True, |
591 | | - help=( |
592 | | - "\b\nAttachment with explicit mimetype,\n--at image.jpg image/jpeg" |
593 | | - ), |
594 | | - ), |
595 | | - Option(["--other"], help="Normal help"), |
596 | | - ], |
597 | | - ) |
598 | | - |
599 | | - result = runner.invoke( |
600 | | - cli, |
601 | | - env={ |
602 | | - "COMP_WORDS": "cli --", |
603 | | - "COMP_CWORD": "--", |
604 | | - "_CLI_COMPLETE": "fish_complete", |
605 | | - }, |
606 | | - ) |
607 | | - |
608 | | - # Should not fail |
609 | | - assert result.exit_code == 0 |
610 | | - |
611 | | - # Output should contain escaped newlines, not literal newlines |
612 | | - # Fish expects: plain\n--at\n{help_with_\\n} |
613 | | - lines = result.output.split("\n") |
614 | | - |
615 | | - # Find the --at completion block (3 lines: type, value, help) |
616 | | - for i in range(0, len(lines) - 2, 3): |
617 | | - if lines[i] == "plain" and lines[i + 1] in ("--at", "--attachment-type"): |
618 | | - help_line = lines[i + 2] |
619 | | - # Help should have escaped newlines (\\n), not actual newlines |
620 | | - assert "\\n" in help_line |
621 | | - # Should contain the example text |
622 | | - assert "image.jpg" in help_line.replace("\\n", " ") |
623 | | - break |
624 | | - else: |
625 | | - pytest.fail("--at completion not found in output") |
| 582 | +def test_fish_format_completion_escapes_help(): |
| 583 | + fc = FishComplete(Command("x"), {}, "x", "_X_COMPLETE") |
| 584 | + item = CompletionItem("--at", help="first\nsecond\tthird") |
| 585 | + # The newline is escaped to the literal characters backslash-n and the tab |
| 586 | + # becomes a space, so each completion stays on one line for fish. |
| 587 | + assert fc.format_completion(item) == "plain,--at\tfirst\\nsecond third" |
0 commit comments