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

Side by Side Diff: test/_test-utils.js

Issue 29548581: Issue 4128, 5138 - Add Parser and Serializer implemented in C++ Base URL: https://github.com/adblockplus/adblockpluscore.git
Patch Set: Created Sept. 18, 2017, 5:23 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
(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 "use strict";
19
20 /**
21 * Short from withNativeArgumentDeletion - wraps the function with the code
22 * deleting native arguments at nativeArgPosition position(s).
23 * Be careful, if an exception is thrown while construction of arguments, they
24 * are not deleted.
25 *
26 * @param {(number|number[])} nativeArgPosition
27 * @param {Function} fn - original function which should be wrapped
28 * @param {Object=} thisObj - 'this' Object to which apply the function fn.
29 * @return {Function} a new function object.
30 */
31 exports.withNAD = function(nativeArgPosition, fn, thisObj)
32 {
33 return function(...args)
34 {
35 try
36 {
37 fn.apply(thisObj ? thisObj : this, args);
38 }
39 finally
40 {
41 for (let i of Array.isArray(nativeArgPosition) ? nativeArgPosition : [nati veArgPosition])
42 if (args[i])
43 args[i].delete();
44 }
45 };
46 };
47
48 /**
49 * Compares only prototype properties of converted from C++ objects.
50 *
51 * @param {Object} test - test
52 * @param {Object} value - an inspecting object
53 * @param {Object} expected - an expected object
54 * @param {Object=} specialPropertyTesters - a dictionary with entries
55 * specifying a special testing function for properties which names are
56 * keys. The testing functions are corresponding values. If there is no
57 * such key in the dictionary then `test.equal` is used a the tester.
58 * @param {Object=} valuePrototype - for internal usage. The prototype of
59 * the inspecting object from its inheritance chain, whose own
60 * properties have been already tested at the previous step. The
61 * function calls recursively itself in order to compare properties
62 * defined in all base prototypes.
63 * If the value is undefined then the parameter value is used.
64 * @param {Object} expectedPrototype - for internal usage, see valuePrototype.
65 */
66 function testEqualObjProperties(test, value, expected, specialPropertyTesters,
67 valuePrototype, expectedPrototype)
68 {
69 valuePrototype = Object.getPrototypeOf(valuePrototype ? valuePrototype : value );
70 expectedPrototype = Object.getPrototypeOf(expectedPrototype ? expectedPrototyp e : expected);
71 test.ok(valuePrototype === expectedPrototype, "Wrong inheritance chains, they are likely different objects");
72 if (!valuePrototype)
73 return;
74 let propDescriptions = Object.getOwnPropertyDescriptors(expectedPrototype);
75 for (let propName in propDescriptions)
76 if ("get" in propDescriptions[propName])
77 ((specialPropertyTesters && propName in specialPropertyTesters) ?
78 specialPropertyTesters[propName] : test.equal)(value[propName], expected [propName], "Property: " + propName);
79 testEqualObjProperties(test, value, expected, specialPropertyTesters, valuePro totype, expectedPrototype);
80 }
81 exports.testEqualObjProperties = testEqualObjProperties;
OLDNEW

Powered by Google App Engine
This is Rietveld