| |
1 // Versions to test listed in ascending order, none can be equal |
| |
2 var comparisons = [ |
| |
3 "0.9", |
| |
4 "0.9.1", |
| |
5 "1.0pre1", |
| |
6 "1.0pre2", |
| |
7 "1.0", |
| |
8 "1.1pre", |
| |
9 "1.1pre1a", |
| |
10 "1.1pre1", |
| |
11 "1.1pre10a", |
| |
12 "1.1pre10", |
| |
13 "1.1", |
| |
14 "1.1.0.1", |
| |
15 "1.1.1", |
| |
16 "1.1.*", |
| |
17 "1.*", |
| |
18 "2.0", |
| |
19 "2.1", |
| |
20 "3.0.-1", |
| |
21 "3.0" |
| |
22 ]; |
| |
23 |
| |
24 // Every version in this list means the same version number |
| |
25 var equality = [ |
| |
26 "1.1pre", |
| |
27 "1.1pre0", |
| |
28 "1.0+" |
| |
29 ]; |
| |
30 |
| |
31 function run_test() |
| |
32 { |
| |
33 var vc = Components.classes["@mozilla.org/xpcom/version-comparator;1"] |
| |
34 .getService(Components.interfaces.nsIVersionComparator); |
| |
35 |
| |
36 for (var i = 0; i < comparisons.length; i++) { |
| |
37 for (var j = 0; j < comparisons.length; j++) { |
| |
38 var result = vc.compare(comparisons[i], comparisons[j]); |
| |
39 if (i == j) { |
| |
40 if (result != 0) |
| |
41 do_throw(comparisons[i] + " should be the same as itself"); |
| |
42 } |
| |
43 else if (i < j) { |
| |
44 if (!(result < 0)) |
| |
45 do_throw(comparisons[i] + " should be less than " + comparisons[j]); |
| |
46 } |
| |
47 else if (!(result > 0)) { |
| |
48 do_throw(comparisons[i] + " should be greater than " + comparisons[j]); |
| |
49 } |
| |
50 } |
| |
51 } |
| |
52 |
| |
53 for (i = 0; i < equality.length; i++) { |
| |
54 for (j = 0; j < equality.length; j++) { |
| |
55 if (vc.compare(equality[i], equality[j]) != 0) |
| |
56 do_throw(equality[i] + " should equal " + equality[j]); |
| |
57 } |
| |
58 } |
| |
59 } |