local p=import("\046\047\115\116\114\105\110\103")describe("\108\105\098\115\046\115\116\114\105\110\103",function()describe("\115\112\108\105\116",function()it("\115\104\111\117\108\100 \098\101 \097 \102\117\110\099\116\105\111\110",function()assert.is_function(p.split)end)it("\115\104\111\117\108\100 \114\101\116\117\114\110 \097\110 \097\114\114\097\121 \111\102 \099\111\109\109\097 \115\101\112\097\114\097\116\101\100 \115\116\114\105\110\103\115 \105\102 \115\101\112 \105\115 \110\105\108",function()assert.are.same({"\072\101\108\108\111";"\119\111\114\108\100","\097\110\100";"\108\101\109\117\114"},p.split("\072\101\108\108\111\044\119\111\114\108\100\044\097\110\100\044\108\101\109\117\114"))end)it("\115\104\111\117\108\100 \114\101\116\117\114\110 \097\110 \097\114\114\097\121 \111\102 \097\108\108 \099\104\097\114\097\099\116\101\114\115 \105\110 \097 \115\116\114\105\110\103 \105\102 \115\101\112 \105\115 \116\104\101 \101\109\112\116\121 \115\116\114\105\110\103",function()assert.are.same({"\072";"\101","\108","\108","\111";"\044";"\119","\111";"\114";"\108";"\100";"\044","\097","\110";"\100","\044";"\108","\101";"\109";"\117";"\114"},p.split("\072\101\108\108\111\044\119\111\114\108\100\044\097\110\100\044\108\101\109\117\114",""))end)it("\115\104\111\117\108\100 \114\101\116\117\114\110 \097\110 \101\109\112\116\121 \116\097\098\108\101 \105\102 \116\104\101 \115\116\114\105\110\103 \097\110\100 \115\101\112 \105\115 \116\104\101 \101\109\112\116\121 \115\116\114\105\110\103",function()assert.are.same({},p.split("",""))end)it("\115\104\111\117\108\100 \114\101\116\117\114\110 \116\104\101 \111\114\105\103\105\110\097\108 \115\116\114\105\110\103 \105\110 \097 \116\097\098\108\101 \105\102 \110\111 \115\101\112 \105\115 \109\097\116\099\104\101\100",function()assert.are.same({"\072\101\108\108\111\044 \119\111\114\108\100"},p.split("\072\101\108\108\111\044 \119\111\114\108\100","\075"))assert.are.same({""},p.split(""," "))end)it("\115\104\111\117\108\100 \114\101\116\117\114\110 \101\109\112\116\121 \115\116\114\105\110\103\115 \097\116 \116\104\101 \102\114\111\110\116 \097\110\100 \098\097\099\107 \119\104\101\110 \115\101\112\115 \097\114\101 \112\114\101\115\101\110\116 \116\104\101\114\101",function()assert.are.same({"";"\086\097\108\105\100\097\114\107","\079\115\121\114\105\115";"\086\111\114\108\105\097\115",""},p.split("\047\086\097\108\105\100\097\114\107\047\079\115\121\114\105\115\047\086\111\114\108\105\097\115\047","\047"))assert.are.same({"";"\086\097\108\105\100\097\114\107";"\079\115\121\114\105\115","\086\111\114\108\105\097\115"},p.split("\047\086\097\108\105\100\097\114\107\047\079\115\121\114\105\115\047\086\111\114\108\105\097\115","\047"))assert.are.same({"\086\097\108\105\100\097\114\107";"\079\115\121\114\105\115";"\086\111\114\108\105\097\115";""},p.split("\086\097\108\105\100\097\114\107\047\079\115\121\114\105\115\047\086\111\114\108\105\097\115\047","\047"))assert.are.same({"\086\097\108\105\100\097\114\107","\079\115\121\114\105\115";"\086\111\114\108\105\097\115"},p.split("\086\097\108\105\100\097\114\107\047\079\115\121\114\105\115\047\086\111\114\108\105\097\115","\047"))end)it("\115\104\111\117\108\100 \097\108\108\111\119 \109\117\108\116\105-\099\104\097\114\097\099\116\101\114 \115\101\112\097\114\097\116\111\114\115",function()assert.are.same({"\072\101\108\108\111";"\119\111\114\108\100"},p.split("\072\101\108\108\111\044 \119\111\114\108\100","\044 "))end)it("\115\104\111\117\108\100 \108\105\116\101\114\097\108\108\121 \105\110\116\101\114\112\114\101\116 \076\117\097 \099\104\097\114\097\099\116\101\114 \099\108\097\115\115\101\115",function()assert.are.same({"\072\101\108\108\111\044 \119\111\114\108\100"},p.split("\072\101\108\108\111\044 \119\111\114\108\100","\037\108"))assert.are.same({"\072\101\108";"\111\044 \119\111\114\108\100"},p.split("\072\101\108\037\108\111\044 \119\111\114\108\100","\037\108"))end)it("\115\104\111\117\108\100 \109\097\116\099\104 \082\111\098\108\111\120\'\115 \105\110\116\101\114\110\097\108 \116\101\115\116\115",function()local C=p.char local H=C(226,128,141)assert.are.same({""},p.split("","\044"))assert.are.same({"\102\111\111";"","\098\097\114"},p.split("\102\111\111\044\044\098\097\114","\044"))assert.are.same({"";"\102\111\111"},p.split("\044\102\111\111","\044"))assert.are.same({"\102\111\111";""},p.split("\102\111\111\044","\044"))assert.are.same({"";""},p.split("\044","\044"))assert.are.same({"","";""},p.split("\044\044","\044"))assert.are.same({""},p.split("","~~~"))assert.are.same({"~~"},p.split("~~","~~~"))assert.are.same({"~~ ~~"},p.split("~~ ~~","~~~"))assert.are.same({"\102\111\111","\098\097\114"},p.split("\102\111\111~~~\098\097\114","~~~"))assert.are.same({"\102\111\111","";"\098\097\114"},p.split("\102\111\111~~~~~~\098\097\114","~~~"))assert.are.same({"";"\102\111\111"},p.split("~~~\102\111\111","~~~"))assert.are.same({"\102\111\111";""},p.split("\102\111\111~~~","~~~"))assert.are.same({"";""},p.split("~~~","~~~"))assert.are.same({"","";""},p.split("~~~~~~","~~~"))assert.are.same({"";"","\079"},p.split("\079\079\079\079\079","\079\079"))assert.are.same({"   \119\115   "},p.split("   \119\115   ","\044"))assert.are.same({"\102\111\111 "," \098\097\114"},p.split("\102\111\111 \044 \098\097\114","\044"))assert.are.same({"\230\136\145\229\190\136\233\171\152\229\133\180";"\228\189\160\229\145\162\239\188\159"},p.split("\230\136\145\229\190\136\233\171\152\229\133\180\239\188\140\228\189\160\229\145\162\239\188\159","\239\188\140"))assert.are.same({"\240\159\145\169","\240\159\145\169";"\240\159\145\167","\240\159\145\167"},p.split("\240\159\145\169\226\128\141\240\159\145\169\226\128\141\240\159\145\167\226\128\141\240\159\145\167",H))assert.are.same({"\102\111\111","\098\097\114"},p.split("\102\111\111\000\098\097\114","\000"))assert.are.same({"\102\111\111";"\098\097\114";""},p.split("\102\111\111\000\098\097\114\000","\000"))assert.are.same({"\102\111\111","\098\097\114"},p.split("\102\111\111\000\000\098\097\114","\000\000"))assert.are.same({"\102\111\111\000"},p.split("\102\111\111\000","\000\000"))assert.are.same({"\102\111\111";"\000"},p.split("\102\111\111\000\000\000","\000\000"))assert.are.same({},p.split("",""))assert.are.same({"\097","\098";"\099"},p.split("\097\098\099",""))assert.are.same({C(239);C(188),C(159)},p.split("\239\188\159",""))end)end)end)
local string = import("./string")

