Show More
@@ -781,7 +781,7 b' def match_dict_keys(keys: List[Union[str, bytes, Tuple[Union[str, bytes]]]], pre' | |||||
781 | prefix_tuple = extra_prefix if extra_prefix else () |
|
781 | prefix_tuple = extra_prefix if extra_prefix else () | |
782 | Nprefix = len(prefix_tuple) |
|
782 | Nprefix = len(prefix_tuple) | |
783 | def filter_by_prefix_tuple(key): |
|
783 | def filter_by_prefix_tuple(key): | |
784 | if len(key) < Nprefix: |
|
784 | if len(key) <= Nprefix: | |
785 | return False |
|
785 | return False | |
786 | for k, pt in zip(key, prefix_tuple): |
|
786 | for k, pt in zip(key, prefix_tuple): | |
787 | if k != pt: |
|
787 | if k != pt: |
@@ -846,6 +846,35 b' class TestCompleter(unittest.TestCase):' | |||||
846 |
|
846 | |||
847 | match_dict_keys |
|
847 | match_dict_keys | |
848 |
|
848 | |||
|
849 | def test_match_dict_keys_tuple(self): | |||
|
850 | """ | |||
|
851 | Test that match_dict_keys called with extra prefix works on a couple of use case, | |||
|
852 | does return what expected, and does not crash. | |||
|
853 | """ | |||
|
854 | delims = " \t\n`!@#$^&*()=+[{]}\\|;:'\",<>?" | |||
|
855 | ||||
|
856 | keys = [("foo", "bar"), ("foo", "oof"), ("foo", b"bar"), ('other', 'test')] | |||
|
857 | ||||
|
858 | # Completion on first key == "foo" | |||
|
859 | assert match_dict_keys(keys, "'", delims=delims, extra_prefix=("foo",)) == ("'", 1, ["bar", "oof"]) | |||
|
860 | assert match_dict_keys(keys, "\"", delims=delims, extra_prefix=("foo",)) == ("\"", 1, ["bar", "oof"]) | |||
|
861 | assert match_dict_keys(keys, "'o", delims=delims, extra_prefix=("foo",)) == ("'", 1, ["oof"]) | |||
|
862 | assert match_dict_keys(keys, "\"o", delims=delims, extra_prefix=("foo",)) == ("\"", 1, ["oof"]) | |||
|
863 | assert match_dict_keys(keys, "b'", delims=delims, extra_prefix=("foo",)) == ("'", 2, ["bar"]) | |||
|
864 | assert match_dict_keys(keys, "b\"", delims=delims, extra_prefix=("foo",)) == ("\"", 2, ["bar"]) | |||
|
865 | assert match_dict_keys(keys, "b'b", delims=delims, extra_prefix=("foo",)) == ("'", 2, ["bar"]) | |||
|
866 | assert match_dict_keys(keys, "b\"b", delims=delims, extra_prefix=("foo",)) == ("\"", 2, ["bar"]) | |||
|
867 | ||||
|
868 | # No Completion | |||
|
869 | assert match_dict_keys(keys, "'", delims=delims, extra_prefix=("no_foo",)) == ("'", 1, []) | |||
|
870 | assert match_dict_keys(keys, "'", delims=delims, extra_prefix=("fo",)) == ("'", 1, []) | |||
|
871 | ||||
|
872 | keys = [('foo1', 'foo2', 'foo3', 'foo4'), ('foo1', 'foo2', 'bar', 'foo4')] | |||
|
873 | assert match_dict_keys(keys, "'foo", delims=delims, extra_prefix=('foo1',)) == ("'", 1, ["foo2", "foo2"]) | |||
|
874 | assert match_dict_keys(keys, "'foo", delims=delims, extra_prefix=('foo1', 'foo2')) == ("'", 1, ["foo3"]) | |||
|
875 | assert match_dict_keys(keys, "'foo", delims=delims, extra_prefix=('foo1', 'foo2', 'foo3')) == ("'", 1, ["foo4"]) | |||
|
876 | assert match_dict_keys(keys, "'foo", delims=delims, extra_prefix=('foo1', 'foo2', 'foo3', 'foo4')) == ("'", 1, []) | |||
|
877 | ||||
849 | def test_dict_key_completion_string(self): |
|
878 | def test_dict_key_completion_string(self): | |
850 | """Test dictionary key completion for string keys""" |
|
879 | """Test dictionary key completion for string keys""" | |
851 | ip = get_ipython() |
|
880 | ip = get_ipython() |
General Comments 0
You need to be logged in to leave comments.
Login now