Skip to content

Commit a317584

Browse files
committed
auto merge of #7726 : omasanori/rust/semver-2.0.0, r=graydon
The Ord impl of Version refered to the algorithm in release candidate versions of semver. [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html) says, "Build metadata SHOULD be ignored when determining version precedence." 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. BTW, is `a || b || ... || x`-style code better or idiomatic in Rust than `if a { return true; } if b { return true; } ... if x { return true; } return false;`-style one?
2 parents 274e7a4 + 31d29d3 commit a317584

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/libextra/semver.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,7 @@ impl cmp::Ord for Version {
113113
(0, _) => false,
114114
(_, 0) => true,
115115
(_, _) => self.pre < other.pre
116-
})) ||
117-
118-
(self.major == other.major &&
119-
self.minor == other.minor &&
120-
self.patch == other.patch &&
121-
self.pre == other.pre &&
122-
self.build < other.build)
116+
}))
123117
}
124118

125119
#[inline]
@@ -324,6 +318,8 @@ fn test_parse() {
324318
fn test_eq() {
325319
assert_eq!(parse("1.2.3"), parse("1.2.3"));
326320
assert_eq!(parse("1.2.3-alpha1"), parse("1.2.3-alpha1"));
321+
assert_eq!(parse("1.2.3+build.42"), parse("1.2.3+build.42"));
322+
assert_eq!(parse("1.2.3-alpha1+42"), parse("1.2.3-alpha1+42"));
327323
}
328324
329325
#[test]
@@ -332,6 +328,7 @@ fn test_ne() {
332328
assert!(parse("0.0.0") != parse("0.1.0"));
333329
assert!(parse("0.0.0") != parse("1.0.0"));
334330
assert!(parse("1.2.3-alpha") != parse("1.2.3-beta"));
331+
assert!(parse("1.2.3+23") != parse("1.2.3+42"));
335332
}
336333
337334
#[test]
@@ -342,6 +339,7 @@ fn test_lt() {
342339
assert!(parse("1.2.3-alpha1") < parse("1.2.3"));
343340
assert!(parse("1.2.3-alpha1") < parse("1.2.3-alpha2"));
344341
assert!(!(parse("1.2.3-alpha2") < parse("1.2.3-alpha2")));
342+
assert!(!(parse("1.2.3+23") < parse("1.2.3+42")));
345343
}
346344
347345
#[test]
@@ -351,6 +349,7 @@ fn test_le() {
351349
assert!(parse("1.2.0") <= parse("1.2.3-alpha2"));
352350
assert!(parse("1.2.3-alpha1") <= parse("1.2.3-alpha2"));
353351
assert!(parse("1.2.3-alpha2") <= parse("1.2.3-alpha2"));
352+
assert!(parse("1.2.3+23") <= parse("1.2.3+42"));
354353
}
355354
356355
#[test]
@@ -361,6 +360,7 @@ fn test_gt() {
361360
assert!(parse("1.2.3-alpha2") > parse("1.2.3-alpha1"));
362361
assert!(parse("1.2.3") > parse("1.2.3-alpha2"));
363362
assert!(!(parse("1.2.3-alpha2") > parse("1.2.3-alpha2")));
363+
assert!(!(parse("1.2.3+23") > parse("1.2.3+42")));
364364
}
365365
366366
#[test]
@@ -370,22 +370,20 @@ fn test_ge() {
370370
assert!(parse("1.2.3-alpha2") >= parse("1.2.0"));
371371
assert!(parse("1.2.3-alpha2") >= parse("1.2.3-alpha1"));
372372
assert!(parse("1.2.3-alpha2") >= parse("1.2.3-alpha2"));
373+
assert!(parse("1.2.3+23") >= parse("1.2.3+42"));
373374
}
374375
375376
#[test]
376377
fn test_spec_order() {
377378
378379
let vs = ["1.0.0-alpha",
379380
"1.0.0-alpha.1",
381+
"1.0.0-alpha.beta",
382+
"1.0.0-beta",
380383
"1.0.0-beta.2",
381384
"1.0.0-beta.11",
382385
"1.0.0-rc.1",
383-
"1.0.0-rc.1+build.1",
384-
"1.0.0",
385-
"1.0.0+0.3.7",
386-
"1.3.7+build",
387-
"1.3.7+build.2.b8f12d7",
388-
"1.3.7+build.11.e0f985a"];
386+
"1.0.0"];
389387
let mut i = 1;
390388
while i < vs.len() {
391389
let a = parse(vs[i-1]).get();

0 commit comments

Comments
 (0)