local util = require "pomo.util"

describe("util.format_time()", function()
  it("should format seconds", function()
    assert.equals("3s", util.format_time(3))
  end)
end)

describe("util.parse_time()", function()
  it("should default to seconds", function()
    assert.equals(3, util.parse_time "3")
  end)

  it("should parse seconds", function()
    assert.equals(3, util.parse_time "3s")
    assert.equals(3, util.parse_time "3 s")
    assert.equals(3, util.parse_time "3 sec")
    assert.equals(3, util.parse_time "3 seconds")
  end)

  it("should parse minutes", function()
    assert.equals(3 * 60, util.parse_time "3m")
    assert.equals(3 * 60, util.parse_time "3 m")
    assert.equals(3 * 60, util.parse_time "3 min")
    assert.equals(3 * 60, util.parse_time "3 minutes")
    assert.equals(90, util.parse_time "1.5 minutes")
  end)

  it("should parse hours", function()
    assert.equals(3 * 60 * 60, util.parse_time "3h")
    assert.equals(3 * 60 * 60, util.parse_time "3 h")
    assert.equals(3 * 60 * 60, util.parse_time "3 hour")
    assert.equals(3 * 60 * 60, util.parse_time "3 hours")
    assert.equals(1.5 * 60 * 60, util.parse_time "1.5 hours")
  end)

  it("should parse minutes and seconds", function()
    assert.equals(3 * 60 + 10, util.parse_time "3m 10s")
    assert.equals(3 * 60 + 10, util.parse_time "3m10s")
    assert.equals(3 * 60 + 10, util.parse_time "3min10s")
  end)
end)
