Files
kucherenko__jscpd/fixtures/lua/file2.lua
apk 64e471e2b0 test: raise coverage to 96%+ on @jscpd/finder and 98%+ on apps/jscpd
Adds 92 new tests (178 → 270 total) with zero source-file modifications:

- packages/finder: 13 new test files covering all reporters, subscribers,
  validators, hooks, utils, options, cloneFound, getFilesToDetect, and
  InFilesDetector; shared buildClone() factory helper
- apps/jscpd: 3 new test files (options-unit, print, store) plus extensions
  to formats, modes, and options integration tests
- vitest.config.ts added to both packages to restrict coverage.include
  to src/** only, eliminating bin/ and prism.js noise
- Fixes 3 tokenizer bugs (trailing space in format lookup, tokenization
  edge cases) uncovered by the new format fixture suite
- Adds fixture files for 40+ language formats to support formats.test.ts
2026-05-09 15:00:38 +02:00

54 lines
1.0 KiB
Lua

-- Common Lua utility functions
local M = {}
function M.validate_input(value)
if not value or value == "" then
return nil, "Input cannot be empty"
end
if #value > 255 then
return nil, "Input exceeds maximum length"
end
return value, nil
end
function M.table_contains(tbl, element)
for _, v in ipairs(tbl) do
if v == element then return true end
end
return false
end
function M.map(tbl, fn)
local result = {}
for i, v in ipairs(tbl) do
result[i] = fn(v)
end
return result
end
function M.filter(tbl, predicate)
local result = {}
for _, v in ipairs(tbl) do
if predicate(v) then
result[#result + 1] = v
end
end
return result
end
function M.reduce(tbl, fn, init)
local acc = init
for _, v in ipairs(tbl) do
acc = fn(acc, v)
end
return acc
end
-- File-specific: product of table elements
function M.product(tbl)
return M.reduce(tbl, function(a, b) return a * b end, 1)
end
return M