@@ -80,7 +80,7 @@ impl ToStr for Identifier {
80
80
81
81
82
82
/// Represents a version number conforming to the semantic versioning scheme.
83
- #[ deriving( Clone , Eq ) ]
83
+ #[ deriving( Clone ) ]
84
84
pub struct Version {
85
85
/// The major version, to be incremented on incompatible changes.
86
86
major : uint ,
@@ -125,6 +125,19 @@ impl ToStr for Version {
125
125
}
126
126
}
127
127
128
+ impl cmp:: Eq for Version {
129
+ #[ inline]
130
+ fn eq ( & self , other : & Version ) -> bool {
131
+ // We should ignore build metadata here, otherwise versions v1 and v2
132
+ // can exist such that !(v1 < v2) && !(v1 > v2) && v1 != v2, which
133
+ // violate strict total ordering rules.
134
+ self . major == other. major &&
135
+ self . minor == other. minor &&
136
+ self . patch == other. patch &&
137
+ self . pre == other. pre
138
+ }
139
+ }
140
+
128
141
impl cmp:: Ord for Version {
129
142
#[ inline]
130
143
fn lt ( & self , other : & Version ) -> bool {
@@ -362,6 +375,7 @@ fn test_eq() {
362
375
assert_eq!(parse(" 1.2 . 3 -alpha1"), parse(" 1.2 . 3 -alpha1"));
363
376
assert_eq!(parse(" 1.2 . 3 +build. 42 "), parse(" 1.2 . 3 +build. 42 "));
364
377
assert_eq!(parse(" 1.2 . 3 -alpha1+42 "), parse(" 1.2 . 3 -alpha1+42 "));
378
+ assert_eq!(parse(" 1.2 . 3 +23 "), parse(" 1.2 . 3 +42 "));
365
379
}
366
380
367
381
#[test]
@@ -370,7 +384,6 @@ fn test_ne() {
370
384
assert!(parse(" 0.0 . 0 ") != parse(" 0.1 . 0 "));
371
385
assert!(parse(" 0.0 . 0 ") != parse(" 1.0 . 0 "));
372
386
assert!(parse(" 1.2 . 3 -alpha") != parse(" 1.2 . 3 -beta"));
373
- assert!(parse(" 1.2 . 3 +23 ") != parse(" 1.2 . 3 +42 "));
374
387
}
375
388
376
389
#[test]
@@ -391,11 +404,11 @@ fn test_to_str() {
391
404
392
405
#[test]
393
406
fn test_lt() {
394
- assert!(parse(" 0.0 . 0 ") < parse(" 1.2 . 3 -alpha2"));
395
- assert!(parse(" 1.0 . 0 ") < parse(" 1.2 . 3 -alpha2"));
396
- assert!(parse(" 1.2 . 0 ") < parse(" 1.2 . 3 -alpha2"));
397
- assert!(parse(" 1.2 . 3 -alpha1") < parse(" 1.2 . 3 "));
398
- assert!(parse(" 1.2 . 3 -alpha1") < parse(" 1.2 . 3 -alpha2"));
407
+ assert!(parse(" 0.0 . 0 ") < parse(" 1.2 . 3 -alpha2"));
408
+ assert!(parse(" 1.0 . 0 ") < parse(" 1.2 . 3 -alpha2"));
409
+ assert!(parse(" 1.2 . 0 ") < parse(" 1.2 . 3 -alpha2"));
410
+ assert!(parse(" 1.2 . 3 -alpha1") < parse(" 1.2 . 3 "));
411
+ assert!(parse(" 1.2 . 3 -alpha1") < parse(" 1.2 . 3 -alpha2"));
399
412
assert!(!(parse(" 1.2 . 3 -alpha2") < parse(" 1.2 . 3 -alpha2")));
400
413
assert!(!(parse(" 1.2 . 3 +23 ") < parse(" 1.2 . 3 +42 ")));
401
414
}
@@ -412,11 +425,11 @@ fn test_le() {
412
425
413
426
#[test]
414
427
fn test_gt() {
415
- assert!(parse(" 1.2 . 3 -alpha2") > parse(" 0.0 . 0 "));
416
- assert!(parse(" 1.2 . 3 -alpha2") > parse(" 1.0 . 0 "));
417
- assert!(parse(" 1.2 . 3 -alpha2") > parse(" 1.2 . 0 "));
418
- assert!(parse(" 1.2 . 3 -alpha2") > parse(" 1.2 . 3 -alpha1"));
419
- assert!(parse(" 1.2 . 3 ") > parse(" 1.2 . 3 -alpha2"));
428
+ assert!(parse(" 1.2 . 3 -alpha2") > parse(" 0.0 . 0 "));
429
+ assert!(parse(" 1.2 . 3 -alpha2") > parse(" 1.0 . 0 "));
430
+ assert!(parse(" 1.2 . 3 -alpha2") > parse(" 1.2 . 0 "));
431
+ assert!(parse(" 1.2 . 3 -alpha2") > parse(" 1.2 . 3 -alpha1"));
432
+ assert!(parse(" 1.2 . 3 ") > parse(" 1.2 . 3 -alpha2"));
420
433
assert!(!(parse(" 1.2 . 3 -alpha2") > parse(" 1.2 . 3 -alpha2")));
421
434
assert!(!(parse(" 1.2 . 3 +23 ") > parse(" 1.2 . 3 +42 ")));
422
435
}
@@ -433,7 +446,6 @@ fn test_ge() {
433
446
434
447
#[test]
435
448
fn test_spec_order() {
436
-
437
449
let vs = [" 1.0 . 0 -alpha",
438
450
" 1.0 . 0 -alpha. 1 ",
439
451
" 1.0 . 0 -alpha. beta",
0 commit comments