|
| 1 | +import { Glob } from "bun"; |
1 | 2 | import { expect, test } from "bun:test"; |
2 | | -import fs from "node:fs/promises"; |
3 | 3 | import path from "node:path"; |
4 | | -import init, { format } from "../pkg"; |
| 4 | +import init, { format } from "../pkg/lua_fmt"; |
5 | 5 |
|
6 | 6 | await init(); |
7 | 7 |
|
8 | | -async function* walk(dir: string): AsyncGenerator<string> { |
9 | | - for await (const d of await fs.readdir(dir)) { |
10 | | - const entry = path.join(dir, d); |
11 | | - const stat = await fs.stat(entry); |
12 | | - |
13 | | - if (stat.isDirectory()) { |
14 | | - yield* walk(entry); |
15 | | - } |
16 | | - |
17 | | - if (stat.isFile()) { |
18 | | - yield entry; |
19 | | - } |
20 | | - } |
21 | | -} |
22 | | - |
23 | 8 | const test_root = Bun.fileURLToPath(new URL("../test_data", import.meta.url)); |
| 9 | +const glob = new Glob("**/*.lua"); |
24 | 10 |
|
25 | | -for await (const input_path of walk(test_root)) { |
| 11 | +for await (const input_path of glob.scan(test_root)) { |
26 | 12 | if (path.basename(input_path).startsWith(".")) { |
27 | 13 | continue; |
28 | 14 | } |
29 | 15 |
|
30 | | - const ext = path.extname(input_path); |
31 | | - |
32 | | - switch (ext) { |
33 | | - case ".lua": |
34 | | - break; |
35 | | - |
36 | | - default: |
37 | | - continue; |
38 | | - } |
| 16 | + const full_path = path.join(test_root, input_path); |
39 | 17 |
|
40 | | - const test_name = path.relative(test_root, input_path); |
41 | 18 | const [input, expected] = await Promise.all([ |
42 | | - Bun.file(input_path).text(), |
43 | | - Bun.file(input_path + ".snap").text(), |
| 19 | + Bun.file(full_path).text(), |
| 20 | + Bun.file(full_path + ".snap").text(), |
44 | 21 | ]); |
45 | 22 |
|
46 | | - test(test_name, () => { |
47 | | - const actual = format(input, input_path); |
| 23 | + test(input_path, () => { |
| 24 | + const actual = format(input, input_path); |
48 | 25 | expect(actual).toBe(expected); |
49 | 26 | }); |
50 | 27 | } |
0 commit comments