Merge pull request #1683 from meh/fix-version

Fix handling pre/build data when minor/patch is missing in Mix.Version
This commit is contained in:
José Valim
2013-09-02 12:39:04 -07:00
2 changed files with 12 additions and 2 deletions
+5 -2
View File
@@ -277,14 +277,17 @@ defmodule Mix.Version do
end
end
defp nillify(""), do: nil
defp nillify(o), do: o
@spec parse_version(String.t) :: { :ok, Mix.Version.matchable } | { :error, :invalid_version }
def parse_version(string) when is_binary(string) do
if valid_version?(string) do
destructure [_, major, minor, patch, pre], Regex.run(@version_regex, string)
major = binary_to_integer(major)
minor = binary_to_integer(minor || "0")
patch = binary_to_integer(patch || "0")
minor = binary_to_integer(minor |> nillify || "0")
patch = binary_to_integer(patch |> nillify || "0")
pre = pre && parse_pre(pre) || []
{ :ok, { major, minor, patch, pre } }
+7
View File
@@ -23,6 +23,13 @@ defmodule Mix.VersionTest do
refute P.valid_requirement?(P.lexer("& 1.0.0", []))
end
test :parse do
assert V.Schema[major: 1, minor: 0, patch: 0] = V.parse("1")
assert V.Schema[major: 1, minor: 2, patch: 0] = V.parse("1.2")
assert V.Schema[major: 1, minor: 2, patch: 3] = V.parse("1.2.3")
assert V.Schema[major: 1, minor: 4, patch: 0, pre: "5-g3318bd5"] = V.parse("1.4-5-g3318bd5")
end
test :== do
assert V.match?("2.3", "2.3")
refute V.match?("2.4", "2.3")