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 +++++++++++++++++++++++--- spec/dates_spec.lua | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'spec') 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) diff --git a/spec/dates_spec.lua b/spec/dates_spec.lua index b1d3594..a8b5a71 100644 --- a/spec/dates_spec.lua +++ b/spec/dates_spec.lua @@ -40,7 +40,7 @@ describe("First week day of", function() assert.are.equal(7, dates.first_week_day(2022)) end) - it("2020 is Saturday", function() + it("2020 is Wednesday", function() assert.are.equal(4, dates.first_week_day(2020)) end) end) -- cgit v1.1