style: apply stylua formatter

This commit is contained in:
Erica Marigold 2025-01-08 14:14:30 +00:00
parent 9d3c815fbb
commit 03320fe090
Signed by: DevComp
GPG key ID: 429EF1C337871656
9 changed files with 489 additions and 485 deletions

View file

@ -431,7 +431,6 @@ function ZipReader.extract(self: ZipReader, entry: ZipEntry, options: Extraction
skip = true, skip = true,
})) }))
-- Check if the path was a relative path -- Check if the path was a relative path
if path.isRelative(linkPath) then if path.isRelative(linkPath) then
if string.sub(linkPath, -1) ~= "/" then if string.sub(linkPath, -1) ~= "/" then

View file

@ -29,7 +29,8 @@ return function(test: typeof(frktest.test))
check.equal(targetPath, "pandoc") check.equal(targetPath, "pandoc")
local bin = zip:extract(entry, { isString = false, followSymlinks = true }) :: buffer local bin = zip:extract(entry, { isString = false, followSymlinks = true }) :: buffer
local expectedBin = process.spawn("unzip", { "-p", "tests/data/pandoc_soft_links.zip", "pandoc-3.2-arm64/bin/pandoc" }) local expectedBin =
process.spawn("unzip", { "-p", "tests/data/pandoc_soft_links.zip", "pandoc-3.2-arm64/bin/pandoc" })
check.is_true(expectedBin.ok) check.is_true(expectedBin.ok)
-- Compare hashes instead of the entire binary to improve speed and not print out -- Compare hashes instead of the entire binary to improve speed and not print out

View file

