Skip to content

Commit

Permalink
Merge pull request #47 from maltoe/issue-46-split-into-units-for-si-p…
Browse files Browse the repository at this point in the history
…refixes-only

split_into_units: Don't break for SI prefixes only
  • Loading branch information
kipcole9 authored Jul 30, 2024
2 parents f125acc + efd3edf commit ed7f7ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cldr/unit/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ defmodule Cldr.Unit.Parser do
end

for {prefix, _scale} <- Prefix.si_factors() do
def split_into_units(<<unquote(prefix), rest::binary>>) do
def split_into_units(<<unquote(prefix), rest::binary>>) when byte_size(rest) > 0 do
[head | rest] = split_into_units(rest)
[unquote(prefix) <> head | rest]
end
Expand Down
5 changes: 5 additions & 0 deletions test/cldr_units_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ defmodule Cldr.UnitsTest do
{Cldr.Unit.UnitNotTranslatableError, "The unit \"milliliter\" is not translatable"}}
end

test "validate unit does not break for SI prefixes only" do
assert Cldr.Unit.validate_unit("milli") ==
{:error, {Cldr.UnknownUnitError, "Unknown unit was detected at \"milli\""}}
end

test "Unit of 1 retrieves a default pattern is plural category pattern does not exist" do
unit = Cldr.Unit.new!(1, :pascal)
assert Cldr.Unit.to_string(unit, locale: "de", style: :short) == {:ok, "1 Pa"}
Expand Down

0 comments on commit ed7f7ac

Please sign in to comment.