import assert from "node:assert/strict"; import fs from "node:fs/promises"; import { basename } from "node:path"; import { chdir } from "node:process"; import { test } from "node:test"; import { fileURLToPath } from "node:url"; import init, { format } from "../pkg/rust_fmt_node.js"; await init(); const test_root = fileURLToPath(import.meta.resolve("../test_data")); chdir(test_root); for await (const input_path of fs.glob("**/*.rs")) { if (basename(input_path).startsWith(".")) { continue; } const expect_path = input_path + ".snap"; const [input, expected] = await Promise.all([ fs.readFile(input_path, "utf-8"), fs.readFile(expect_path, "utf-8").catch(() => { // 如果没有 snap 文件,就创建一个 const formatted = format(input); return formatted; }), ]); test(input_path, () => { const actual = format(input); assert.equal(actual, expected); }); }