Allow "no" to match "nb" in language util (#92862)

* Allow "no" to match "nb"

* Adjust comparison for speed
This commit is contained in:
Michael Hansen 2023-05-09 13:46:57 -05:00 committed by GitHub
parent 7d29d584fd
commit 5d6ccd6a32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 10 deletions

View file

@ -190,3 +190,39 @@ def test_sr_latn() -> None:
"sr-CS",
"sr-RS",
]
def test_no_nb_same() -> None:
"""Test that the no/nb are interchangeable."""
assert language.matches(
"no",
["en-US", "en-GB", "nb"],
) == ["nb"]
assert language.matches(
"nb",
["en-US", "en-GB", "no"],
) == ["no"]
def test_no_nb_prefer_exact() -> None:
"""Test that the exact language is preferred even if an interchangeable language is available."""
assert language.matches(
"no",
["en-US", "en-GB", "nb", "no"],
) == ["no", "nb"]
assert language.matches(
"no",
["en-US", "en-GB", "no", "nb"],
) == ["no", "nb"]
def test_no_nb_prefer_exact_regions() -> None:
"""Test that the exact language/region is preferred."""
assert language.matches(
"no-AA",
["en-US", "en-GB", "nb-AA", "no-AA"],
) == ["no-AA", "nb-AA"]
assert language.matches(
"no-AA",
["en-US", "en-GB", "no-AA", "nb-AA"],
) == ["no-AA", "nb-AA"]