SwVitaliy

Untitled

Aug 7th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function uTest() {
  2. 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]);
  3.           return function() { return fn.apply(ctx, args); } },
  4.     l = function () { console.log.apply(console, arguments); return undefined; },
  5.     w = function (testName, e) { l('w', arguments); l( testName + ' - ' + (e() ? 'OK' : 'ERROR') ); },
  6.     t = function(ns, q) { var i, j, setArgs, m, providerName;
  7.        for (i in q) { if (!q.hasOwnProperty(i)) continue; m = i.match(/^(.+)Test$/); if (!m || m.length < 2) continue;
  8.             providerName = m[1] + 'Provider'; if (typeof q[providerName] !== 'function') { w(m[1], p(ns, q[i])); } else {
  9.               setArgs = q[providerName].apply(q, []);for (j =0; j<setArgs.length; ++j) { w(m[1], p.apply(null, [ns, q[i]].concat(setArgs[j]))) } } } };
  10. if (arguments.length<2)
  11.   return { proxy:p, log:l, wrapper:w, testRun:t };
  12. else {
  13.   t(arguments[0], arguments[1]);
  14.   return undefined;
  15. }
  16. }
  17.  
  18. 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