Fix to_string for Version with numeric pre

Signed-off-by: Eric Meadows-Jönsson <eric.meadows.jonsson@gmail.com>
This commit is contained in:
Eric Meadows-Jönsson
2015-06-07 22:12:43 +02:00
parent f0ed2d48ce
commit c355ab6482
2 changed files with 13 additions and 1 deletions
+12 -1
View File
@@ -519,10 +519,21 @@ end
defimpl String.Chars, for: Version do
def to_string(version) do
pre = unless Enum.empty?(pre = version.pre), do: "-#{pre}"
pre = pre(version.pre)
build = if build = version.build, do: "+#{build}"
"#{version.major}.#{version.minor}.#{version.patch}#{pre}#{build}"
end
defp pre([]) do
""
end
defp pre(pre) do
Enum.map(["-"] ++ pre, fn
int when is_integer(int) -> Integer.to_string(int)
string when is_binary(string) -> string
end)
end
end
defimpl Inspect, for: Version do
+1
View File
@@ -72,6 +72,7 @@ defmodule VersionTest do
assert V.parse("1.0.0-dev") |> elem(1) |> to_string == "1.0.0-dev"
assert V.parse("1.0.0+lol") |> elem(1) |> to_string == "1.0.0+lol"
assert V.parse("1.0.0-dev+lol") |> elem(1) |> to_string == "1.0.0-dev+lol"
assert V.parse("1.0.0-0") |> elem(1) |> to_string == "1.0.0-0"
end
test "invalid match" do