🎉 initial commit

This commit is contained in:
2025-09-20 20:44:24 +08:00
commit 82538addcc
19 changed files with 483 additions and 0 deletions

35
test_node/test-node.mjs Normal file
View File

@@ -0,0 +1,35 @@
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);
});
}