Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function uTest() {
- var p = function (ctx, fn) { var args,s = 2; if (typeof ctx === 'function') { fn = ctx; ctx = null; s = 1; } args = Array.prototype.slice.apply(arguments, [s]);
- return function() { return fn.apply(ctx, args); } },
- l = function () { console.log.apply(console, arguments); return undefined; },
- w = function (testName, e) { l('w', arguments); l( testName + ' - ' + (e() ? 'OK' : 'ERROR') ); },
- t = function(ns, q) { var i, j, setArgs, m, providerName;
- for (i in q) { if (!q.hasOwnProperty(i)) continue; m = i.match(/^(.+)Test$/); if (!m || m.length < 2) continue;
- providerName = m[1] + 'Provider'; if (typeof q[providerName] !== 'function') { w(m[1], p(ns, q[i])); } else {
- setArgs = q[providerName].apply(q, []);for (j =0; j<setArgs.length; ++j) { w(m[1], p.apply(null, [ns, q[i]].concat(setArgs[j]))) } } } };
- if (arguments.length<2)
- return { proxy:p, log:l, wrapper:w, testRun:t };
- else {
- t(arguments[0], arguments[1]);
- return undefined;
- }
- }
- uTest({ i:0, func: function(){ console.log("call func!"); return this.i++ & 1; } }, { funcTest: function(v) { return v === this.func(); }, funcProvider: function() { return [ [0], [1], [0] ] } })
Advertisement
Add Comment
Please, Sign In to add comment