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

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

Issue 29592604: Issue 5957 - Get the unit tests passing again (Closed)
Patch Set: lib/adblockplus.js isn't required for the tests anymore Created Oct. 30, 2017, 3:17 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
« no previous file with comments | « qunit/tests/url.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 /* globals Cu */
19
20 "use strict";
21
22 {
23 const {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
24 const {compare} = Services.vc;
25
26 function allPairs(array)
27 {
28 let pairs = [];
29 for (let i = 0; i < array.length - 1; i++)
30 {
31 for (let j = i + 1; j < array.length; j++)
32 pairs.push([array[i], array[j]]);
33 }
34 return pairs;
35 }
36
37 function versionsEqual(versions)
38 {
39 allPairs(versions).forEach(pair =>
40 {
41 let v1 = pair[0];
42 let v2 = pair[1];
43 equal(compare(v1, v2), 0, "'" + v1 + "' should be equal to '" + v2 + "'");
44 });
45 }
46
47 function versionSmaller(v1, v2)
48 {
49 equal(compare(v1, v2), -1,
50 "'" + v1 + "' should be smaller than '" + v2 + "'");
51 equal(compare(v2, v1), 1,
52 "'" + v2 + "' should be larger than '" + v1 + "'");
53 }
54
55 module("Test utilities");
56 test("allPairs", 1, () =>
57 {
58 deepEqual(allPairs([1, 2, 3]), [[1, 2], [1, 3], [2, 3]]);
59 });
60
61 module("versionComparator");
62
63 test("Optional zero", 12, () =>
64 {
65 versionsEqual(["1", "1.0", "1.0.0", "1.0.0.0"]);
66 versionsEqual(["1.a", "1.0a", "1.a0", "1.0a0"]);
67 });
68
69 test("+", 2, () =>
70 {
71 versionsEqual(["2pre", "1+"]);
72 versionsEqual(["1.1pre", "1.0+"]);
73 });
74
75 test("*", 6, () =>
76 {
77 versionSmaller("1", "*");
78 versionSmaller("1.1", "1.*");
79 versionSmaller("1.*", "2");
80 });
81
82 test("Examples", 296, () =>
83 {
84 let examples = [
85 "1.0+a",
86 "1.0a",
87 "1.0pre1",
88 "1.0pre2",
89 ["1.0", "1.0.0", "1.0.0.0"],
90 ["1.1pre", "1.1pre0", "1.0+"],
91 "1.1pre1a",
92 "1.1pre1",
93 "1.1pre10a",
94 ["1.1pre10", "1.1pre010"],
95 ["1.10", "1.010", "1.00010"]
96 ];
97
98 examples.forEach(example =>
99 {
100 if (example instanceof Array)
101 versionsEqual(example);
102 });
103
104 allPairs(examples).forEach(pair =>
105 {
106 let v1 = [].concat(pair[0]);
107 let v2 = [].concat(pair[1]);
108 for (let i = 0; i < v1.length; i++)
109 {
110 for (let j = 0; j < v2.length; j++)
111 versionSmaller(v1[i], v2[j]);
112 }
113 });
114 });
115 }
OLDNEW
« no previous file with comments | « qunit/tests/url.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld