Files
2026-11-12 18:34:33 +08:00

64 lines
1.9 KiB
TypeScript

import { parse as parseToml } from "@std/toml";
import { assertEquals } from "@std/assert";
// Deno.test("PFiles initialization", () => {
// const pfiles = new PFiles("./mobile_src");
// console.log(pfiles);
// });
// Deno.test("PDF generate", async () => {
// const builder = new DocuBuilder();
// try {
// await builder.with_browser();
// const cfg = JSON.parse(await Deno.readTextFile("config.json"));
// for (const config of cfg.settings) {
// console.debug(`Processing config: ${JSON.stringify(config)}`);
// builder.with_files_sync(config.journal.from_directory);
// builder.as_html_page();
// await builder.build_as_pdf(config.playwright);
// }
// } finally {
// await builder.close_browser();
// }
// });
// Deno.test({
// name: "IndexBuilder test",
// sanitizeOps: false,
// sanitizeResources: false,
// async fn() {
// },
// });
Deno.test("default config is TOML with an asset base and vars table", async () => {
const config = parseToml(await Deno.readTextFile("./config.toml")) as {
asset_base: string;
settings: unknown[];
vars: Record<string, unknown>;
};
assertEquals(config.asset_base, "../../assets");
assertEquals(config.settings.length, 3);
assertEquals(typeof config.vars, "object");
});
Deno.test("ripgrep test", async () => {
let pattern = "NULL ";
const cmd = new Deno.Command("rg", {
args: ["-q", "-F", pattern],
stdin: "piped",
stdout: "piped",
stderr: "piped",
});
const child = cmd.spawn();
const writer = child.stdin.getWriter();
await writer.write(
new TextEncoder().encode("This is a test string with NULL in it."),
);
await writer.close();
const { code, stdout, stderr } = await child.output();
console.log(`Exit code: ${code}`);
console.log(`stdout: ${new TextDecoder().decode(stdout)}`);
console.log(`stderr: ${new TextDecoder().decode(stderr)}`);
});