@ -17,7 +17,7 @@ local FALLIBLES = {
-- FIXME: Does not error when it should -- FIXME: Does not error when it should
-- "comment_garbage.zip", -- "comment_garbage.zip",
"chinese.zip", "chinese.zip",
"non_utf8.zip", -- FIXME: Lune breaks for non utf8 data in process stdout "non_utf8.zip", -- FIXME: Lune breaks for non utf8 data in process stdout
"pandoc_soft_links.zip", -- Soft links are tested separately in edge_cases "pandoc_soft_links.zip", -- Soft links are tested separately in edge_cases
} }
@ -49,7 +49,7 @@ return function(test: typeof(frktest.test))
end end
-- Extract with unzip for comparison -- Extract with unzip for comparison
local unzipOutput = process.spawn(`unzip`, { "-p", zipPath, entry:getPath() }) local unzipOutput = process.spawn(`unzip`, { "-p", zipPath, entry:getPath() })
-- NOTE: We use assert since we don't know whether to expect true or false -- NOTE: We use assert since we don't know whether to expect true or false
assert(unzipOutput.ok) assert(unzipOutput.ok)
@ -57,7 +57,7 @@ return function(test: typeof(frktest.test))
-- Test string extraction -- Test string extraction
local contentString = zip:extract(entry, stringOptions) :: string local contentString = zip:extract(entry, stringOptions) :: string
check.equal(#contentString, entry.size) check.equal(#contentString, entry.size)
check.equal(contentString, unzipOutput.stdout) check.equal(contentString, unzipOutput.stdout)
-- Test buffer extraction -- Test buffer extraction
local contentBuffer = zip:extract(entry, bufferOptions) :: buffer local contentBuffer = zip:extract(entry, bufferOptions) :: buffer

View file

@ -7,69 +7,69 @@ local check = frktest.assert.check
local ZipReader = require("../lib") local ZipReader = require("../lib")
return function(test: typeof(frktest.test)) return function(test: typeof(frktest.test))
test.suite("ZIP listing tests (top-level)", function() test.suite("ZIP listing tests (top-level)", function()
test.case("Lists all entries correctly", function() test.case("Lists all entries correctly", function()
-- Read our test zip file -- Read our test zip file
local data = fs.readFile("tests/data/files_and_dirs.zip") local data = fs.readFile("tests/data/files_and_dirs.zip")
local zip = ZipReader.load(buffer.fromstring(data)) local zip = ZipReader.load(buffer.fromstring(data))
-- Get listing from our implementation -- Get listing from our implementation
local entries = {} local entries = {}
for _, entry in zip:listDirectory("/") do for _, entry in zip:listDirectory("/") do
table.insert(entries, entry:getPath()) table.insert(entries, entry:getPath())
end end
-- Get listing from zip command -- Get listing from zip command
local result = process.spawn("zip", {"-sf", "tests/data/files_and_dirs.zip"}) local result = process.spawn("zip", { "-sf", "tests/data/files_and_dirs.zip" })
check.is_true(result.ok) check.is_true(result.ok)
local zipOutput = result.stdout local zipOutput = result.stdout
-- Parse zip command output into sorted array -- Parse zip command output into sorted array
local zipEntries = {} local zipEntries = {}
for line in string.gmatch(zipOutput, "[^\r\n]+") do for line in string.gmatch(zipOutput, "[^\r\n]+") do
-- Skip header/footer lines -- Skip header/footer lines
if not string.match(line, "^Archive contains:") and not string.match(line, "^Total %d+ entries") then if not string.match(line, "^Archive contains:") and not string.match(line, "^Total %d+ entries") then
table.insert(zipEntries, string.match(line, "^%s*(.+)$")) table.insert(zipEntries, string.match(line, "^%s*(.+)$"))
end end
end end
-- Compare results -- Compare results
for _, entry in entries do for _, entry in entries do
check.not_nil(table.find(zipEntries, entry)) check.not_nil(table.find(zipEntries, entry))
end end
end) end)
test.case("Lists directories correctly", function() test.case("Lists directories correctly", function()
local data = fs.readFile("tests/data/files_and_dirs.zip") local data = fs.readFile("tests/data/files_and_dirs.zip")
local zip = ZipReader.load(buffer.fromstring(data)) local zip = ZipReader.load(buffer.fromstring(data))
local dirs = {} local dirs = {}
for _, entry in zip:listDirectory("/") do for _, entry in zip:listDirectory("/") do
if entry.isDirectory then if entry.isDirectory then
table.insert(dirs, entry:getPath()) table.insert(dirs, entry:getPath())
end end
end end
-- Verify all directory paths end with / -- Verify all directory paths end with /
for _, dir in dirs do for _, dir in dirs do
check.equal(string.sub(dir, -1), "/") check.equal(string.sub(dir, -1), "/")
end end
end) end)
test.case("Directory statistics match", function() test.case("Directory statistics match", function()
local data = fs.readFile("tests/data/files_and_dirs.zip") local data = fs.readFile("tests/data/files_and_dirs.zip")
local zip = ZipReader.load(buffer.fromstring(data)) local zip = ZipReader.load(buffer.fromstring(data))
local stats = zip:getStats() local stats = zip:getStats()
-- Get file count from zip command -- Get file count from zip command
local result = process.spawn("zip", {"-sf", "tests/data/files_and_dirs.zip"}) local result = process.spawn("zip", { "-sf", "tests/data/files_and_dirs.zip" })
check.is_true(result.ok) check.is_true(result.ok)
-- Parse file count from last line of zip output -- Parse file count from last line of zip output
local fileCount = tonumber(string.match(result.stdout, "Total (%d+) entries.*$")) local fileCount = tonumber(string.match(result.stdout, "Total (%d+) entries.*$"))
check.equal(stats.fileCount + stats.dirCount, fileCount) check.equal(stats.fileCount + stats.dirCount, fileCount)
end) end)
end) end)
end end

View file

@ -15,7 +15,7 @@ local FALLIBLES = {
"invalid_offset2.zip", "invalid_offset2.zip",
"misaligned_comment.zip", "misaligned_comment.zip",
"comment_garbage.zip", "comment_garbage.zip",
"chinese.zip" -- FIXME: Support encoding other than UTF-8 and ASCII using OS APIs after FFI "chinese.zip", -- FIXME: Support encoding other than UTF-8 and ASCII using OS APIs after FFI
} }
local METHOD_NAME_TRANSFORMATIONS: { [string]: unzip.CompressionMethod } = { local METHOD_NAME_TRANSFORMATIONS: { [string]: unzip.CompressionMethod } = {
@ -83,7 +83,9 @@ return function(test: typeof(frktest.test))
continue continue
end end
local checkErr:(((...any) -> any?) -> nil) = if table.find(FALLIBLES, file) then check.should_error else check.should_not_error local checkErr: ((...any) -> any?) -> nil = if table.find(FALLIBLES, file)
then check.should_error
else check.should_not_error
test.case(`Parsed metadata matches unzip output - {file}`, function() test.case(`Parsed metadata matches unzip output - {file}`, function()
checkErr(function(...) checkErr(function(...)
file = "tests/data/" .. file file = "tests/data/" .. file
@ -118,7 +120,9 @@ return function(test: typeof(frktest.test))
check.equal(tonumber(length), entry.size) check.equal(tonumber(length), entry.size)
check.equal(METHOD_NAME_TRANSFORMATIONS[method :: string], entry.method) check.equal(METHOD_NAME_TRANSFORMATIONS[method :: string], entry.method)
check.is_true(dateFuzzyEq(gotDateTime:formatLocalTime("%Y-%m-%d"), expectedDate :: string, 1)) check.is_true(
dateFuzzyEq(gotDateTime:formatLocalTime("%Y-%m-%d"), expectedDate :: string, 1)
)
-- TODO: Use extra datetime field -- TODO: Use extra datetime field
check.is_true( check.is_true(