Skip to content

Commit

Permalink
Fix spec for known_territory_subdivision (#39)
Browse files Browse the repository at this point in the history
`{:ok, nil}` is a valid response and not covered by the existing spec. Here I update the spec to account for this case.

There's an argument that maybe the library should return `{:ok, []}` when there are no known subdivisions for a valid territory. But as the `{:ok, nil}` was already the tested result I went with just updating the spec.
  • Loading branch information
richard-ash committed Mar 30, 2024
1 parent f226c37 commit 1d0fdb8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/cldr/backend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,15 @@ defmodule Cldr.Territory.Backend do
"gbcma", "gbcmd", "gbcmn", "gbcon", "gbcov", "gbcrf", "gbcry", "gbcwy",
"gbdal", "gbdby", "gbden", ...]}
=> #{inspect __MODULE__}.known_territory_subdivisions(:AI)
{:ok, nil}
iex> #{inspect __MODULE__}.known_territory_subdivisions(:ZZZ)
{:error, {Cldr.UnknownTerritoryError, "The territory :ZZZ is unknown"}}
"""
@doc since: "2.2.0"
@spec known_territory_subdivisions(atom() | String.t() | LanguageTag.t()) :: {:ok, String.t()} | {:error, {module(), String.t()}}
@spec known_territory_subdivisions(atom() | String.t() | LanguageTag.t()) :: {:ok, [String.t()] | nil} | {:error, {module(), String.t()}}
def known_territory_subdivisions(territory_code) do
case Cldr.validate_territory(territory_code) do
{:error, reason} -> {:error, reason}
Expand Down
2 changes: 1 addition & 1 deletion lib/cldr/territory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ defmodule Cldr.Territory do
"gbdal", "gbdby", "gbden", ...]}
"""
@doc since: "2.2.0"
@spec known_territory_subdivisions(atom() | String.t() | LanguageTag.t(), Cldr.backend()) :: {:ok, [String.t()]} | {:error, {module(), String.t()}}
@spec known_territory_subdivisions(atom() | String.t() | LanguageTag.t(), Cldr.backend()) :: {:ok, [String.t()] | nil} | {:error, {module(), String.t()}}
def known_territory_subdivisions(territory_code, backend), do: Module.concat(backend, Territory).known_territory_subdivisions(territory_code)

@doc """
Expand Down

0 comments on commit 1d0fdb8

Please sign in to comment.