import { Glob } from "bun"; import { expect, test } from "bun:test"; import { chdir } from "node:process"; import { fileURLToPath } from "node:url"; import init, { format } from "../pkg/rust_fmt"; await init(); const test_root = fileURLToPath(import.meta.resolve("../test_data")); chdir(test_root); const glob = new Glob("**/*.rs"); for await (const input_path of glob.scan()) { const [input, expected] = await Promise.all([ Bun.file(input_path).text(), Bun.file(input_path + ".snap").text().catch(() => { // 如果没有 snap 文件,就创建一个 const formatted = format(input); return formatted; }), ]); test(input_path, () => { const actual = format(input); expect(actual).toBe(expected); }); }