示例工程 04-strings

04-strings/03-utf8-vs-bytes/_test.lua

lua · 0.4 KB

-- @runtimes lua54
local h = require("harness")
local m = require("main")
 
h.describe("UTF-8 与字节", function()
	h.it("中文 2 字 6 字节", function()
		local result = m.run(function() end)
		h.eq(result.bytes, 6)
		h.eq(result.chars, 2)
	end)
 
	h.it("非法序列返回 nil 与位置", function()
		local result = m.run(function() end)
		h.eq(result.bad_pos, 1)
	end)
end)
 
h.run()