mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 07:23:00 +00:00
Test the rest of the sring polyfills
This commit is contained in:
parent
6a42aa6838
commit
afce954306
5 changed files with 167 additions and 40 deletions
|
@ -1,4 +1,3 @@
|
||||||
expose("", function()
|
|
||||||
local polyfill = require("worldeditadditions.utils.strings.polyfill")
|
local polyfill = require("worldeditadditions.utils.strings.polyfill")
|
||||||
|
|
||||||
describe("str_padend", function()
|
describe("str_padend", function()
|
||||||
|
@ -39,4 +38,3 @@ expose("", function()
|
||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
|
||||||
|
|
40
.tests/strings/str_padstart.test.lua
Normal file
40
.tests/strings/str_padstart.test.lua
Normal 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)
|
40
.tests/strings/str_starts.test.lua
Normal file
40
.tests/strings/str_starts.test.lua
Normal 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)
|
46
.tests/strings/trim.test.lua
Normal file
46
.tests/strings/trim.test.lua
Normal 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)
|
|
@ -42,6 +42,9 @@ if worldeditadditions then
|
||||||
worldeditadditions.trim = trim
|
worldeditadditions.trim = trim
|
||||||
else
|
else
|
||||||
return {
|
return {
|
||||||
str_padend = str_padend
|
str_padend = str_padend,
|
||||||
|
str_padstart = str_padstart,
|
||||||
|
str_starts = str_starts,
|
||||||
|
trim = trim
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue