@@ -615,6 +615,59 @@ def test_path_completion_user_path_expansion(cmd_app) -> None:
615615 assert completions_tilde_slash == completions_home
616616
617617
618+ @pytest .mark .parametrize ("prefix" , ["[ab]" , "[!ab]" ])
619+ def test_path_completion_literal_brackets_in_filename (cmd_app , tmp_path , monkeypatch , prefix ) -> None :
620+ for name in ("[ab].txt" , "[!ab].txt" , "a.txt" , "c.txt" ):
621+ (tmp_path / name ).touch ()
622+ monkeypatch .chdir (tmp_path )
623+ line = f"shell cat { prefix } "
624+
625+ completions = cmd_app .path_complete (prefix , line , len (line ) - len (prefix ), len (line ))
626+
627+ assert completions .to_strings () == (prefix + ".txt" ,)
628+
629+
630+ @pytest .mark .parametrize ("mode" , ["absolute" , "relative" , "empty_cwd" , "cwd_prefix" , "tilde" ])
631+ def test_path_completion_literal_brackets_in_directory (cmd_app , tmp_path , monkeypatch , mode ) -> None :
632+ directory = tmp_path / "project[2026]"
633+ directory .mkdir ()
634+ (directory / "target.txt" ).touch ()
635+ monkeypatch .chdir (tmp_path )
636+ if mode == "absolute" :
637+ text = str (directory / "tar" )
638+ expected = str (directory / "target.txt" )
639+ elif mode == "relative" :
640+ text = os .path .join (directory .name , "tar" )
641+ expected = os .path .join (directory .name , "target.txt" )
642+ elif mode == "tilde" :
643+ monkeypatch .setenv ("USERPROFILE" if sys .platform == "win32" else "HOME" , str (directory ))
644+ text = os .path .join ("~" , "tar" )
645+ expected = os .path .join ("~" , "target.txt" )
646+ else :
647+ monkeypatch .chdir (directory )
648+ text = "" if mode == "empty_cwd" else "tar"
649+ expected = "target.txt"
650+ line = f"shell cat { text } "
651+
652+ completions = cmd_app .path_complete (text , line , len (line ) - len (text ), len (line ))
653+
654+ assert completions .to_strings () == (expected ,)
655+
656+
657+ def test_path_completion_literal_brackets_directory_filter (cmd_app , tmp_path , monkeypatch ) -> None :
658+ (tmp_path / "[ab]-dir" ).mkdir ()
659+ (tmp_path / "a-dir" ).mkdir ()
660+ (tmp_path / "[ab]-file.txt" ).touch ()
661+ monkeypatch .chdir (tmp_path )
662+ text = "[ab]"
663+ line = f"shell cat { text } "
664+
665+ completions = cmd_app .path_complete (text , line , len (line ) - len (text ), len (line ), path_filter = os .path .isdir )
666+
667+ assert completions .to_strings () == ("[ab]-dir" + os .path .sep ,)
668+ assert not completions .allow_finalization
669+
670+
618671def test_basic_completion (cmd_app ) -> None :
619672 text = "P"
620673 line = f"list_food -f { text } "
0 commit comments