Debian Codegraph @

tests/test_parser.py

raw
1 import pytest
2
3 import click
4 from click.parser import _OptionParser
5 from click.shell_completion import split_arg_string
6
7
8 @pytest.mark.parametrize(
9 ("value", "expect"),
10 [
11 ("cli a b c", ["cli", "a", "b", "c"]),
12 ("cli 'my file", ["cli", "my file"]),
13 ("cli 'my file'", ["cli", "my file"]),
14 ("cli my\\", ["cli", "my"]),
15 ("cli my\\ file", ["cli", "my file"]),
16 ],
17 )
18 def test_split_arg_string(value, expect):
19 assert split_arg_string(value) == expect
20
21
22 def test_parser_default_prefixes():
23 parser = _OptionParser()
24 assert parser._opt_prefixes == {"-", "--"}
25
26
27 def test_parser_collects_prefixes():
28 ctx = click.Context(click.Command("test"))
29 parser = _OptionParser(ctx)
30 click.Option("+p", is_flag=True).add_to_parser(parser, ctx)
31 click.Option("!e", is_flag=True).add_to_parser(parser, ctx)
32 assert parser._opt_prefixes == {"-", "--", "+", "!"}