var assert=require("assert"),Pend=require("./"),tests=[{name:"basic",fn:testBasic},{name:"max",fn:testWithMax},{name:"callback twice",fn:testCallbackTwice},{name:"calling wait twice",fn:testCallingWaitTwice},{name:"hold()",fn:testHoldFn}],testCount=tests.length;function doOneTest(){var t=tests.shift();t?(process.stdout.write(t.name+"..."),t.fn(function(){process.stdout.write("OK\n"),doOneTest()})):console.log(testCount+" tests passed.")}function testBasic(t){var e=new Pend,n=[];e.go(function(t){n.push(1),setTimeout(function(){n.push(3),t()},500)}),e.go(function(t){n.push(2),setTimeout(function(){n.push(4),t()},1e3)}),e.wait(function(e){assert.deepEqual(n,[1,2,3,4]),t()}),assert.deepEqual(n,[1,2])}function testWithMax(t){var e=new Pend,n=[];e.max=2,e.go(function(t){n.push("a"),setTimeout(function(){n.push(1),t()},500)}),e.go(function(t){n.push("b"),setTimeout(function(){n.push(1),t()},500)}),e.go(function(t){n.push("c"),setTimeout(function(){n.push(2),t()},100)}),e.wait(function(e){assert.deepEqual(n,["a","b",1,"c",1,2]),t()}),assert.deepEqual(n,["a","b"])}function testCallbackTwice(t){var e=new Pend;e.go(function(t){setTimeout(t,100)}),e.go(function(t){t(),assert.throws(t,/callback called twice/)}),e.wait(t)}function testCallingWaitTwice(t){var e=new Pend;e.go(function(t){setTimeout(t,100)}),e.wait(function(){e.go(function(t){setTimeout(t,50)}),e.go(function(t){setTimeout(t,10)}),e.go(function(t){setTimeout(t,20)}),e.wait(t)})}function testHoldFn(t){var e=new Pend;setTimeout(e.hold(),100),e.go(function(t){t()}),e.wait(t)}doOneTest();