describe("libs.string", function()
	describe("split", function()
		it("should be a function", function()
			assert.is_function(string.split)
		end)

		it("should return an array of comma separated strings if sep is nil", function()
			assert.are.same({"Hello", "world", "and", "lemur"}, string.split("Hello,world,and,lemur"))
		end)

		it("should return an array of all characters in a string if sep is the empty string", function()
			assert.are.same({
				"H",
				"e",
				"l",
				"l",
				"o",
				",",
				"w",
				"o",
				"r",
				"l",
				"d",
				",",
				"a",
				"n",
				"d",
				",",
				"l",
				"e",
				"m",
				"u",
				"r",
			}, string.split("Hello,world,and,lemur", ""))
		end)

		it("should return an empty table if the string and sep is the empty string", function()
			assert.are.same({}, string.split("", ""))
		end)

		it("should return the original string in a table if no sep is matched", function()
			assert.are.same({"Hello, world"}, string.split("Hello, world", "K"))
			assert.are.same({""}, string.split("", " "))
		end)

		it("should return empty strings at the front and back when seps are present there", function()
			assert.are.same({"", "Validark", "Osyris", "Vorlias", ""}, string.split("/Validark/Osyris/Vorlias/", "/"))
			assert.are.same({"", "Validark", "Osyris", "Vorlias"}, string.split("/Validark/Osyris/Vorlias", "/"))
			assert.are.same({"Validark", "Osyris", "Vorlias", ""}, string.split("Validark/Osyris/Vorlias/", "/"))
			assert.are.same({"Validark", "Osyris", "Vorlias"}, string.split("Validark/Osyris/Vorlias", "/"))
		end)

		it("should allow multi-character separators", function()
			assert.are.same({"Hello", "world"}, string.split("Hello, world", ", "))
		end)

		it("should literally interpret Lua character classes", function()
			assert.are.same({"Hello, world"}, string.split("Hello, world", "%l"))
			assert.are.same({"Hel", "o, world"}, string.split("Hel%lo, world", "%l"))
		end)

		it("should match Roblox's internal tests", function()
			-- Provided by tiffany352 at https://github.com/LPGhatguy/lemur/pull/190
			local char = string.char
			local ZWJ = char(0xe2, 0x80, 0x8d)
			assert.are.same({ "" }, string.split("", ","))
			assert.are.same({ "foo", "", "bar" }, string.split("foo,,bar", ","))
			assert.are.same({ "", "foo" }, string.split(",foo", ","))
			assert.are.same({ "foo", "" }, string.split("foo,", ","))
			assert.are.same({ "", "" }, string.split(",", ","))
			assert.are.same({ "", "", "" }, string.split(",,", ","))
			assert.are.same({ "" }, string.split("", "~~~"))
			assert.are.same({ "~~" }, string.split("~~", "~~~"))
			assert.are.same({ "~~ ~~" }, string.split("~~ ~~", "~~~"))
			assert.are.same({ "foo", "bar" }, string.split("foo~~~bar", "~~~"))
			assert.are.same({ "foo", "", "bar" }, string.split("foo~~~~~~bar", "~~~"))
			assert.are.same({ "", "foo" }, string.split("~~~foo", "~~~"))
			assert.are.same({ "foo", "" }, string.split("foo~~~", "~~~"))
			assert.are.same({ "", "" }, string.split("~~~", "~~~"))
			assert.are.same({ "", "", "" }, string.split("~~~~~~", "~~~"))
			assert.are.same({ "", "", "O" }, string.split("OOOOO", "OO"))
			assert.are.same({ "   ws   " }, string.split("   ws   ", ","))
			assert.are.same({ "foo ", " bar" }, string.split("foo , bar", ","))
			assert.are.same({ "我很高兴", "你呢？" }, string.split("我很高兴，你呢？", "，"))
			assert.are.same({ "👩", "👩", "👧", "👧" }, string.split("👩‍👩‍👧‍👧", ZWJ))
			assert.are.same({ "foo", "bar" }, string.split("foo\0bar", "\0"))
			assert.are.same({ "foo", "bar", "" }, string.split("foo\0bar\0", "\0"))
			assert.are.same({ "foo", "bar" }, string.split("foo\0\0bar", "\0\0"))
			assert.are.same({ "foo\0" }, string.split("foo\0", "\0\0"))
			assert.are.same({ "foo", "\0" }, string.split("foo\0\0\0", "\0\0"))
			assert.are.same({ }, string.split("", ""))
			assert.are.same({ "a", "b", "c" }, string.split("abc", ""))
			assert.are.same({ char(0xef), char(0xbc), char(0x9f) }, string.split("？", ""))
		end)
	end)
end)
