// Generated by CoffeeScript 1.6.3 (function() { var MAX_PARAM, MakeSync, RES_WITHOUT_EXTRA_FUNC, RES_WITH_EXTRA_FUNC, Sync, doneError, extraFunc, fiberError, makeTestFunc, should, _, _matchExclude, _ref, _ref1, __slice = [].slice; should = require('should'); _ref = require('../lib/make-sync'), Sync = _ref.Sync, MakeSync = _ref.MakeSync, _matchExclude = _ref._matchExclude; _ref1 = require('./helpers/function-gen'), makeTestFunc = _ref1.makeTestFunc, extraFunc = _ref1.extraFunc, MAX_PARAM = _ref1.MAX_PARAM, RES_WITHOUT_EXTRA_FUNC = _ref1.RES_WITHOUT_EXTRA_FUNC, RES_WITH_EXTRA_FUNC = _ref1.RES_WITH_EXTRA_FUNC; _ = require('lodash'); fiberError = /without a fiber/; doneError = /is not a function/; describe("object", function() { var buildAsyncFuncCall, buildObj, buildOptions, buildSyncFuncCall; buildObj = function() { var funcStart, i, obj, _fn, _i, _j, _len, _ref2; obj = { abc: 15 }; _ref2 = ['f', 'g', '_f']; for (_i = 0, _len = _ref2.length; _i < _len; _i++) { funcStart = _ref2[_i]; _fn = function() { var f; f = makeTestFunc(i, i % 2 === 0, i >= 2); return obj["" + funcStart + i] = function() { var args, b, res; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; b = this.abc.def; res = f.apply(null, args); return res; }; }; for (i = _j = 0; 0 <= MAX_PARAM ? _j <= MAX_PARAM : _j >= MAX_PARAM; i = 0 <= MAX_PARAM ? ++_j : --_j) { _fn(); } } return obj; }; buildAsyncFuncCall = function(funcName, i, obj) { return function() { var args, expected; args = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].slice(0, i); expected = RES_WITHOUT_EXTRA_FUNC[i]; if (i >= 2) { args.push(extraFunc); expected = RES_WITH_EXTRA_FUNC[i]; } if (i % 2 === 0) { return obj["" + funcName].apply(obj, __slice.call(args).concat([function(err, res) { return res.should.equal(expected); }])); } else { return obj["" + funcName].apply(obj, __slice.call(args).concat([function(res) { return res.should.equal(expected); }])); } }; }; buildSyncFuncCall = function(funcName, i, obj, addUndefined) { if (addUndefined == null) { addUndefined = false; } return function() { var args, expected; args = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].slice(0, i); expected = RES_WITHOUT_EXTRA_FUNC[i]; if (i >= 2) { args.push(extraFunc); expected = RES_WITH_EXTRA_FUNC[i]; } if (addUndefined) { args.push(void 0); } return Sync(function() { var res; res = obj["" + funcName].apply(obj, args); return res.should.equal(expected); }); }; }; buildOptions = function(mode) { var funcStart, i, options, _i, _j, _len, _ref2; options = { mode: mode, exclude: ['g0', 'g1', /^_/], 'sync-return': {} }; if (_.isEqual(mode, ['mixed', 'args'])) { options.num_of_args = { g2: 3, g3: 4, use: function(err, res) { if (res == null) { res = err; } return res; } }; } _ref2 = ['f', 'g', '_f']; for (_i = 0, _len = _ref2.length; _i < _len; _i++) { funcStart = _ref2[_i]; for (i = _j = 0; 0 <= MAX_PARAM ? _j <= MAX_PARAM : _j >= MAX_PARAM; i = 0 <= MAX_PARAM ? ++_j : --_j) { if (i % 2 === 1) { options['sync-return']["" + funcStart + i] = 'res'; } } } return options; }; describe("mode=sync", function() { var funcStart, i, obj, options, test, _i, _len, _ref2, _ref3, _results; _ref2 = [], options = _ref2[0], obj = _ref2[1]; before(function(done) { obj = buildObj(); options = buildOptions('sync'); MakeSync(obj, options); return done(); }); test = function(funcStart, i) { var funcName; funcName = "" + funcStart + i; it("" + funcName + " async call", function(done) { var funcCall; funcCall = buildAsyncFuncCall(funcName, i, obj); switch (funcStart) { case 'f': funcCall.should["throw"](fiberError); return done(); case 'g': if (i < 2) { funcCall.should.not["throw"](); } if (i >= 2) { funcCall.should["throw"](fiberError); } return done(); case '_f': funcCall.should.not["throw"](); return done(); } }); return it("" + funcName + " sync call", function(done) { var funcCall; funcCall = buildSyncFuncCall(funcName, i, obj); switch (funcStart) { case 'f': funcCall.should.not["throw"](); return done(); case 'g': if (i < 2) { funcCall.should["throw"](doneError); } if (i >= 2) { funcCall.should.not["throw"](); } return done(); case '_f': funcCall.should["throw"](doneError); return done(); } }); }; _ref3 = ['f', 'g', '_f']; _results = []; for (_i = 0, _len = _ref3.length; _i < _len; _i++) { funcStart = _ref3[_i]; _results.push((function() { var _j, _results1; _results1 = []; for (i = _j = 0; 0 <= MAX_PARAM ? _j <= MAX_PARAM : _j >= MAX_PARAM; i = 0 <= MAX_PARAM ? ++_j : --_j) { _results1.push(test(funcStart, i)); } return _results1; })()); } return _results; }); describe("mode=async", function() { var funcStart, i, obj, options, test, _i, _len, _ref2, _ref3, _results; _ref2 = [], options = _ref2[0], obj = _ref2[1]; before(function(done) { obj = buildObj(); options = buildOptions('async'); MakeSync(obj, options); return done(); }); test = function(funcStart, i) { var funcName; funcName = "" + funcStart + i; it("" + funcName + " async call", function(done) { var funcCall; funcCall = buildAsyncFuncCall(funcName, i, obj); switch (funcStart) { case 'f': funcCall.should.not["throw"](); return done(); case 'g': funcCall.should.not["throw"](); return done(); case '_f': funcCall.should.not["throw"](); return done(); } }); return it("" + funcName + " sync call", function(done) { var funcCall; funcCall = buildSyncFuncCall(funcName, i, obj); switch (funcStart) { case 'f': funcCall.should["throw"](doneError); return done(); case 'g': funcCall.should["throw"](doneError); return done(); case '_f': funcCall.should["throw"](doneError); return done(); } }); }; _ref3 = ['f', 'g', '_f']; _results = []; for (_i = 0, _len = _ref3.length; _i < _len; _i++) { funcStart = _ref3[_i]; _results.push((function() { var _j, _results1; _results1 = []; for (i = _j = 0; 0 <= MAX_PARAM ? _j <= MAX_PARAM : _j >= MAX_PARAM; i = 0 <= MAX_PARAM ? ++_j : --_j) { _results1.push(test(funcStart, i)); } return _results1; })()); } return _results; }); describe("mode=mixed-fibers", function() { var funcStart, i, obj, options, test, _i, _len, _ref2, _ref3, _results; _ref2 = [], options = _ref2[0], obj = _ref2[1]; before(function(done) { obj = buildObj(); options = buildOptions(['mixed', 'fibers']); MakeSync(obj, options); return done(); }); test = function(funcStart, i) { var funcName; funcName = "" + funcStart + i; it("" + funcName + " async call", function(done) { var funcCall; funcCall = buildAsyncFuncCall(funcName, i, obj); switch (funcStart) { case 'f': funcCall.should.not["throw"](); return done(); case 'g': funcCall.should.not["throw"](); return done(); case '_f': funcCall.should.not["throw"](); return done(); } }); return it("" + funcName + " sync call", function(done) { var funcCall; funcCall = buildSyncFuncCall(funcName, i, obj); switch (funcStart) { case 'f': funcCall.should.not["throw"](); return done(); case 'g': if (i < 2) { funcCall.should["throw"](doneError); } if (i >= 2) { funcCall.should.not["throw"](); } return done(); case '_f': funcCall.should["throw"](doneError); return done(); } }); }; _ref3 = ['f', 'g', '_f']; _results = []; for (_i = 0, _len = _ref3.length; _i < _len; _i++) { funcStart = _ref3[_i]; _results.push((function() { var _j, _results1; _results1 = []; for (i = _j = 0; 0 <= MAX_PARAM ? _j <= MAX_PARAM : _j >= MAX_PARAM; i = 0 <= MAX_PARAM ? ++_j : --_j) { _results1.push(test(funcStart, i)); } return _results1; })()); } return _results; }); return describe("mode=mixed-args", function() { var funcStart, i, obj, options, test, _i, _len, _ref2, _ref3, _results; _ref2 = [], options = _ref2[0], obj = _ref2[1]; before(function(done) { obj = buildObj(); options = buildOptions(['mixed', 'args']); MakeSync(obj, options); return done(); }); test = function(funcStart, i) { var funcName; funcName = "" + funcStart + i; it("" + funcName + " async call", function(done) { var funcCall; funcCall = buildAsyncFuncCall(funcName, i, obj); switch (funcStart) { case 'f': funcCall.should.not["throw"](); return done(); case 'g': funcCall.should.not["throw"](); return done(); case '_f': funcCall.should.not["throw"](); return done(); } }); return it("" + funcName + " sync call", function(done) { var funcCall, funcCallWithUndefined; funcCall = buildSyncFuncCall(funcName, i, obj); switch (funcStart) { case 'f': if (i < 2) { funcCall.should.not["throw"](); } if (i >= 2) { funcCall.should["throw"](doneError); funcCallWithUndefined = buildSyncFuncCall(funcName, i, obj, true); funcCallWithUndefined.should.not["throw"](); } return done(); case 'g': if (i < 2) { funcCall.should["throw"](doneError); } if (i >= 2) { funcCall.should.not["throw"](); } return done(); case '_f': funcCall.should["throw"](doneError); return done(); } }); }; _ref3 = ['f', 'g', '_f']; _results = []; for (_i = 0, _len = _ref3.length; _i < _len; _i++) { funcStart = _ref3[_i]; _results.push((function() { var _j, _results1; _results1 = []; for (i = _j = 0; 0 <= MAX_PARAM ? _j <= MAX_PARAM : _j >= MAX_PARAM; i = 0 <= MAX_PARAM ? ++_j : --_j) { _results1.push(test(funcStart, i)); } return _results1; })()); } return _results; }); }); }).call(this);