local Y=import("\046\047\100\101\108\097\121")local J=import("\046\046\047\084\097\115\107\083\099\104\101\100\117\108\101\114")describe("\116\097\115\107\070\117\110\099\116\105\111\110\115\046\100\101\108\097\121",function()it("\115\104\111\117\108\100 \115\099\104\101\100\117\108\101 \097\102\116\101\114 \097 \115\109\097\108\108 \097\109\111\117\110\116 \111\102 \116\105\109\101",function()local K=J.new()local q=Y(K)local e=spy.new(function() end)q(0,function()e()end)K:step(.2);(assert.spy(e)).was_called()end)it("\115\104\111\117\108\100 \110\111\116 \099\097\108\108 \116\104\101 \102\117\110\099\116\105\111\110 \117\110\116\105\108 \097\102\116\101\114 \116\104\101 \100\101\108\097\121",function()local K=J.new()local q=Y(K)local e=spy.new(function() end)q(1,function()e()end)K:step(.2);(assert.spy(e)).was_not_called()end)it("\115\104\111\117\108\100 \101\114\114\111\114 \119\104\101\110 \103\105\118\101\110 \097 \110\111\110-\110\117\109\098\101\114 \100\101\108\097\121",function()local K=J.new()local q=Y(K)assert.has.errors(function()q("\097 \108\111\110\103 \116\105\109\101",function() end)end)end)end)
local createDelay = import("./delay")
local TaskScheduler = import("../TaskScheduler")

describe("taskFunctions.delay", function()
	it("should schedule after a small amount of time", function()
		local scheduler = TaskScheduler.new()
		local delay = createDelay(scheduler)

		local spy = spy.new(function() end)
		delay(0, function() spy() end)
		scheduler:step(0.2)
		assert.spy(spy).was_called()
	end)

	it("should not call the function until after the delay", function()
		local scheduler = TaskScheduler.new()
		local delay = createDelay(scheduler)

		local spy = spy.new(function() end)
		delay(1, function() spy() end)
		scheduler:step(0.2)
		assert.spy(spy).was_not_called()
	end)

	it("should error when given a non-number delay", function()
		local scheduler = TaskScheduler.new()
		local delay = createDelay(scheduler)
		assert.has.errors(function()
			delay("a long time", function() end)
		end)
	end)
end)