local h = require("harness") local t = h.module("package") t.check("read returns a file's text", function() local text = reskate.package.read("data/sample.txt") assert(text and text:sub(1, 12) == "ptest sample", tostring(text)) end) t.check("read returns nil for a file that is not there", function() assert(reskate.package.read("data/missing.txt") == nil) end) t.check("read_json returns the file as tables", function() local data = reskate.package.read_json("data/sample.json") assert(data.name == "sample" and data.list[3] == 3 and data.nested.yes == true) end) t.check("list names a folder's files, sorted", function() local names = table.concat(reskate.package.list("data"), ",") assert(names == "sample.json,sample.txt", names) end) t.check("list with no folder is the package, folders ending in /", function() local names = table.concat(reskate.package.list(), ",") assert(names:find("plugin/", 1, true) and names:find("reskate-plugin.json", 1, true), names) end) t.check("paths out of the package are refused", function() for _, path in {"../x", "/x", "C:/Windows/win.ini", "data\\sample.txt", "data/../../x", "data/./sample.txt"} do h.refused(reskate.package.read, path) end end)