summaryrefslogtreecommitdiff
path: root/lib/elixir/test/elixir/version_test.exs
diff options
context:
space:
mode:
authorEric Meadows-Jönsson <eric.meadows.jonsson@gmail.com>2014-02-01 18:05:49 +0100
committerEric Meadows-Jönsson <eric.meadows.jonsson@gmail.com>2014-02-02 20:28:46 +0100
commit6bc699672be2c339f444899a08f4169adec7023d (patch)
treea4b11de26c73f2fc195b478bdb1e0d715b0b2ae3 /lib/elixir/test/elixir/version_test.exs
parent61cac4eebcb8e1fe7561478e670c1df954d60a27 (diff)
downloadelixir-6bc699672be2c339f444899a08f4169adec7023d.tar.gz
Only allow semver versions in Version
Functions in Version that previously raised on invalid versions or requirements now returns an error tuple.
Diffstat (limited to 'lib/elixir/test/elixir/version_test.exs')
-rw-r--r--lib/elixir/test/elixir/version_test.exs224
1 files changed, 122 insertions, 102 deletions
diff --git a/lib/elixir/test/elixir/version_test.exs b/lib/elixir/test/elixir/version_test.exs
index f5f994908..90afeab18 100644
--- a/lib/elixir/test/elixir/version_test.exs
+++ b/lib/elixir/test/elixir/version_test.exs
@@ -6,46 +6,52 @@ defmodule VersionTest do
alias Version, as: V
test "compare" do
- assert :gt == V.compare("1.0.1", "1.0.0")
- assert :gt == V.compare("1.1.0", "1.0.1")
- assert :gt == V.compare("2.1.1", "1.2.2")
- assert :gt == V.compare("1.0.0", "1.0.0-dev")
- assert :gt == V.compare("1.2.3-dev", "0.1.2")
- assert :gt == V.compare("1.0.0-a.b", "1.0.0-a")
- assert :gt == V.compare("1.0.0-b", "1.0.0-a.b")
- assert :gt == V.compare("1.0.0-a", "1.0.0-0")
- assert :gt == V.compare("1.0.0-a.b", "1.0.0-a.a")
-
- assert :lt == V.compare("1.0.0", "1.0.1")
- assert :lt == V.compare("1.0.1", "1.1.0")
- assert :lt == V.compare("1.2.2", "2.1.1")
- assert :lt == V.compare("1.0.0-dev", "1.0.0")
- assert :lt == V.compare("0.1.2", "1.2.3-dev")
- assert :lt == V.compare("1.0.0-a", "1.0.0-a.b")
- assert :lt == V.compare("1.0.0-a.b", "1.0.0-b")
- assert :lt == V.compare("1.0.0-0", "1.0.0-a")
- assert :lt == V.compare("1.0.0-a.a", "1.0.0-a.b")
-
- assert :eq == V.compare("1.0.0", "1.0.0")
- assert :eq == V.compare("1.0.0-dev", "1.0.0-dev")
- assert :eq == V.compare("1.0.0-a", "1.0.0-a")
+ assert { :ok, :gt } == V.compare("1.0.1", "1.0.0")
+ assert { :ok, :gt } == V.compare("1.1.0", "1.0.1")
+ assert { :ok, :gt } == V.compare("2.1.1", "1.2.2")
+ assert { :ok, :gt } == V.compare("1.0.0", "1.0.0-dev")
+ assert { :ok, :gt } == V.compare("1.2.3-dev", "0.1.2")
+ assert { :ok, :gt } == V.compare("1.0.0-a.b", "1.0.0-a")
+ assert { :ok, :gt } == V.compare("1.0.0-b", "1.0.0-a.b")
+ assert { :ok, :gt } == V.compare("1.0.0-a", "1.0.0-0")
+ assert { :ok, :gt } == V.compare("1.0.0-a.b", "1.0.0-a.a")
+
+ assert { :ok, :lt } == V.compare("1.0.0", "1.0.1")
+ assert { :ok, :lt } == V.compare("1.0.1", "1.1.0")
+ assert { :ok, :lt } == V.compare("1.2.2", "2.1.1")
+ assert { :ok, :lt } == V.compare("1.0.0-dev", "1.0.0")
+ assert { :ok, :lt } == V.compare("0.1.2", "1.2.3-dev")
+ assert { :ok, :lt } == V.compare("1.0.0-a", "1.0.0-a.b")
+ assert { :ok, :lt } == V.compare("1.0.0-a.b", "1.0.0-b")
+ assert { :ok, :lt } == V.compare("1.0.0-0", "1.0.0-a")
+ assert { :ok, :lt } == V.compare("1.0.0-a.a", "1.0.0-a.b")
+
+ assert { :ok, :eq } == V.compare("1.0.0", "1.0.0")
+ assert { :ok, :eq } == V.compare("1.0.0-dev", "1.0.0-dev")
+ assert { :ok, :eq } == V.compare("1.0.0-a", "1.0.0-a")
+ end
+
+ test "invalid compare" do
+ assert { :error, _ } = V.compare("1.0", "1.0.0")
+ assert { :error, _ } = V.compare("1.0.0-dev", "1.0")
+ assert { :error, _ } = V.compare("foo", "1.0.0-a")
end
test "lexes specifications properly" do
assert P.lexer("== != > >= < <= ~>", []) == [:'==', :'!=', :'>', :'>=', :'<', :'<=', :'~>']
- assert P.lexer("2.3", []) == [:'==', "2.3"]
- assert P.lexer("!2.3", []) == [:'!=', "2.3"]
- assert P.lexer(">>=", []) == [:'>', :'>=']
- assert P.lexer(">2.4", []) == [:'>', "2.4"]
- assert P.lexer(" > 2.4", []) == [:'>', "2.4"]
+ assert P.lexer("2.3.0", []) == [:'==', "2.3.0"]
+ assert P.lexer("!2.3.0", []) == [:'!=', "2.3.0"]
+ assert P.lexer(">>=", []) == [:'>', :'>=']
+ assert P.lexer(">2.4.0", []) == [:'>', "2.4.0"]
+ assert P.lexer(" > 2.4.0", []) == [:'>', "2.4.0"]
end
test "valid requirement" do
- assert V.valid_requirement?("2.3")
- refute V.valid_requirement?("> >= 2.3")
- refute V.valid_requirement?("> 2.3 and")
- refute V.valid_requirement?("> 2.3 or and 4.3")
- assert V.valid_requirement?("> 2.4 and 4.5")
+ assert V.valid_requirement?("2.3.0")
+ refute V.valid_requirement?("> >= 2.3.0")
+ refute V.valid_requirement?("> 2.3.0 and")
+ refute V.valid_requirement?("> 2.3.0 or and 4.3.0")
+ assert V.valid_requirement?("> 2.4.0 and 4.5.0")
refute V.valid_requirement?("& 1.0.0")
end
@@ -60,114 +66,128 @@ defmodule VersionTest do
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")
+ assert { :ok, V.Schema[major: 1, minor: 2, patch: 3] } = V.parse("1.2.3")
+ assert { :ok, V.Schema[major: 1, minor: 4, patch: 5] } = V.parse("1.4.5+ignore")
+ assert { :ok, V.Schema[major: 1, minor: 4, patch: 5, pre: ["6-g3318bd5"]] } = V.parse("1.4.5-6-g3318bd5")
+ assert { :ok, V.Schema[major: 1, minor: 4, patch: 5, pre: [6, 7, "eight"]] } = V.parse("1.4.5-6.7.eight")
+ assert { :ok, V.Schema[major: 1, minor: 4, patch: 5, pre: ["6-g3318bd5"]] } = V.parse("1.4.5-6-g3318bd5+ignore")
+
+ assert { :error, :invalid_version } = V.parse("foobar")
+ assert { :error, :inexact_version } = V.parse("2.3")
+ assert { :error, :inexact_version } = V.parse("2")
+ assert { :error, :leading_zeros_in_prerelease } = V.parse("2.3.0-01")
end
- test "==" do
- assert V.match?("2.3", "2.3")
- refute V.match?("2.4", "2.3")
+ test "invalid match" do
+ assert { :error, :invalid_version } == V.match?("foo", "2.3.0")
+ assert { :error, :invalid_version } == V.match?("2.3.0", "foo")
+ assert { :error, :inexact_version } == V.match?("2.3.0", "2.3")
+ assert { :error, :inexact_version } == V.match?("2.3", "2.3.0")
+ end
- assert V.match?("2.3", "== 2.3")
- refute V.match?("2.4", "== 2.3")
+ test "==" do
+ assert { :ok, true } == V.match?("2.3.0", "2.3.0")
+ assert { :ok, false } == V.match?("2.4.0", "2.3.0")
- assert V.match?("1.0.0", "1.0.0")
- assert V.match?("1.0.0", "1.0")
+ assert { :ok, true } == V.match?("2.3.0", "== 2.3.0")
+ assert { :ok, false } == V.match?("2.4.0", "== 2.3.0")
- assert V.match?("1.2.3-alpha", "1.2.3-alpha")
+ assert { :ok, true } == V.match?("1.0.0", "1.0.0")
+ assert { :ok, true } == V.match?("1.0.0", "1.0.0")
- assert V.match?("iliketrains", "iliketrains")
- assert V.match?("1.2.3.4", "1.2.3.4")
+ assert { :ok, true } == V.match?("1.2.3-alpha", "1.2.3-alpha")
- assert V.match?("0.9.3", "== 0.9.3+dev")
+ assert { :ok, true } == V.match?("0.9.3", "== 0.9.3+dev")
end
test "!=" do
- assert V.match?("2.4", "!2.3")
- refute V.match?("2.3", "!2.3")
+ assert { :ok, true } == V.match?("2.4.0", "!2.3.0")
+ assert { :ok, false } == V.match?("2.3.0", "!2.3.0")
- assert V.match?("2.4", "!= 2.3")
- refute V.match?("2.3", "!= 2.3")
+ assert { :ok, true } == V.match?("2.4.0", "!= 2.3.0")
+ assert { :ok, false } == V.match?("2.3.0", "!= 2.3.0")
+
+ assert { :error, :inexact_version } == V.match?("2.3.0", "! 2.3")
+ assert { :error, :inexact_version } == V.match?("2.3.0", "!= 2.3")
end
test ">" do
- assert V.match?("2.4", "> 2.3")
- refute V.match?("2.2", "> 2.3")
- refute V.match?("2.3", "> 2.3")
-
- assert V.match?("1.2.3", "> 1.2.3-alpha")
- assert V.match?("1.2.3-alpha.1", "> 1.2.3-alpha")
- assert V.match?("1.2.3-alpha.beta.sigma", "> 1.2.3-alpha.beta")
- refute V.match?("1.2.3-alpha.10", "< 1.2.3-alpha.1")
- refute V.match?("0.10.2-dev", "> 0.10.2")
-
- refute V.match?("1.0.0-dev", "> 1.0.0")
- refute V.match?("0.1.2", "> 1.2.3-dev")
+ assert { :ok, true } == V.match?("2.4.0", "> 2.3.0")
+ assert { :ok, false } == V.match?("2.2.0", "> 2.3.0")
+ assert { :ok, false } == V.match?("2.3.0", "> 2.3.0")
+
+ assert { :ok, true } == V.match?("1.2.3", "> 1.2.3-alpha")
+ assert { :ok, true } == V.match?("1.2.3-alpha.1", "> 1.2.3-alpha")
+ assert { :ok, true } == V.match?("1.2.3-alpha.beta.sigma", "> 1.2.3-alpha.beta")
+ assert { :ok, false } == V.match?("1.2.3-alpha.10", "< 1.2.3-alpha.1")
+ assert { :ok, false } == V.match?("0.10.2-dev", "> 0.10.2")
end
test ">=" do
- assert V.match?("2.4", ">= 2.3")
- refute V.match?("2.2", ">= 2.3")
- assert V.match?("2.3", ">= 2.3")
+ assert { :ok, true } == V.match?("2.4.0", ">= 2.3.0")
+ assert { :ok, false } == V.match?("2.2.0", ">= 2.3.0")
+ assert { :ok, true } == V.match?("2.3.0", ">= 2.3.0")
- assert V.match?("2.0", ">= 1.0")
- assert V.match?("1.0.0", ">= 1.0")
+ assert { :ok, true } == V.match?("2.0.0", ">= 1.0.0")
+ assert { :ok, true } == V.match?("1.0.0", ">= 1.0.0")
end
test "<" do
- assert V.match?("2.2", "< 2.3")
- refute V.match?("2.4", "< 2.3")
- refute V.match?("2.3", "< 2.3")
+ assert { :ok, true } == V.match?("2.2.0", "< 2.3.0")
+ assert { :ok, false } == V.match?("2.4.0", "< 2.3.0")
+ assert { :ok, false } == V.match?("2.3.0", "< 2.3.0")
- assert V.match?("0.10.2-dev", "< 0.10.2")
+ assert { :ok, true } == V.match?("0.10.2-dev", "< 0.10.2")
- refute V.match?("1.0.0", "< 1.0.0-dev")
- refute V.match?("1.2.3-dev", "< 0.1.2")
+ assert { :ok, false } == V.match?("1.0.0", "< 1.0.0-dev")
+ assert { :ok, false } == V.match?("1.2.3-dev", "< 0.1.2")
end
test "<=" do
- assert V.match?("2.2", "<= 2.3")
- refute V.match?("2.4", "<= 2.3")
- assert V.match?("2.3", "<= 2.3")
+ assert { :ok, true } == V.match?("2.2.0", "<= 2.3.0")
+ assert { :ok, false } == V.match?("2.4.0", "<= 2.3.0")
+ assert { :ok, true } == V.match?("2.3.0", "<= 2.3.0")
end
test "~>" do
- assert V.match?("3.0", "~> 3.0")
- assert V.match?("3.2", "~> 3.0")
- refute V.match?("4.0", "~> 3.0")
- refute V.match?("4.4", "~> 3.0")
+ assert { :ok, true } == V.match?("3.0.0", "~> 3.0")
+ assert { :ok, true } == V.match?("3.2.0", "~> 3.0")
+ assert { :ok, false } == V.match?("4.0.0", "~> 3.0")
+ assert { :ok, false } == V.match?("4.4.0", "~> 3.0")
- assert V.match?("3.0.2", "~> 3.0.0")
- assert V.match?("3.0.0", "~> 3.0.0")
- refute V.match?("3.1", "~> 3.0.0")
- refute V.match?("3.4", "~> 3.0.0")
+ assert { :ok, true } == V.match?("3.0.2", "~> 3.0.0")
+ assert { :ok, true } == V.match?("3.0.0", "~> 3.0.0")
+ assert { :ok, false } == V.match?("3.1.0", "~> 3.0.0")
+ assert { :ok, false } == V.match?("3.4.0", "~> 3.0.0")
- assert V.match?("3.6", "~> 3.5")
- assert V.match?("3.5", "~> 3.5")
- refute V.match?("4.0", "~> 3.5")
- refute V.match?("5.0", "~> 3.5")
+ assert { :ok, true } == V.match?("3.6.0", "~> 3.5")
+ assert { :ok, true } == V.match?("3.5.0", "~> 3.5")
+ assert { :ok, false } == V.match?("4.0.0", "~> 3.5")
+ assert { :ok, false } == V.match?("5.0.0", "~> 3.5")
- assert V.match?("3.5.2", "~> 3.5.0")
- assert V.match?("3.5.4", "~> 3.5.0")
- refute V.match?("3.6", "~> 3.5.0")
- refute V.match?("3.6.3", "~> 3.5.0")
+ assert { :ok, true } == V.match?("3.5.2", "~> 3.5.0")
+ assert { :ok, true } == V.match?("3.5.4", "~> 3.5.0")
+ assert { :ok, false } == V.match?("3.6.0", "~> 3.5.0")
+ assert { :ok, false } == V.match?("3.6.3", "~> 3.5.0")
- assert V.match?("0.9.3", "~> 0.9.3-dev")
- refute V.match?("0.10.0", "~> 0.9.3-dev")
+ assert { :ok, true } == V.match?("0.9.3", "~> 0.9.3-dev")
+ assert { :ok, false } == V.match?("0.10.0", "~> 0.9.3-dev")
- refute V.match?("0.3.0-dev", "~> 0.2.0")
+ assert { :ok, false } == V.match?("0.3.0-dev", "~> 0.2.0")
+
+ assert { :error, :inexact_version } == V.match?("3.0.0", "~> 3")
end
test "and" do
- assert V.match?("0.9.3", "> 0.9 and < 0.10")
- refute V.match?("0.10.2", "> 0.9 and < 0.10")
+ assert { :ok, true } == V.match?("0.9.3", "> 0.9.0 and < 0.10.0")
+ assert { :ok, false } == V.match?("0.10.2", "> 0.9.0 and < 0.10.0")
end
test "or" do
- assert V.match?("0.9.1", "0.9.1 or 0.9.3 or 0.9.5")
- assert V.match?("0.9.3", "0.9.1 or 0.9.3 or 0.9.5")
- assert V.match?("0.9.5", "0.9.1 or 0.9.3 or 0.9.5")
+ assert { :ok, true } == V.match?("0.9.1", "0.9.1 or 0.9.3 or 0.9.5")
+ assert { :ok, true } == V.match?("0.9.3", "0.9.1 or 0.9.3 or 0.9.5")
+ assert { :ok, true } == V.match?("0.9.5", "0.9.1 or 0.9.3 or 0.9.5")
+
+ assert { :ok, false } == V.match?("0.9.6", "0.9.1 or 0.9.3 or 0.9.5")
end
end