From 9ba32f306a27abbf82b70dc48c1b973e37759034 Mon Sep 17 00:00:00 2001 From: OGINO Masanori Date: Thu, 11 Jul 2013 15:36:56 +0900 Subject: [PATCH 1/2] Update the ordering algorithm to semver 2.0.0. Note that Version's `le` is not "less than or equal to" now, since `lt` ignores build metadata. I think the new ordering algorithm satisfies strict weak ordering which C++ STL requires, instead of strict total ordering. --- src/libextra/semver.rs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/libextra/semver.rs b/src/libextra/semver.rs index 6c9453a5a3b..a5e99cc79bb 100644 --- a/src/libextra/semver.rs +++ b/src/libextra/semver.rs @@ -113,13 +113,7 @@ impl cmp::Ord for Version { (0, _) => false, (_, 0) => true, (_, _) => self.pre < other.pre - })) || - - (self.major == other.major && - self.minor == other.minor && - self.patch == other.patch && - self.pre == other.pre && - self.build < other.build) + })) } #[inline] @@ -377,15 +371,12 @@ fn test_spec_order() { let vs = ["1.0.0-alpha", "1.0.0-alpha.1", + "1.0.0-alpha.beta", + "1.0.0-beta", "1.0.0-beta.2", "1.0.0-beta.11", "1.0.0-rc.1", - "1.0.0-rc.1+build.1", - "1.0.0", - "1.0.0+0.3.7", - "1.3.7+build", - "1.3.7+build.2.b8f12d7", - "1.3.7+build.11.e0f985a"]; + "1.0.0"]; let mut i = 1; while i < vs.len() { let a = parse(vs[i-1]).get(); From 31d29d394f817580cacf0962bd8c2272c8b817db Mon Sep 17 00:00:00 2001 From: OGINO Masanori Date: Mon, 15 Jul 2013 21:07:26 +0900 Subject: [PATCH 2/2] Add more tests for build metadata. --- src/libextra/semver.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libextra/semver.rs b/src/libextra/semver.rs index a5e99cc79bb..dc016c8117b 100644 --- a/src/libextra/semver.rs +++ b/src/libextra/semver.rs @@ -318,6 +318,8 @@ fn test_parse() { fn test_eq() { assert_eq!(parse("1.2.3"), parse("1.2.3")); assert_eq!(parse("1.2.3-alpha1"), parse("1.2.3-alpha1")); + assert_eq!(parse("1.2.3+build.42"), parse("1.2.3+build.42")); + assert_eq!(parse("1.2.3-alpha1+42"), parse("1.2.3-alpha1+42")); } #[test] @@ -326,6 +328,7 @@ fn test_ne() { assert!(parse("0.0.0") != parse("0.1.0")); assert!(parse("0.0.0") != parse("1.0.0")); assert!(parse("1.2.3-alpha") != parse("1.2.3-beta")); + assert!(parse("1.2.3+23") != parse("1.2.3+42")); } #[test] @@ -336,6 +339,7 @@ fn test_lt() { assert!(parse("1.2.3-alpha1") < parse("1.2.3")); assert!(parse("1.2.3-alpha1") < parse("1.2.3-alpha2")); assert!(!(parse("1.2.3-alpha2") < parse("1.2.3-alpha2"))); + assert!(!(parse("1.2.3+23") < parse("1.2.3+42"))); } #[test] @@ -345,6 +349,7 @@ fn test_le() { assert!(parse("1.2.0") <= parse("1.2.3-alpha2")); assert!(parse("1.2.3-alpha1") <= parse("1.2.3-alpha2")); assert!(parse("1.2.3-alpha2") <= parse("1.2.3-alpha2")); + assert!(parse("1.2.3+23") <= parse("1.2.3+42")); } #[test] @@ -355,6 +360,7 @@ fn test_gt() { assert!(parse("1.2.3-alpha2") > parse("1.2.3-alpha1")); assert!(parse("1.2.3") > parse("1.2.3-alpha2")); assert!(!(parse("1.2.3-alpha2") > parse("1.2.3-alpha2"))); + assert!(!(parse("1.2.3+23") > parse("1.2.3+42"))); } #[test] @@ -364,6 +370,7 @@ fn test_ge() { assert!(parse("1.2.3-alpha2") >= parse("1.2.0")); assert!(parse("1.2.3-alpha2") >= parse("1.2.3-alpha1")); assert!(parse("1.2.3-alpha2") >= parse("1.2.3-alpha2")); + assert!(parse("1.2.3+23") >= parse("1.2.3+42")); } #[test]