mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 22:34:56 +00:00
feat: add testing utilities including context, mock functions, and snapshot handling
This commit is contained in:
43
packages/lua_test/seed/scripts/string_utils.lua
Normal file
43
packages/lua_test/seed/scripts/string_utils.lua
Normal file
@@ -0,0 +1,43 @@
|
||||
-- String utilities for testing
|
||||
-- Provides trim, split, startsWith, endsWith functions
|
||||
|
||||
---@class StringUtils
|
||||
local M = {}
|
||||
|
||||
---Trim whitespace from both ends of a string
|
||||
---@param s string String to trim
|
||||
---@return string Trimmed string
|
||||
function M.trim(s)
|
||||
return s:match("^%s*(.-)%s*$")
|
||||
end
|
||||
|
||||
---Split a string by delimiter
|
||||
---@param s string String to split
|
||||
---@param delimiter? string Delimiter pattern (default whitespace)
|
||||
---@return string[] Array of parts
|
||||
function M.split(s, delimiter)
|
||||
delimiter = delimiter or "%s"
|
||||
local result = {}
|
||||
for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do
|
||||
result[#result + 1] = match
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
---Check if string starts with prefix
|
||||
---@param s string String to check
|
||||
---@param prefix string Prefix to look for
|
||||
---@return boolean True if s starts with prefix
|
||||
function M.startsWith(s, prefix)
|
||||
return s:sub(1, #prefix) == prefix
|
||||
end
|
||||
|
||||
---Check if string ends with suffix
|
||||
---@param s string String to check
|
||||
---@param suffix string Suffix to look for
|
||||
---@return boolean True if s ends with suffix
|
||||
function M.endsWith(s, suffix)
|
||||
return suffix == "" or s:sub(-#suffix) == suffix
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user