Test the rest of the sring polyfills

This commit is contained in:
Starbeamrainbowlabs 2021-06-26 02:17:49 +01:00
parent 6a42aa6838
commit afce954306
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
5 changed files with 167 additions and 40 deletions

View File

@ -1,42 +1,40 @@
expose("", function()
local polyfill = require("worldeditadditions.utils.strings.polyfill")
local polyfill = require("worldeditadditions.utils.strings.polyfill")
describe("str_padend", function()
it("should pad a string", function()
assert.are.equal(
polyfill.str_padend("test", 5, " "),
"test "
)
end)
it("should pad a different string", function()
assert.are.equal(
polyfill.str_padend("yay", 4, " "),
"yay "
)
end)
it("should pad a string with multiple characters", function()
assert.are.equal(
polyfill.str_padend("test", 10, " "),
"test "
)
end)
it("should not pad a long string", function()
assert.are.equal(
polyfill.str_padend("testtest", 5, " "),
"testtest"
)
end)
it("should pad with other characters", function()
assert.are.equal(
polyfill.str_padend("1", 2, "0"),
"10"
)
end)
it("should pad with multiple other characters", function()
assert.are.equal(
polyfill.str_padend("1", 5, "0"),
"10000"
)
end)
describe("str_padend", function()
it("should pad a string", function()
assert.are.equal(
polyfill.str_padend("test", 5, " "),
"test "
)
end)
it("should pad a different string", function()
assert.are.equal(
polyfill.str_padend("yay", 4, " "),
"yay "
)
end)
it("should pad a string with multiple characters", function()
assert.are.equal(
polyfill.str_padend("test", 10, " "),
"test "
)
end)
it("should not pad a long string", function()
assert.are.equal(
polyfill.str_padend("testtest", 5, " "),
"testtest"
)
end)
it("should pad with other characters", function()
assert.are.equal(
polyfill.str_padend("1", 2, "0"),
"10"
)
end)
it("should pad with multiple other characters", function()
assert.are.equal(
polyfill.str_padend("1", 5, "0"),
"10000"
)
end)
end)

View File

@ -0,0 +1,40 @@
local polyfill = require("worldeditadditions.utils.strings.polyfill")
describe("str_padstart", function()
it("should pad a string", function()
assert.are.equal(
polyfill.str_padstart("test", 5, " "),
" test"
)
end)
it("should pad a different string", function()
assert.are.equal(
polyfill.str_padstart("yay", 4, " "),
" yay"
)
end)
it("should pad a string with multiple characters", function()
assert.are.equal(
polyfill.str_padstart("test", 10, " "),
" test"
)
end)
it("should not pad a long string", function()
assert.are.equal(
polyfill.str_padstart("testtest", 5, " "),
"testtest"
)
end)
it("should pad with other characters", function()
assert.are.equal(
polyfill.str_padstart("1", 2, "0"),
"01"
)
end)
it("should pad with multiple other characters", function()
assert.are.equal(
polyfill.str_padstart("1", 5, "0"),
"00001"
)
end)
end)

View File

@ -0,0 +1,40 @@
local polyfill = require("worldeditadditions.utils.strings.polyfill")
describe("str_starts", function()
it("should return true for a single character", function()
assert.are.equal(
polyfill.str_starts("test", "t"),
true
)
end)
it("should return true for a multiple characters", function()
assert.are.equal(
polyfill.str_starts("test", "te"),
true
)
end)
it("should return true for identical strings", function()
assert.are.equal(
polyfill.str_starts("test", "test"),
true
)
end)
it("should return false for a single character ", function()
assert.are.equal(
polyfill.str_starts("test", "y"),
false
)
end)
it("should return false for a character present elsewherer", function()
assert.are.equal(
polyfill.str_starts("test", "e"),
false
)
end)
it("should return false for another substring", function()
assert.are.equal(
polyfill.str_starts("test", "est"),
false
)
end)
end)

View File

@ -0,0 +1,46 @@
local polyfill = require("worldeditadditions.utils.strings.polyfill")
describe("trim", function()
it("work for a string that's already trimmed", function()
assert.are.equal(
polyfill.trim("test"),
"test"
)
end)
it("trim from the start", function()
assert.are.equal(
polyfill.trim(" test"),
"test"
)
end)
it("trim from the end", function()
assert.are.equal(
polyfill.trim("test "),
"test"
)
end)
it("trim from both ends", function()
assert.are.equal(
polyfill.trim(" test "),
"test"
)
end)
it("trim another string", function()
assert.are.equal(
polyfill.trim("yay "),
"yay"
)
end)
it("trim tabs", function()
assert.are.equal(
polyfill.trim("//forest "),
"//forest"
)
end)
it("avoid trimming spaces in the middle", function()
assert.are.equal(
polyfill.trim("te st "),
"te st"
)
end)
end)

View File

@ -42,6 +42,9 @@ if worldeditadditions then
worldeditadditions.trim = trim
else
return {
str_padend = str_padend
str_padend = str_padend,
str_padstart = str_padstart,
str_starts = str_starts,
trim = trim
}
end