-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
875fbba
commit df480d8
Showing
1 changed file
with
16 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,28 @@ | ||
import { Glob } from "bun"; | ||
import { expect, test } from "bun:test"; | ||
import fs from "node:fs/promises"; | ||
import path from "node:path"; | ||
import init, { format } from ".."; | ||
|
||
await init(); | ||
|
||
async function* walk(dir: string): AsyncGenerator<string> { | ||
for await (const d of await fs.readdir(dir)) { | ||
const entry = path.join(dir, d); | ||
const stat = await fs.stat(entry); | ||
|
||
if (stat.isDirectory()) { | ||
yield* walk(entry); | ||
} | ||
|
||
if (stat.isFile()) { | ||
yield entry; | ||
} | ||
} | ||
} | ||
|
||
const test_root = Bun.fileURLToPath(new URL("../test_data", import.meta.url)); | ||
const glob = new Glob("**/*.input"); | ||
|
||
for await (const input_path of walk(test_root)) { | ||
const ext = path.extname(input_path); | ||
|
||
switch (ext) { | ||
case ".input": | ||
break; | ||
for await (const input_path of glob.scan(test_root)) { | ||
if (path.basename(input_path).startsWith(".")) { | ||
continue; | ||
} | ||
|
||
default: | ||
continue; | ||
} | ||
const full_path = path.join(test_root, input_path); | ||
const expect_path = full_path.replace(".input", ".expect"); | ||
|
||
const test_name = path.relative(test_root, input_path); | ||
const [input, expected] = await Promise.all([ | ||
Bun.file(input_path).text(), | ||
Bun.file(input_path.replace(ext, ".expect")).text(), | ||
]); | ||
const [input, expected] = await Promise.all([ | ||
Bun.file(full_path).text(), | ||
Bun.file(expect_path).text(), | ||
]); | ||
|
||
test(test_name, () => { | ||
const actual = format(input); | ||
expect(actual).toBe(expected); | ||
}); | ||
test(input_path, () => { | ||
const actual = format(input, input_path); | ||
expect(actual).toBe(expected); | ||
}); | ||
} |