From 89b7fc43530535ea0fb2114e5fa0cf5660ca37a0 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 8 Feb 2024 01:48:43 +0100 Subject: Fixed last two weeks of each year not showing up --- spec/activity_spec.lua | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'spec/activity_spec.lua') diff --git a/spec/activity_spec.lua b/spec/activity_spec.lua index 634a228..197b57f 100644 --- a/spec/activity_spec.lua +++ b/spec/activity_spec.lua @@ -1,4 +1,5 @@ local activity = require "activity" +local dates = require "activity.dates" local plain = require "activity.formats.plain" local Y2024 = [[ @@ -34,16 +35,35 @@ Fri 0000000000000000000000000000000000000000000000000000_ describe("Generator", function() describe("shall generate correct table for year", function() + local function lookup (year, day) return 0 end + it("2024", function() - assert.are.equal(Y2024, activity.generate_table(2024, {}, plain)) + assert.are.equal(Y2024, activity.generate_table(2024, lookup, plain)) end) it("2023", function() - assert.are.equal(Y2023, activity.generate_table(2023, {}, plain)) + assert.are.equal(Y2023, activity.generate_table(2023, lookup, plain)) end) it("2020", function() - assert.are.equal(Y2020, activity.generate_table(2020, {}, plain)) + assert.are.equal(Y2020, activity.generate_table(2020, lookup, plain)) + end) + end) + + describe("shall put activity into cells for", function() + local function lookup (year, day) + if day < 1 or dates.days_in(year) < day then + return 0 + end + return 1 + end + + it("regular years", function() + assert.are.equal(Y2023:gsub("0", "1"), activity.generate_table(2023, lookup, plain)) + end) + + it("leap years", function() + assert.are.equal(Y2024:gsub("0", "1"), activity.generate_table(2024, lookup, plain)) end) end) end) -- cgit v1.1