summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--activity/formats/plain.lua49
-rw-r--r--spec/activity_spec.lua49
-rw-r--r--spec/dates_spec.lua3
3 files changed, 101 insertions, 0 deletions
diff --git a/activity/formats/plain.lua b/activity/formats/plain.lua
new file mode 100644
index 0000000..9e12bb6
--- /dev/null
+++ b/activity/formats/plain.lua
@@ -0,0 +1,49 @@
+local plain = {}
+
+
+function plain.start_document (_)
+ return ""
+end
+
+
+function plain.end_document ()
+ return ""
+end
+
+
+function plain.start_table ()
+ return ""
+end
+
+
+function plain.end_table ()
+ return ""
+end
+
+
+function plain.start_row ()
+ return ""
+end
+
+
+function plain.end_row ()
+ return "\n"
+end
+
+
+function plain.label (name)
+ return ("%3s "):format(name)
+end
+
+
+function plain.spot ()
+ return "_"
+end
+
+
+function plain.cell (level)
+ return ("%1d"):format(level)
+end
+
+
+return plain
diff --git a/spec/activity_spec.lua b/spec/activity_spec.lua
new file mode 100644
index 0000000..634a228
--- /dev/null
+++ b/spec/activity_spec.lua
@@ -0,0 +1,49 @@
+local activity = require "activity"
+local plain = require "activity.formats.plain"
+
+local Y2024 = [[
+ _0000000000000000000000000000000000000000000000000000
+Mon 00000000000000000000000000000000000000000000000000000
+ 00000000000000000000000000000000000000000000000000000
+Wed 0000000000000000000000000000000000000000000000000000_
+ 0000000000000000000000000000000000000000000000000000_
+Fri 0000000000000000000000000000000000000000000000000000_
+ 0000000000000000000000000000000000000000000000000000_
+]]
+
+local Y2023 = [[
+ 00000000000000000000000000000000000000000000000000000
+Mon 0000000000000000000000000000000000000000000000000000_
+ 0000000000000000000000000000000000000000000000000000_
+Wed 0000000000000000000000000000000000000000000000000000_
+ 0000000000000000000000000000000000000000000000000000_
+Fri 0000000000000000000000000000000000000000000000000000_
+ 0000000000000000000000000000000000000000000000000000_
+]]
+
+local Y2020 = [[
+ _0000000000000000000000000000000000000000000000000000
+Mon _0000000000000000000000000000000000000000000000000000
+ _0000000000000000000000000000000000000000000000000000
+Wed 00000000000000000000000000000000000000000000000000000
+ 00000000000000000000000000000000000000000000000000000
+Fri 0000000000000000000000000000000000000000000000000000_
+ 0000000000000000000000000000000000000000000000000000_
+]]
+
+
+describe("Generator", function()
+ describe("shall generate correct table for year", function()
+ it("2024", function()
+ assert.are.equal(Y2024, activity.generate_table(2024, {}, plain))
+ end)
+
+ it("2023", function()
+ assert.are.equal(Y2023, activity.generate_table(2023, {}, plain))
+ end)
+
+ it("2020", function()
+ assert.are.equal(Y2020, activity.generate_table(2020, {}, plain))
+ end)
+ end)
+end)
diff --git a/spec/dates_spec.lua b/spec/dates_spec.lua
index 1c5382e..b1d3594 100644
--- a/spec/dates_spec.lua
+++ b/spec/dates_spec.lua
@@ -1,5 +1,6 @@
local dates = require "activity.dates"
+
describe("Days in a year", function()
it("should support regular years", function()
assert.are.equal(365, dates.days_in(1970))
@@ -20,6 +21,7 @@ describe("Days in a year", function()
end)
end)
+
describe("This year is", function()
local this_year = tonumber(os.date"%Y") -- Quite useless test
@@ -28,6 +30,7 @@ describe("This year is", function()
end)
end)
+
describe("First week day of", function()
it("2023 is Sunday", function()
assert.are.equal(1, dates.first_week_day(2023))