group('task', function()
  group('getStatus', function()
    test('is nil for a new coroutine', function()
      local task = coroutine.create(function() end)
      expect(lovr.task.getStatus(task)).to.be(nil)
    end)

    test('is nil for a finished coroutine that was never scheduled', function()
      local task = coroutine.create(function() end)
      coroutine.resume(task)
      expect(coroutine.status(task)).to.be('dead')
      expect(lovr.task.getStatus(task)).to.be(nil)
    end)

    test('is running for the current coroutine', function()
      expect(lovr.task.getStatus(coroutine.running())).to.be('running')
    end)

    test('is waiting for a task that is waiting for an async call', function()
      local task = lovr.task.start(function() lovr.timer.sleep(0) end)
      expect(lovr.task.getStatus(task)).to.be('waiting')
    end)

    test('is ready for a task that finished waiting for an async call', function()
      local task = lovr.task.start(function() lovr.timer.sleep(0) end)
      for task in lovr.task.poll() do end
      expect(lovr.task.getStatus(task)).to.be('ready')
    end)

    test('is failed for a task that errored', function()
      local task = coroutine.create(error)
      pcall(lovr.task.resume, task)
      expect(lovr.task.getStatus(task)).to.be('failed')
    end)

    test('is complete for a task that finished', function()
      local task = coroutine.create(function() end)
      pcall(lovr.task.resume, task)
      expect(lovr.task.getStatus(task)).to.be('complete')
    end)

    test('is nil for a task that yielded with coroutine.yield', function()
      local task = lovr.task.start(function() coroutine.yield() end)
      expect(lovr.task.getStatus(task)).to.be(nil)
    end)

    test('is failed for a task that errored after waiting', function()
      local task = lovr.task.start(function()
        lovr.timer.sleep(.01)
        error('opps')
      end)
      pcall(lovr.task.wait, task)
      expect(lovr.task.getStatus(task)).to.be('failed')
    end)
  end)
end)
