Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion babel/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ def format_list(
style: Literal[
'standard',
'standard-short',
'standard-narrow',
'or',
'or-short',
'or-narrow',
'unit',
'unit-short',
'unit-narrow',
Expand All @@ -64,20 +66,24 @@ def format_list(
set forth in the CLDR root XML file, and raise a ValueError if no suitable replacement
can be found.

The following text is verbatim from the Unicode TR35-49 spec [1].
Styles follow the Unicode TR35-49 specification [1].

* standard:
A typical 'and' list for arbitrary placeholders.
eg. "January, February, and March"
* standard-short:
A short version of an 'and' list, suitable for use with short or abbreviated placeholder values.
eg. "Jan., Feb., and Mar."
* standard-narrow:
A particularly compact list of items joined with the standard style.
* or:
A typical 'or' list for arbitrary placeholders.
eg. "January, February, or March"
* or-short:
A short version of an 'or' list.
eg. "Jan., Feb., or Mar."
* or-narrow:
A particularly compact list of alternatives.
* unit:
A list suitable for wide units.
eg. "3 feet, 7 inches"
Expand Down
11 changes: 11 additions & 0 deletions tests/test_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ def test_format_list(list, locale, expected):
assert lists.format_list(list, locale=locale) == expected


@pytest.mark.parametrize(
('style', 'expected'),
[
('standard-narrow', 'apples, pears, plums'),
('or-narrow', 'apples, pears, or plums'),
],
)
def test_format_list_narrow_styles(style, expected):
assert lists.format_list(['apples', 'pears', 'plums'], style=style, locale='en') == expected


def test_format_list_error():
with pytest.raises(ValueError):
lists.format_list(['a', 'b', 'c'], style='orange', locale='en')
Expand Down