@@ -72,7 +72,7 @@ impl fmt::Show for Identifier {
72
72
73
73
74
74
/// Represents a version number conforming to the semantic versioning scheme.
75
- #[ deriving( Clone , Eq ) ]
75
+ #[ deriving( Clone ) ]
76
76
pub struct Version {
77
77
/// The major version, to be incremented on incompatible changes.
78
78
major : uint ,
@@ -110,6 +110,19 @@ impl fmt::Show for Version {
110
110
}
111
111
}
112
112
113
+ impl cmp:: Eq for Version {
114
+ #[ inline]
115
+ fn eq ( & self , other : & Version ) -> bool {
116
+ // We should ignore build metadata here, otherwise versions v1 and v2
117
+ // can exist such that !(v1 < v2) && !(v1 > v2) && v1 != v2, which
118
+ // violate strict total ordering rules.
119
+ self . major == other. major &&
120
+ self . minor == other. minor &&
121
+ self . patch == other. patch &&
122
+ self . pre == other. pre
123
+ }
124
+ }
125
+
113
126
impl cmp:: Ord for Version {
114
127
#[ inline]
115
128
fn lt ( & self , other : & Version ) -> bool {
@@ -347,6 +360,7 @@ fn test_eq() {
347
360
assert_eq!(parse(" 1.2 . 3 -alpha1"), parse(" 1.2 . 3 -alpha1"));
348
361
assert_eq!(parse(" 1.2 . 3 +build. 42 "), parse(" 1.2 . 3 +build. 42 "));
349
362
assert_eq!(parse(" 1.2 . 3 -alpha1+42 "), parse(" 1.2 . 3 -alpha1+42 "));
363
+ assert_eq!(parse(" 1.2 . 3 +23 "), parse(" 1.2 . 3 +42 "));
350
364
}
351
365
352
366
#[test]
@@ -355,7 +369,6 @@ fn test_ne() {
355
369
assert!(parse(" 0.0 . 0 ") != parse(" 0.1 . 0 "));
356
370
assert!(parse(" 0.0 . 0 ") != parse(" 1.0 . 0 "));
357
371
assert!(parse(" 1.2 . 3 -alpha") != parse(" 1.2 . 3 -beta"));
358
- assert!(parse(" 1.2 . 3 +23 ") != parse(" 1.2 . 3 +42 "));
359
372
}
360
373
361
374
#[test]
@@ -376,11 +389,11 @@ fn test_to_str() {
376
389
377
390
#[test]
378
391
fn test_lt() {
379
- assert!(parse(" 0.0 . 0 ") < parse(" 1.2 . 3 -alpha2"));
380
- assert!(parse(" 1.0 . 0 ") < parse(" 1.2 . 3 -alpha2"));
381
- assert!(parse(" 1.2 . 0 ") < parse(" 1.2 . 3 -alpha2"));
382
- assert!(parse(" 1.2 . 3 -alpha1") < parse(" 1.2 . 3 "));
383
- assert!(parse(" 1.2 . 3 -alpha1") < parse(" 1.2 . 3 -alpha2"));
392
+ assert!(parse(" 0.0 . 0 ") < parse(" 1.2 . 3 -alpha2"));
393
+ assert!(parse(" 1.0 . 0 ") < parse(" 1.2 . 3 -alpha2"));
394
+ assert!(parse(" 1.2 . 0 ") < parse(" 1.2 . 3 -alpha2"));
395
+ assert!(parse(" 1.2 . 3 -alpha1") < parse(" 1.2 . 3 "));
396
+ assert!(parse(" 1.2 . 3 -alpha1") < parse(" 1.2 . 3 -alpha2"));
384
397
assert!(!(parse(" 1.2 . 3 -alpha2") < parse(" 1.2 . 3 -alpha2")));
385
398
assert!(!(parse(" 1.2 . 3 +23 ") < parse(" 1.2 . 3 +42 ")));
386
399
}
@@ -397,11 +410,11 @@ fn test_le() {
397
410
398
411
#[test]
399
412
fn test_gt() {
400
- assert!(parse(" 1.2 . 3 -alpha2") > parse(" 0.0 . 0 "));
401
- assert!(parse(" 1.2 . 3 -alpha2") > parse(" 1.0 . 0 "));
402
- assert!(parse(" 1.2 . 3 -alpha2") > parse(" 1.2 . 0 "));
403
- assert!(parse(" 1.2 . 3 -alpha2") > parse(" 1.2 . 3 -alpha1"));
404
- assert!(parse(" 1.2 . 3 ") > parse(" 1.2 . 3 -alpha2"));
413
+ assert!(parse(" 1.2 . 3 -alpha2") > parse(" 0.0 . 0 "));
414
+ assert!(parse(" 1.2 . 3 -alpha2") > parse(" 1.0 . 0 "));
415
+ assert!(parse(" 1.2 . 3 -alpha2") > parse(" 1.2 . 0 "));
416
+ assert!(parse(" 1.2 . 3 -alpha2") > parse(" 1.2 . 3 -alpha1"));
417
+ assert!(parse(" 1.2 . 3 ") > parse(" 1.2 . 3 -alpha2"));
405
418
assert!(!(parse(" 1.2 . 3 -alpha2") > parse(" 1.2 . 3 -alpha2")));
406
419
assert!(!(parse(" 1.2 . 3 +23 ") > parse(" 1.2 . 3 +42 ")));
407
420
}
@@ -418,7 +431,6 @@ fn test_ge() {
418
431
419
432
#[test]
420
433
fn test_spec_order() {
421
-
422
434
let vs = [" 1.0 . 0 -alpha",
423
435
" 1.0 . 0 -alpha. 1 ",
424
436
" 1.0 . 0 -alpha. beta",
0 commit comments