Skip to content

Commit

Permalink
chore: update test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Nov 12, 2024
1 parent 0dba0b9 commit c89f2d0
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions test_node/test-node.mjs
Original file line number Diff line number Diff line change
@@ -1,41 +1,31 @@
import assert from "node:assert/strict";
import fs from "node:fs/promises";
import path from "node:path";
import { basename } from "node:path";
import { chdir } from "node:process";
import { test } from "node:test";
import { fileURLToPath } from "node:url";

import init, { format } from "../zig_fmt_node.js";

await init();

const test_root = fileURLToPath(new URL("../test_data", import.meta.url));
const test_root = fileURLToPath(import.meta.resolve("../test_data"));
chdir(test_root);

for await (const dirent of await fs.opendir(test_root, { recursive: true })) {
if (!dirent.isFile()) {
for await (const input_path of fs.glob("**/*.input")) {
if (basename(input_path).startsWith(".")) {
continue;
}

const input_path = dirent.path;
const ext = path.extname(input_path);

switch (ext) {
case ".input":
break;

default:
continue;
}

const expect_path = input_path.replace(ext, ".expect");
const expect_path = input_path.slice(0, -".input".length) + ".expect";

const [input, expected] = await Promise.all([
fs.readFile(input_path, "utf-8"),
fs.readFile(expect_path, "utf-8"),
]);

const test_name = path.relative(test_root, input_path);

test(test_name, () => {
const actual = format(input);
test(input_path, () => {
const actual = format(input, input_path);
assert.equal(actual, expected);
});
}

0 comments on commit c89f2d0

Please sign in to comment.