Minetest-WorldEditAdditions/.tests/strings/trim.test.lua

47 lines
952 B
Lua
Raw Normal View History

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