← Lua Academy

Test-driven development · 42 / 69

Compare table contents

YOUR TASK

Make this happen

3 steps
  1. Tables have identity as well as contents. Test helpers use deep_eq to compare nested data. Repair the function so its nested result matches the expected structure.

  2. Read the cases in lesson.test.lua, then choose Check solution to see what needs to change.

  3. Update subject.lua until every test passes. Keep the supplied tests unchanged.

Read the starter and tests

subject.lua

exports.receipt = function()
  return { order = { total = 0 }, tags = { "paid" } }
end

lesson.test.lua

local t = require("test")
local subject = require("cococo.subject")
t.it("nested receipt", function()
  local s = subject.load()
  t.expect(s.receipt()):deep_eq({ order = { total = 24 }, tags = { "paid" } })
end)