tests/test-config-parselist.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Fri, 05 Apr 2024 11:33:47 +0200
changeset 51580 b70628a9aa7e
parent 47950 6961eca0b3ee
permissions -rw-r--r--
phases: use revision number in new_heads All graph operations will be done using revision numbers, so passing nodes only means they will eventually get converted to revision numbers internally. As part of an effort to align the code on using revision number we make the `phases.newheads` function operated on revision number, taking them as input and using them in returns, instead of the node-id it used to consume and produce. This is part of multiple changesets effort to translate more part of the logic, but is done step by step to facilitate the identification of issue that might arise in mercurial core and extensions. To make the change simpler to handle for third party extensions, we also rename the function, using a more modern form. This will help detecting the different between the node-id version and the rev-num version. I also take this as an opportunity to add some comment about possible performance improvement for the future. They don't matter too much now, but they are worse exploring in a while.

"""
List-valued configuration keys have an ad-hoc microsyntax. From `hg help config`:

> List values are separated by whitespace or comma, except when values are
> placed in double quotation marks:
>
>     allow_read = "John Doe, PhD", brian, betty
>
> Quotation marks can be escaped by prefixing them with a backslash. Only
> quotation marks at the beginning of a word is counted as a quotation
> (e.g., ``foo"bar baz`` is the list of ``foo"bar`` and ``baz``).

That help documentation is fairly light on details, the actual parser has many
other edge cases. This test tries to cover them.
"""

from mercurial.utils import stringutil


def assert_parselist(input, expected):
    result = stringutil.parselist(input)
    if result != expected:
        raise AssertionError(
            "parse_input(%r)\n     got %r\nexpected %r"
            % (input, result, expected)
        )


# Keep these Python tests in sync with the Rust ones in `rust/hg-core/src/config/values.rs`

assert_parselist(b'', [])
assert_parselist(b',', [])
assert_parselist(b'A', [b'A'])
assert_parselist(b'B,B', [b'B', b'B'])
assert_parselist(b', C, ,C,', [b'C', b'C'])
assert_parselist(b'"', [b'"'])
assert_parselist(b'""', [b'', b''])
assert_parselist(b'D,"', [b'D', b'"'])
assert_parselist(b'E,""', [b'E', b'', b''])
assert_parselist(b'"F,F"', [b'F,F'])
assert_parselist(b'"G,G', [b'"G', b'G'])
assert_parselist(b'"H \\",\\"H', [b'"H', b',', b'H'])
assert_parselist(b'I,I"', [b'I', b'I"'])
assert_parselist(b'J,"J', [b'J', b'"J'])
assert_parselist(b'K K', [b'K', b'K'])
assert_parselist(b'"K" K', [b'K', b'K'])
assert_parselist(b'L\tL', [b'L', b'L'])
assert_parselist(b'"L"\tL', [b'L', b'', b'L'])
assert_parselist(b'M\x0bM', [b'M', b'M'])
assert_parselist(b'"M"\x0bM', [b'M', b'', b'M'])
assert_parselist(b'"N"  , ,"', [b'N"'])
assert_parselist(b'" ,O,  ', [b'"', b'O'])