Files
metabuilder/packages/lua_test/seed/scripts/assert_utils.lua
JohnDoe6345789 0f69e33d9b feat: Implement Slider component with enhanced features and styles
- Added a new Slider component with support for controlled and uncontrolled values, marks, value labels, and customizable styles.
- Introduced new props for Slider including min, max, step, orientation, color, size, and disabled state.
- Implemented internal state management for value and visibility of value labels.
- Created SCSS styles for the Slider component, supporting various orientations, sizes, and color variants.
- Added accessibility features to the Slider component, including ARIA attributes.

chore: Introduce assertion utilities and refactor assertion functions

- Created standalone assertion functions (assertTrue, assertFalse, assertEqual, etc.) for better test readability.
- Developed assertion utilities for error handling and value stringification.
- Refactored existing assertion functions to utilize the new utility functions for improved maintainability.
- Implemented a chainable expect() function with various matchers for enhanced testing capabilities.
2025-12-30 11:01:44 +00:00

77 lines
1.9 KiB
Lua

-- Assertion utilities - helper functions
-- Provides stringify, deepEqual, assertionError for matchers
---@class AssertionUtils
local M = {}
---Get type with better nil handling
---@param value any Value to check type of
---@return string The type name
function M.getType(value)
if value == nil then return "nil" end
return type(value)
end
---Convert any value to a string representation for error messages
---@param value any Value to stringify
---@return string String representation
function M.stringify(value)
local t = type(value)
if t == "string" then
return '"' .. value .. '"'
elseif t == "table" then
local parts = {}
for k, v in pairs(value) do
parts[#parts + 1] = tostring(k) .. "=" .. M.stringify(v)
end
return "{" .. table.concat(parts, ", ") .. "}"
elseif t == "nil" then
return "nil"
else
return tostring(value)
end
end
---Deep equality check for tables
---@param a any First value
---@param b any Second value
---@return boolean True if deeply equal
function M.deepEqual(a, b)
if type(a) ~= type(b) then return false end
if type(a) ~= "table" then return a == b end
-- Check all keys in a exist in b with same values
for k, v in pairs(a) do
if not M.deepEqual(v, b[k]) then return false end
end
-- Check all keys in b exist in a
for k, _ in pairs(b) do
if a[k] == nil then return false end
end
return true
end
---@class AssertionError
---@field type string Always "AssertionError"
---@field message string Error message
---@field expected any Expected value
---@field actual any Actual value
---Create an assertion error object
---@param message string Error message
---@param expected any Expected value
---@param actual any Actual value
---@return AssertionError
function M.assertionError(message, expected, actual)
return {
type = "AssertionError",
message = message,
expected = expected,
actual = actual
}
end
return M