Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

Add string.split implementation #190

Merged
merged 4 commits into from
Apr 16, 2019

Conversation

Validark
Copy link
Contributor

  • Adds string.split and tests. Modeled after the file which adds Roblox's math.clamp function.

@tiffany352
Copy link
Contributor

Here are our internal unit tests for this function, reformatted to the unit testing framework used here.

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("", ""))

@Validark
Copy link
Contributor Author

Thank you so much for providing this! I added it in. I think it is pretty funny you can use string.split to split up a family. Luckily, a call to table.concat should bring them back together.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 98.02% when pulling 3f7e35c on Validark:add-string.split into 6346da9 on LPGhatguy:master.

@LPGhatguy
Copy link
Owner

If it passes our internal tests, then it looks good to me!

@LPGhatguy LPGhatguy merged commit a69e245 into LPGhatguy:master Apr 16, 2019
@LPGhatguy LPGhatguy mentioned this pull request Apr 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants