diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/activity_spec.lua | 40 | ||||
-rw-r--r-- | spec/dates_spec.lua | 18 |
2 files changed, 50 insertions, 8 deletions
diff --git a/spec/activity_spec.lua b/spec/activity_spec.lua index 581b0ba..38338e8 100644 --- a/spec/activity_spec.lua +++ b/spec/activity_spec.lua @@ -43,21 +43,26 @@ Fri 0000000000000000000000000000000000000000000000000000_ ]] -describe("Generator", function() - describe("shall generate correct table for year", function() - local function lookup (year, day) return 0 end +local +function always_zero (...) + return 0 +end + +describe("Yearly chart generator", function() + describe("shall generate empty table for year", function() it("2024", function() - assert.are.equal(Y2024, activity.generate_table(2024, lookup, plain)) + assert.are.equal(Y2024, activity.generate_table(2024, always_zero, plain)) end) it("2023", function() - assert.are.equal(Y2023, activity.generate_table(2023, lookup, plain)) + assert.are.equal(Y2023, activity.generate_table(2023, always_zero, plain)) end) it("2020", function() - assert.are.equal(Y2020, activity.generate_table(2020, lookup, plain)) + assert.are.equal(Y2020, activity.generate_table(2020, always_zero, plain)) end) + end) describe("shall put activity into cells for", function() @@ -76,9 +81,28 @@ describe("Generator", function() assert.are.equal(Y2024:gsub("0", "1"), activity.generate_table(2024, lookup, plain)) end) end) +end) + + +describe("Rolling chart generator", function() + it("shall generate empty table", function() + local date = os.date("*t", os.time{year=2024, month=2, day=8}) + assert.are.equal(ROLL, activity.generate_table("rolling", always_zero, plain, date)) + end) - it("shall support generating rolling table", function() + it("shall put activity into cells", function() local date = os.date("*t", os.time{year=2024, month=2, day=8}) - assert.are.equal(ROLL, activity.generate_table("rolling", lookup, plain, date)) + + local function lookup (year, day) + if year == 2023 and day >= 36 then + return 1 + end + if year == 2024 and day <= 39 then + return 1 + end + return 0 + end + + assert.are.equal(ROLL:gsub("0", "1"), activity.generate_table("rolling", lookup, plain, date)) end) end) diff --git a/spec/dates_spec.lua b/spec/dates_spec.lua index a8b5a71..d820080 100644 --- a/spec/dates_spec.lua +++ b/spec/dates_spec.lua @@ -44,3 +44,21 @@ describe("First week day of", function() assert.are.equal(4, dates.first_week_day(2020)) end) end) + + +describe("Day 5 days before", function() + it("3 Mar 2023 is 26 Feb", function() + local date = {year=2023, month=3, day=3} + assert.are.same({year=2023, month=2, day=26}, dates.before(date, 5)) + end) + + it("3 Mar 2024 is 27 Feb", function() + local date = {year=2024, month=3, day=3} + assert.are.same({year=2024, month=2, day=27}, dates.before(date, 5)) + end) + + it("2 Jan 2024 is 28 Dec 2023", function() + local date = {year=2024, month=1, day=2} + assert.are.same({year=2023, month=12, day=28}, dates.before(date, 5)) + end) +end) |