Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: qunit/tests/versionComparator.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Patch Set: Undo accidental whitespace change Created Jan. 16, 2017, 2:57 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 "use strict";
18 19
19 (function()
20 { 20 {
21 var compare = Services.vc.compare; 21 let compare = Services.vc.compare;
22 22
23 function allPairs(array) 23 function allPairs(array)
24 { 24 {
25 var pairs = []; 25 let pairs = [];
26 for (var i = 0; i < array.length - 1; i++) 26 for (let i = 0; i < array.length - 1; i++)
27 for (var j = i + 1; j < array.length; j++) 27 for (let j = i + 1; j < array.length; j++)
28 pairs.push([array[i], array[j]]); 28 pairs.push([array[i], array[j]]);
29 return pairs; 29 return pairs;
30 } 30 }
31 31
32 function versionsEqual(versions) 32 function versionsEqual(versions)
33 { 33 {
34 allPairs(versions).forEach(function(pair) 34 allPairs(versions).forEach(pair =>
35 { 35 {
36 var v1 = pair[0]; 36 let v1 = pair[0];
37 var v2 = pair[1]; 37 let v2 = pair[1];
38 equal(compare(v1, v2), 0, "'" + v1 + "' should be equal to '" + v2 + "'"); 38 equal(compare(v1, v2), 0, "'" + v1 + "' should be equal to '" + v2 + "'");
39 }); 39 });
40 } 40 }
41 41
42 function versionSmaller(v1, v2) 42 function versionSmaller(v1, v2)
43 { 43 {
44 equal(compare(v1, v2), -1, 44 equal(compare(v1, v2), -1,
45 "'" + v1 + "' should be smaller than '" + v2 + "'"); 45 "'" + v1 + "' should be smaller than '" + v2 + "'");
46 equal(compare(v2, v1), 1, 46 equal(compare(v2, v1), 1,
47 "'" + v2 + "' should be larger than '" + v1 + "'"); 47 "'" + v2 + "' should be larger than '" + v1 + "'");
48 } 48 }
49 49
50 module("Test utilities"); 50 module("Test utilities");
51 test("allPairs", 1, function() 51 test("allPairs", 1, () =>
52 { 52 {
53 deepEqual(allPairs([1, 2, 3]), [[1, 2], [1, 3], [2, 3]]); 53 deepEqual(allPairs([1, 2, 3]), [[1, 2], [1, 3], [2, 3]]);
54 }); 54 });
55 55
56 module("versionComparator"); 56 module("versionComparator");
57 57
58 test("Optional zero", 12, function() 58 test("Optional zero", 12, () =>
59 { 59 {
60 versionsEqual(["1", "1.0", "1.0.0", "1.0.0.0"]); 60 versionsEqual(["1", "1.0", "1.0.0", "1.0.0.0"]);
61 versionsEqual(["1.a", "1.0a", "1.a0", "1.0a0"]); 61 versionsEqual(["1.a", "1.0a", "1.a0", "1.0a0"]);
62 }); 62 });
63 63
64 test("+", 2, function() 64 test("+", 2, () =>
65 { 65 {
66 versionsEqual(["2pre", "1+"]); 66 versionsEqual(["2pre", "1+"]);
67 versionsEqual(["1.1pre", "1.0+"]); 67 versionsEqual(["1.1pre", "1.0+"]);
68 }); 68 });
69 69
70 test("*", 6, function() 70 test("*", 6, () =>
71 { 71 {
72 versionSmaller("1", "*"); 72 versionSmaller("1", "*");
73 versionSmaller("1.1", "1.*"); 73 versionSmaller("1.1", "1.*");
74 versionSmaller("1.*", "2"); 74 versionSmaller("1.*", "2");
75 }); 75 });
76 76
77 test("Examples", 296, function() 77 test("Examples", 296, () =>
78 { 78 {
79 var examples = [ 79 let examples = [
80 "1.0+a", 80 "1.0+a",
81 "1.0a", 81 "1.0a",
82 "1.0pre1", 82 "1.0pre1",
83 "1.0pre2", 83 "1.0pre2",
84 ["1.0", "1.0.0", "1.0.0.0"], 84 ["1.0", "1.0.0", "1.0.0.0"],
85 ["1.1pre", "1.1pre0", "1.0+"], 85 ["1.1pre", "1.1pre0", "1.0+"],
86 "1.1pre1a", 86 "1.1pre1a",
87 "1.1pre1", 87 "1.1pre1",
88 "1.1pre10a", 88 "1.1pre10a",
89 ["1.1pre10", "1.1pre010"], 89 ["1.1pre10", "1.1pre010"],
90 ["1.10", "1.010", "1.00010"], 90 ["1.10", "1.010", "1.00010"],
91 ]; 91 ];
92 92
93 examples.forEach(function(example) 93 examples.forEach(example =>
94 { 94 {
95 if (example instanceof Array) 95 if (example instanceof Array)
96 versionsEqual(example); 96 versionsEqual(example);
97 }); 97 });
98 98
99 allPairs(examples).forEach(function(pair) 99 allPairs(examples).forEach(pair =>
100 { 100 {
101 var v1 = [].concat(pair[0]); 101 let v1 = [].concat(pair[0]);
102 var v2 = [].concat(pair[1]); 102 let v2 = [].concat(pair[1]);
103 for (var i = 0; i < v1.length; i++) 103 for (let i = 0; i < v1.length; i++)
104 for (var j = 0; j < v2.length; j++) 104 for (let j = 0; j < v2.length; j++)
105 versionSmaller(v1[i], v2[j]); 105 versionSmaller(v1[i], v2[j]);
106 }); 106 });
107 }); 107 });
108 })(); 108 }
OLDNEW
« qunit/tests/url.js ('K') | « qunit/tests/url.js ('k') | stats.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld