Typed Lua · 29 / 69
Model a status
YOUR TASK
Make this happen
A literal union restricts a parameter to a small set of values. Use the declared states to decide whether an order may ship.
Read the cases in
lesson.test.lua, then choose Check solution to see what needs to change.Update
subject.luauntil every test passes. Keep the supplied tests unchanged.
Read the starter and tests
subject.lua
type Status = "paid" | "pending" | "cancelled" exports.canShip = function(status: Status): boolean return true end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.it("paid orders ship", function()
local s = subject.load()
t.expect(s.canShip("paid")):eq(true)
end)
t.it("pending orders wait", function()
local s = subject.load()
t.expect(s.canShip("pending")):eq(false)
end)
t.it("cancelled orders stay stopped", function()
local s = subject.load()
t.expect(s.canShip("cancelled")):eq(false)
end)