| 1 |
""" |
| 2 |
List-valued configuration keys have an ad-hoc microsyntax. From `hg help config`: |
| 3 |
|
| 4 |
> List values are separated by whitespace or comma, except when values are |
| 5 |
> placed in double quotation marks: |
| 6 |
> |
| 7 |
> allow_read = "John Doe, PhD", brian, betty |
| 8 |
> |
| 9 |
> Quotation marks can be escaped by prefixing them with a backslash. Only |
| 10 |
> quotation marks at the beginning of a word is counted as a quotation |
| 11 |
> (e.g., ``foo"bar baz`` is the list of ``foo"bar`` and ``baz``). |
| 12 |
|
| 13 |
That help documentation is fairly light on details, the actual parser has many |
| 14 |
other edge cases. This test tries to cover them. |
| 15 |
""" |
| 16 |
|
| 17 |
from mercurial.utils import stringutil |
| 18 |
|
| 19 |
|
| 20 |
def assert_parselist(input, expected): |
| 21 |
result = stringutil.parselist(input) |
| 22 |
if result != expected: |
| 23 |
raise AssertionError( |
| 24 |
"parse_input(%r)\n got %r\nexpected %r" |
| 25 |
% (input, result, expected) |
| 26 |
) |
| 27 |
|
| 28 |
|
| 29 |
# Keep these Python tests in sync with the Rust ones in `rust/hg-core/src/config/values.rs` |
| 30 |
|
| 31 |
assert_parselist(b'', []) |
| 32 |
assert_parselist(b',', []) |
| 33 |
assert_parselist(b'A', [b'A']) |
| 34 |
assert_parselist(b'B,B', [b'B', b'B']) |
| 35 |
assert_parselist(b', C, ,C,', [b'C', b'C']) |
| 36 |
assert_parselist(b'"', [b'"']) |
| 37 |
assert_parselist(b'""', [b'', b'']) |
| 38 |
assert_parselist(b'D,"', [b'D', b'"']) |
| 39 |
assert_parselist(b'E,""', [b'E', b'', b'']) |
| 40 |
assert_parselist(b'"F,F"', [b'F,F']) |
| 41 |
assert_parselist(b'"G,G', [b'"G', b'G']) |
| 42 |
assert_parselist(b'"H \\",\\"H', [b'"H', b',', b'H']) |
| 43 |
assert_parselist(b'I,I"', [b'I', b'I"']) |
| 44 |
assert_parselist(b'J,"J', [b'J', b'"J']) |
| 45 |
assert_parselist(b'K K', [b'K', b'K']) |
| 46 |
assert_parselist(b'"K" K', [b'K', b'K']) |
| 47 |
assert_parselist(b'L\tL', [b'L', b'L']) |
| 48 |
assert_parselist(b'"L"\tL', [b'L', b'', b'L']) |
| 49 |
assert_parselist(b'M\x0bM', [b'M', b'M']) |
| 50 |
assert_parselist(b'"M"\x0bM', [b'M', b'', b'M']) |
| 51 |
assert_parselist(b'"N" , ,"', [b'N"']) |
| 52 |
assert_parselist(b'" ,O, ', [b'"', b'O']) |