local F=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local K=require(F.Packages.Lyra.splitUtf8String)local d=require(F.DevPackages.JestGlobals)local J=d.describe local N=d.it local P=d.expect J("\115\112\108\105\116\085\116\102\056\083\116\114\105\110\103",function()N("\099\111\114\114\101\099\116\108\121 \115\112\108\105\116\115 \097 \110\111\110-\101\109\112\116\121 \115\116\114\105\110\103 \119\105\116\104\105\110 \116\104\101 \109\097\120\083\105\122\101\066\121\116\101\115 \108\105\109\105\116",function()local F=K("\072\101\108\108\111\044 \119\111\114\108\100\033",5);(P(F)).toEqual({"\072\101\108\108\111","\044 \119\111\114","\108\100\033"})end)N("\099\111\114\114\101\099\116\108\121 \104\097\110\100\108\101\115 \101\109\112\116\121 \115\116\114\105\110\103 \105\110\112\117\116",function()local F=K("",5);(P(F)).toEqual({})end)N("\116\104\114\111\119\115 \097\110 \101\114\114\111\114 \119\104\101\110 \109\097\120\083\105\122\101\066\121\116\101\115 \105\115 \108\101\115\115 \116\104\097\110 \111\114 \101\113\117\097\108 \116\111 \048",function()(P(function()K("\072\101\108\108\111\044 \119\111\114\108\100\033",0)end)).toThrow("\115\112\108\105\116\085\116\102\056\083\116\114\105\110\103\058 \101\120\112\101\099\116\101\100 \109\097\120\083\105\122\101\066\121\116\101\115 \116\111 \098\101 \103\114\101\097\116\101\114 \116\104\097\110 \048\044 \103\111\116 \048")end)N("\099\111\114\114\101\099\116\108\121 \115\112\108\105\116\115 \097 \115\116\114\105\110\103 \119\105\116\104 \109\117\108\116\105\098\121\116\101 \085\084\070-\056 \099\104\097\114\097\099\116\101\114\115",function()local F=K("\227\129\147\227\130\147\227\129\171\227\129\161\227\129\175\228\184\150\231\149\140",9);(P(F)).toEqual({"\227\129\147\227\130\147\227\129\171";"\227\129\161\227\129\175\228\184\150";"\231\149\140"})end)N("\099\111\114\114\101\099\116\108\121 \104\097\110\100\108\101\115 \115\116\114\105\110\103 \119\104\101\114\101 \097 \099\104\097\114\097\099\116\101\114\'\115 \098\121\116\101 \115\105\122\101 \101\120\099\101\101\100\115 \109\097\120\083\105\122\101\066\121\116\101\115",function()local F=K("\227\129\147\227\130\147\227\129\171\227\129\161\227\129\175\228\184\150\231\149\140",3);(P(F)).toEqual({"\227\129\147","\227\130\147";"\227\129\171","\227\129\161","\227\129\175","\228\184\150";"\231\149\140"})end)N("\099\111\114\114\101\099\116\108\121 \104\097\110\100\108\101\115 \101\100\103\101 \099\097\115\101\115 \119\104\101\114\101 \109\097\120\083\105\122\101\066\121\116\101\115 \105\115 \101\120\097\099\116\108\121 \116\104\101 \115\105\122\101 \111\102 \097 \099\104\097\114\097\099\116\101\114",function()local F=K("\072\101\108\108\111",1);(P(F)).toEqual({"\072";"\101";"\108","\108";"\111"})end)N("\101\110\115\117\114\101\115 \110\111 \108\111\115\115 \111\102 \100\097\116\097 \100\117\114\105\110\103 \115\112\108\105\116\116\105\110\103",function()local F=K("\072\101\108\108\111\044 \119\111\114\108\100\033",5);(P(table.concat(F))).toBe("\072\101\108\108\111\044 \119\111\114\108\100\033")end)N("\109\097\105\110\116\097\105\110\115 \099\111\114\114\101\099\116 \111\114\100\101\114 \111\102 \115\101\099\116\105\111\110\115",function()local F=K("\072\101\108\108\111\044 \119\111\114\108\100\033",5);(P(F)).toEqual({"\072\101\108\108\111";"\044 \119\111\114";"\108\100\033"})end)N("\099\111\114\114\101\099\116\108\121 \115\112\108\105\116\115 \118\101\114\121 \108\097\114\103\101 \115\116\114\105\110\103\115",function()local F=string.rep("\097",1000)local d=K(F,100);(P(#d)).toBe(10);(P(table.concat(d))).toBe(F)end)N("\104\097\110\100\108\101\115 \105\110\118\097\108\105\100 \085\084\070-\056 \115\116\114\105\110\103\115 \103\114\097\099\101\102\117\108\108\121",function()(P(function()K("\072\101\108\108\111\192\175\119\111\114\108\100",5)end)).toThrow("\115\112\108\105\116\085\116\102\056\083\116\114\105\110\103\058 \105\110\118\097\108\105\100 \085\084\070-\056 \115\101\113\117\101\110\099\101 \100\101\116\101\099\116\101\100 \097\116 \111\102\102\115\101\116 \049")end)N("\101\110\115\117\114\101\115 \116\104\097\116 \101\097\099\104 \115\101\099\116\105\111\110 \105\115 \097 \118\097\108\105\100 \085\084\070-\056 \115\116\114\105\110\103",function()local F=K("\227\129\147\227\130\147\227\129\171\227\129\161\227\129\175\228\184\150\231\149\140",9)for F,K in F do(P(utf8.len(K))).never.toBe(nil)end end)N("\098\111\117\110\100\097\114\121 \116\101\115\116 \102\111\114 \115\116\114\105\110\103\115 \119\105\116\104 \099\104\097\114\097\099\116\101\114\115 \097\116 \116\104\101 \109\097\120\083\105\122\101\066\121\116\101\115 \108\105\109\105\116",function()local F=K("\227\129\147\227\130\147\227\129\171\227\129\161\227\129\175",3);(P(F)).toEqual({"\227\129\147";"\227\130\147";"\227\129\171","\227\129\161";"\227\129\175"})end)N("\098\111\117\110\100\097\114\121 \116\101\115\116 \102\111\114 \115\105\110\103\108\101 \099\104\097\114\097\099\116\101\114 \115\116\114\105\110\103\115",function()local F=K("\097",1);(P(F)).toEqual({"\097"})end)N("\118\097\108\105\100\097\116\101\115 \116\121\112\101 \111\102 \114\101\116\117\114\110\101\100 \115\101\099\116\105\111\110\115",function()local F=K("\072\101\108\108\111\044 \119\111\114\108\100\033",5)for F,K in F do(P(typeof(K))).toBe("\115\116\114\105\110\103")end end)end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local splitUtf8String = require(ReplicatedStorage.Packages.Lyra.splitUtf8String)
local JestGlobals = require(ReplicatedStorage.DevPackages.JestGlobals)

local describe = JestGlobals.describe
local it = JestGlobals.it
local expect = JestGlobals.expect

describe("splitUtf8String", function()
	it("correctly splits a non-empty string within the maxSizeBytes limit", function()
		local result = splitUtf8String("Hello, world!", 5)
		expect(result).toEqual({ "Hello", ", wor", "ld!" })
	end)

	it("correctly handles empty string input", function()
		local result = splitUtf8String("", 5)
		expect(result).toEqual({})
	end)

	it("throws an error when maxSizeBytes is less than or equal to 0", function()
		expect(function()
			splitUtf8String("Hello, world!", 0)
		end).toThrow("splitUtf8String: expected maxSizeBytes to be greater than 0, got 0")
	end)

	it("correctly splits a string with multibyte UTF-8 characters", function()
		local result = splitUtf8String("こんにちは世界", 9)
		expect(result).toEqual({ "こんに", "ちは世", "界" })
	end)

	it("correctly handles string where a character's byte size exceeds maxSizeBytes", function()
		local result = splitUtf8String("こんにちは世界", 3)
		expect(result).toEqual({ "こ", "ん", "に", "ち", "は", "世", "界" })
	end)

	it("correctly handles edge cases where maxSizeBytes is exactly the size of a character", function()
		local result = splitUtf8String("Hello", 1)
		expect(result).toEqual({ "H", "e", "l", "l", "o" })
	end)

	it("ensures no loss of data during splitting", function()
		local result = splitUtf8String("Hello, world!", 5)
		expect(table.concat(result)).toBe("Hello, world!")
	end)

	it("maintains correct order of sections", function()
		local result = splitUtf8String("Hello, world!", 5)
		expect(result).toEqual({ "Hello", ", wor", "ld!" })
	end)

	it("correctly splits very large strings", function()
		local largeString = string.rep("a", 1000)
		local result = splitUtf8String(largeString, 100)
		expect(#result).toBe(10)
		expect(table.concat(result)).toBe(largeString)
	end)

	it("handles invalid UTF-8 strings gracefully", function()
		expect(function()
			splitUtf8String("Hello\xC0\xAFworld", 5)
		end).toThrow("splitUtf8String: invalid UTF-8 sequence detected at offset 1")
	end)

	it("ensures that each section is a valid UTF-8 string", function()
		local result = splitUtf8String("こんにちは世界", 9)
		for _, section in result do
			expect(utf8.len(section)).never.toBe(nil)
		end
	end)

	it("boundary test for strings with characters at the maxSizeBytes limit", function()
		local result = splitUtf8String("こんにちは", 3)
		expect(result).toEqual({ "こ", "ん", "に", "ち", "は" })
	end)

	it("boundary test for single character strings", function()
		local result = splitUtf8String("a", 1)
		expect(result).toEqual({ "a" })
	end)

	it("validates type of returned sections", function()
		local result = splitUtf8String("Hello, world!", 5)
		for _, section in result do
			expect(typeof(section)).toBe("string")
		end
	end)
end)
