示例工程 06-control-flow-and-truthiness

06-control-flow-and-truthiness/02-table-driven-switch/_test.lua

lua · 0.4 KB

-- @runtimes lua54 luajit
local h = require("harness")
local m = require("main")
 
h.describe("表驱动分派", function()
	h.it("按名字选函数", function()
		local result = m.run(function() end)
		h.eq(result.add, 5)
		h.eq(result.mul, 6)
	end)
 
	h.it("未知操作返回 nil", function()
		local result = m.run(function() end)
		h.eq(result.unknown, true)
	end)
end)
 
h.run()