OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 | 18 |
19 (function() | |
20 { | 19 { |
21 var compare = Services.vc.compare; | 20 let compare = Services.vc.compare; |
22 | 21 |
23 function allPairs(array) | 22 function allPairs(array) |
24 { | 23 { |
25 var pairs = []; | 24 let pairs = []; |
26 for (var i = 0; i < array.length - 1; i++) | 25 for (let i = 0; i < array.length - 1; i++) |
27 for (var j = i + 1; j < array.length; j++) | 26 for (let j = i + 1; j < array.length; j++) |
28 pairs.push([array[i], array[j]]); | 27 pairs.push([array[i], array[j]]); |
29 return pairs; | 28 return pairs; |
30 } | 29 } |
31 | 30 |
32 function versionsEqual(versions) | 31 function versionsEqual(versions) |
33 { | 32 { |
34 allPairs(versions).forEach(function(pair) | 33 allPairs(versions).forEach(pair => |
35 { | 34 { |
36 var v1 = pair[0]; | 35 let v1 = pair[0]; |
37 var v2 = pair[1]; | 36 let v2 = pair[1]; |
38 equal(compare(v1, v2), 0, "'" + v1 + "' should be equal to '" + v2 + "'"); | 37 equal(compare(v1, v2), 0, "'" + v1 + "' should be equal to '" + v2 + "'"); |
39 }); | 38 }); |
40 } | 39 } |
41 | 40 |
42 function versionSmaller(v1, v2) | 41 function versionSmaller(v1, v2) |
43 { | 42 { |
44 equal(compare(v1, v2), -1, | 43 equal(compare(v1, v2), -1, |
45 "'" + v1 + "' should be smaller than '" + v2 + "'"); | 44 "'" + v1 + "' should be smaller than '" + v2 + "'"); |
46 equal(compare(v2, v1), 1, | 45 equal(compare(v2, v1), 1, |
47 "'" + v2 + "' should be larger than '" + v1 + "'"); | 46 "'" + v2 + "' should be larger than '" + v1 + "'"); |
48 } | 47 } |
49 | 48 |
50 module("Test utilities"); | 49 module("Test utilities"); |
51 test("allPairs", 1, function() | 50 test("allPairs", 1, () => |
52 { | 51 { |
53 deepEqual(allPairs([1, 2, 3]), [[1, 2], [1, 3], [2, 3]]); | 52 deepEqual(allPairs([1, 2, 3]), [[1, 2], [1, 3], [2, 3]]); |
54 }); | 53 }); |
55 | 54 |
56 module("versionComparator"); | 55 module("versionComparator"); |
57 | 56 |
58 test("Optional zero", 12, function() | 57 test("Optional zero", 12, () => |
59 { | 58 { |
60 versionsEqual(["1", "1.0", "1.0.0", "1.0.0.0"]); | 59 versionsEqual(["1", "1.0", "1.0.0", "1.0.0.0"]); |
61 versionsEqual(["1.a", "1.0a", "1.a0", "1.0a0"]); | 60 versionsEqual(["1.a", "1.0a", "1.a0", "1.0a0"]); |
62 }); | 61 }); |
63 | 62 |
64 test("+", 2, function() | 63 test("+", 2, () => |
65 { | 64 { |
66 versionsEqual(["2pre", "1+"]); | 65 versionsEqual(["2pre", "1+"]); |
67 versionsEqual(["1.1pre", "1.0+"]); | 66 versionsEqual(["1.1pre", "1.0+"]); |
68 }); | 67 }); |
69 | 68 |
70 test("*", 6, function() | 69 test("*", 6, () => |
71 { | 70 { |
72 versionSmaller("1", "*"); | 71 versionSmaller("1", "*"); |
73 versionSmaller("1.1", "1.*"); | 72 versionSmaller("1.1", "1.*"); |
74 versionSmaller("1.*", "2"); | 73 versionSmaller("1.*", "2"); |
75 }); | 74 }); |
76 | 75 |
77 test("Examples", 296, function() | 76 test("Examples", 296, () => |
78 { | 77 { |
79 var examples = [ | 78 let examples = [ |
80 "1.0+a", | 79 "1.0+a", |
81 "1.0a", | 80 "1.0a", |
82 "1.0pre1", | 81 "1.0pre1", |
83 "1.0pre2", | 82 "1.0pre2", |
84 ["1.0", "1.0.0", "1.0.0.0"], | 83 ["1.0", "1.0.0", "1.0.0.0"], |
85 ["1.1pre", "1.1pre0", "1.0+"], | 84 ["1.1pre", "1.1pre0", "1.0+"], |
86 "1.1pre1a", | 85 "1.1pre1a", |
87 "1.1pre1", | 86 "1.1pre1", |
88 "1.1pre10a", | 87 "1.1pre10a", |
89 ["1.1pre10", "1.1pre010"], | 88 ["1.1pre10", "1.1pre010"], |
90 ["1.10", "1.010", "1.00010"], | 89 ["1.10", "1.010", "1.00010"], |
91 ]; | 90 ]; |
92 | 91 |
93 examples.forEach(function(example) | 92 examples.forEach(example => |
94 { | 93 { |
95 if (example instanceof Array) | 94 if (example instanceof Array) |
96 versionsEqual(example); | 95 versionsEqual(example); |
97 }); | 96 }); |
98 | 97 |
99 allPairs(examples).forEach(function(pair) | 98 allPairs(examples).forEach(pair => |
100 { | 99 { |
101 var v1 = [].concat(pair[0]); | 100 let v1 = [].concat(pair[0]); |
102 var v2 = [].concat(pair[1]); | 101 let v2 = [].concat(pair[1]); |
103 for (var i = 0; i < v1.length; i++) | 102 for (let i = 0; i < v1.length; i++) |
104 for (var j = 0; j < v2.length; j++) | 103 for (let j = 0; j < v2.length; j++) |
105 versionSmaller(v1[i], v2[j]); | 104 versionSmaller(v1[i], v2[j]); |
106 }); | 105 }); |
107 }); | 106 }); |
108 })(); | 107 } |
OLD | NEW |