From 4597edcf1e6d576ccff7ee2ba031ad56fa4f29a8 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Fri, 31 Dec 2021 01:33:44 +0000 Subject: [PATCH] str_ends: write tests --- .tests/strings/str_ends.test.lua | 40 +++++++++++++++++++ worldeditadditions/utils/strings/polyfill.lua | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .tests/strings/str_ends.test.lua diff --git a/.tests/strings/str_ends.test.lua b/.tests/strings/str_ends.test.lua new file mode 100644 index 0000000..b17665c --- /dev/null +++ b/.tests/strings/str_ends.test.lua @@ -0,0 +1,40 @@ +local polyfill = require("worldeditadditions.utils.strings.polyfill") + +describe("str_ends", function() + it("should return true for a single character", function() + assert.are.equal( + true, + polyfill.str_ends("test", "t") + ) + end) + it("should return true for a multiple characters", function() + assert.are.equal( + true, + polyfill.str_ends("test", "st") + ) + end) + it("should return true for identical strings", function() + assert.are.equal( + true, + polyfill.str_ends("test", "test") + ) + end) + it("should return false for a single character ", function() + assert.are.equal( + false, + polyfill.str_ends("test", "y") + ) + end) + it("should return false for a character present elsewherer", function() + assert.are.equal( + false, + polyfill.str_ends("test", "e") + ) + end) + it("should return false for another substring", function() + assert.are.equal( + false, + polyfill.str_ends("test", "tes") + ) + end) +end) diff --git a/worldeditadditions/utils/strings/polyfill.lua b/worldeditadditions/utils/strings/polyfill.lua index 4fc0497..1348da2 100644 --- a/worldeditadditions/utils/strings/polyfill.lua +++ b/worldeditadditions/utils/strings/polyfill.lua @@ -54,7 +54,7 @@ else str_padend = str_padend, str_padstart = str_padstart, str_starts = str_starts, - str_ends = str_starts, + str_ends = str_ends, trim = trim } end