2022-09-19 02:18:48 +02:00
|
|
|
local polyfill = require("worldeditadditions_core.utils.strings.polyfill")
|
2021-06-26 03:17:49 +02:00
|
|
|
|
|
|
|
describe("trim", function()
|
2023-08-15 18:44:19 +02:00
|
|
|
it("should work for a string that's already trimmed", function()
|
2021-06-26 03:17:49 +02:00
|
|
|
assert.are.equal(
|
|
|
|
polyfill.trim("test"),
|
|
|
|
"test"
|
|
|
|
)
|
|
|
|
end)
|
2023-08-15 18:44:19 +02:00
|
|
|
it("should trim from the start", function()
|
2021-06-26 03:17:49 +02:00
|
|
|
assert.are.equal(
|
|
|
|
polyfill.trim(" test"),
|
|
|
|
"test"
|
|
|
|
)
|
|
|
|
end)
|
2023-08-15 18:44:19 +02:00
|
|
|
it("should trim from the end", function()
|
2021-06-26 03:17:49 +02:00
|
|
|
assert.are.equal(
|
|
|
|
polyfill.trim("test "),
|
|
|
|
"test"
|
|
|
|
)
|
|
|
|
end)
|
2023-08-15 18:44:19 +02:00
|
|
|
it("should trim from both ends", function()
|
2021-06-26 03:17:49 +02:00
|
|
|
assert.are.equal(
|
|
|
|
polyfill.trim(" test "),
|
|
|
|
"test"
|
|
|
|
)
|
|
|
|
end)
|
2023-08-15 18:44:19 +02:00
|
|
|
it("should trim another string", function()
|
2021-06-26 03:17:49 +02:00
|
|
|
assert.are.equal(
|
|
|
|
polyfill.trim("yay "),
|
|
|
|
"yay"
|
|
|
|
)
|
|
|
|
end)
|
2023-08-15 18:44:19 +02:00
|
|
|
it("should trim tabs", function()
|
2021-06-26 03:17:49 +02:00
|
|
|
assert.are.equal(
|
|
|
|
polyfill.trim("//forest "),
|
|
|
|
"//forest"
|
|
|
|
)
|
|
|
|
end)
|
2023-08-15 18:44:19 +02:00
|
|
|
it("should avoid trimming spaces in the middle", function()
|
2021-06-26 03:17:49 +02:00
|
|
|
assert.are.equal(
|
|
|
|
polyfill.trim("te st "),
|
|
|
|
"te st"
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
end)
|