示例工程 02-values-and-types

02-values-and-types/01-truthiness-table/_test.lua

lua · 0.6 KB

-- @runtimes lua54 luajit
local h = require("harness")
local m = require("main")
 
h.describe("真值表", function()
	h.it("0、空串、空表为真", function()
		local result = m.run(function() end)
		local by_label = {}
		for _, row in ipairs(result.rows) do
			by_label[row.label] = row.truthy
		end
		h.eq(by_label["0"], true)
		h.eq(by_label['""'], true)
		h.eq(by_label["{}"], true)
	end)
 
	h.it("nil 与 false 为假", function()
		local result = m.run(function() end)
		h.eq(result.rows[4].truthy, false)
		h.eq(result.rows[5].truthy, false)
	end)
end)
 
h.run()